arc: Add inclusion of "gdbarch.h" in "arc-tdep.h"
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b811d2c2 2@c Copyright (C) 1988--2020 Free Software Foundation, Inc.
c906108c 3@c
5d161b24 4@c %**start of header
c906108c
SS
5@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6@c of @set vars. However, you can override filename with makeinfo -o.
7@setfilename gdb.info
8@c
43662968 9@c man begin INCLUDE
c906108c 10@include gdb-cfg.texi
43662968 11@c man end
c906108c 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
00595b5e
EZ
23@c To avoid file-name clashes between index.html and Index.html, when
24@c the manual is produced on a Posix host and then moved to a
25@c case-insensitive filesystem (e.g., MS-Windows), we separate the
26@c indices into two: Concept Index and all the rest.
27@syncodeindex ky fn
28@syncodeindex tp fn
c906108c 29
41afff9a 30@c readline appendices use @vindex, @findex and @ftable,
48e934c6 31@c annotate.texi and gdbmi use @findex.
00595b5e 32@syncodeindex vr fn
c906108c
SS
33
34@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 35@c This is updated by GNU Press.
26829f2b 36@set EDITION Tenth
c906108c 37
87885426
FN
38@c !!set GDB edit command default editor
39@set EDITOR /bin/ex
c906108c 40
6c0e9fb3 41@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 42
c906108c 43@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 44@c manuals to an info tree.
03727ca6 45@dircategory Software development
96a2c332 46@direntry
03727ca6 47* Gdb: (gdb). The GNU debugger.
6cb999f8 48* gdbserver: (gdb) Server. The GNU debugging server.
96a2c332
SS
49@end direntry
50
a67ec3f4 51@copying
43662968 52@c man begin COPYRIGHT
e5d78223 53Copyright @copyright{} 1988-2020 Free Software Foundation, Inc.
c906108c 54
e9c75b65 55Permission is granted to copy, distribute and/or modify this document
4f5d9f07 56under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 57any later version published by the Free Software Foundation; with the
959acfd1
EZ
58Invariant Sections being ``Free Software'' and ``Free Software Needs
59Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60and with the Back-Cover Texts as in (a) below.
c906108c 61
b8533aec
DJ
62(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63this GNU Manual. Buying copies from GNU Press supports the FSF in
64developing GNU and promoting software freedom.''
43662968 65@c man end
a67ec3f4
JM
66@end copying
67
68@ifnottex
69This file documents the @sc{gnu} debugger @value{GDBN}.
70
71This is the @value{EDITION} Edition, of @cite{Debugging with
72@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73@ifset VERSION_PACKAGE
74@value{VERSION_PACKAGE}
75@end ifset
76Version @value{GDBVN}.
77
78@insertcopying
79@end ifnottex
c906108c
SS
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
c906108c 84@sp 1
c906108c 85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
9e9c5ae7 90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 91@page
c906108c
SS
92@tex
93{\parskip=0pt
c16158bc 94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
53a5351d 99
c906108c 100@vskip 0pt plus 1filll
c906108c 101Published by the Free Software Foundation @*
c02a867d
EZ
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
26829f2b 104ISBN 978-0-9831592-3-0 @*
e9c75b65 105
a67ec3f4 106@insertcopying
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
c5a6a07f 111@node Top, Summary
6d2ebf8b 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
e5d78223 123Copyright (C) 1988-2020 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.
d1feda86 163* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
164
165* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 166
39037522
TT
167@ifset SYSTEM_READLINE
168* Command Line Editing: (rluserman). Command Line Editing
169* Using History Interactively: (history). Using History Interactively
170@end ifset
171@ifclear SYSTEM_READLINE
6d2ebf8b
SS
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
39037522 174@end ifclear
4ceed123 175* In Memoriam:: In Memoriam
0869d01b 176* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 177* Installing GDB:: Installing GDB
eb12ee30 178* Maintenance Commands:: Maintenance Commands
e0ce93ac 179* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 180* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
181* Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
07e059b5
VP
183* Operating System Information:: Getting additional information from
184 the operating system
00bf0b85 185* Trace File Format:: GDB trace file format
90476074 186* Index Section Format:: .gdb_index section format
43662968 187* Man Pages:: Manual pages
aab4e0ec
AC
188* Copying:: GNU General Public License says
189 how you can copy and share GDB
6826cf00 190* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
191* Concept Index:: Index of @value{GDBN} concepts
192* Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
6d2ebf8b
SS
194@end menu
195
6c0e9fb3 196@end ifnottex
c906108c 197
449f3b6c 198@contents
449f3b6c 199
6d2ebf8b 200@node Summary
c906108c
SS
201@unnumbered Summary of @value{GDBN}
202
203The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204going on ``inside'' another program while it executes---or what another
205program was doing at the moment it crashed.
206
207@value{GDBN} can do four main kinds of things (plus other things in support of
208these) to help you catch bugs in the act:
209
210@itemize @bullet
211@item
212Start your program, specifying anything that might affect its behavior.
213
214@item
215Make your program stop on specified conditions.
216
217@item
218Examine what has happened, when your program has stopped.
219
220@item
221Change things in your program, so you can experiment with correcting the
222effects of one bug and go on to learn about another.
223@end itemize
224
49efadf5 225You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 226For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
227For more information, see @ref{C,,C and C++}.
228
6aecb9c2
JB
229Support for D is partial. For information on D, see
230@ref{D,,D}.
231
cce74817 232@cindex Modula-2
e632838e
AC
233Support for Modula-2 is partial. For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
c906108c 235
f4b8a18d
KW
236Support for OpenCL C is partial. For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
cce74817
JM
239@cindex Pascal
240Debugging Pascal programs which use sets, subranges, file variables, or
241nested functions does not currently work. @value{GDBN} does not support
242entering expressions, printing values, or similar features using Pascal
243syntax.
c906108c 244
c906108c
SS
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 247it may be necessary to refer to some variables with a trailing
cce74817 248underscore.
c906108c 249
b37303ee
AF
250@value{GDBN} can be used to debug programs written in Objective-C,
251using either the Apple/NeXT or the GNU Objective-C runtime.
252
c906108c
SS
253@menu
254* Free Software:: Freely redistributable software
984359d2 255* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
79a6e687 260@unnumberedsec Free Software
c906108c 261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
984359d2 275@node Free Documentation
2666264b 276@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
277
278The biggest deficiency in the free software community today is not in
279the software---it is the lack of good free documentation that we can
280include with the free software. Many of our most important
281programs do not come with free reference manuals and free introductory
282texts. Documentation is an essential part of any software package;
283when an important free software package does not come with a free
284manual and a free tutorial, that is a major gap. We have many such
285gaps today.
286
287Consider Perl, for instance. The tutorial manuals that people
288normally use are non-free. How did this come about? Because the
289authors of those manuals published them with restrictive terms---no
290copying, no modification, source files not available---which exclude
291them from the free software world.
292
293That wasn't the first time this sort of thing happened, and it was far
294from the last. Many times we have heard a GNU user eagerly describe a
295manual that he is writing, his intended contribution to the community,
296only to learn that he had ruined everything by signing a publication
297contract to make it non-free.
298
299Free documentation, like free software, is a matter of freedom, not
300price. The problem with the non-free manual is not that publishers
301charge a price for printed copies---that in itself is fine. (The Free
302Software Foundation sells printed copies of manuals, too.) The
303problem is the restrictions on the use of the manual. Free manuals
304are available in source code form, and give you permission to copy and
305modify. Non-free manuals do not allow this.
306
307The criteria of freedom for a free manual are roughly the same as for
308free software. Redistribution (including the normal kinds of
309commercial redistribution) must be permitted, so that the manual can
310accompany every copy of the program, both on-line and on paper.
311
312Permission for modification of the technical content is crucial too.
313When people modify the software, adding or changing features, if they
314are conscientious they will change the manual too---so they can
315provide accurate and clear documentation for the modified program. A
316manual that leaves you no choice but to write a new manual to document
317a changed version of the program is not really available to our
318community.
319
320Some kinds of limits on the way modification is handled are
321acceptable. For example, requirements to preserve the original
322author's copyright notice, the distribution terms, or the list of
323authors, are ok. It is also no problem to require modified versions
324to include notice that they were modified. Even entire sections that
325may not be deleted or changed are acceptable, as long as they deal
326with nontechnical topics (like this one). These kinds of restrictions
327are acceptable because they don't obstruct the community's normal use
328of the manual.
329
330However, it must be possible to modify all the @emph{technical}
331content of the manual, and then distribute the result in all the usual
332media, through all the usual channels. Otherwise, the restrictions
333obstruct the use of the manual, it is not free, and we need another
334manual to replace it.
335
336Please spread the word about this issue. Our community continues to
337lose manuals to proprietary publishing. If we spread the word that
338free software needs free reference manuals and free tutorials, perhaps
339the next person who wants to contribute by writing documentation will
340realize, before it is too late, that only free manuals contribute to
341the free software community.
342
343If you are writing documentation, please insist on publishing it under
344the GNU Free Documentation License or another free documentation
345license. Remember that this decision requires your approval---you
346don't have to let the publisher decide. Some commercial publishers
347will use a free license if you insist, but they will not propose the
348option; it is up to you to raise the issue and say firmly that this is
349what you want. If the publisher you are dealing with refuses, please
350try other publishers. If you're not sure whether a proposed license
42584a72 351is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
352
353You can encourage commercial publishers to sell more free, copylefted
354manuals and tutorials by buying them, and particularly by buying
355copies from the publishers that paid for their writing or for major
356improvements. Meanwhile, try to avoid buying non-free documentation
357at all. Check the distribution terms of a manual before you buy it,
358and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
959acfd1
EZ
361
362The Free Software Foundation maintains a list of free documentation
363published by other publishers, at
364@url{http://www.fsf.org/doc/other-free-books.html}.
365
6d2ebf8b 366@node Contributors
96a2c332
SS
367@unnumberedsec Contributors to @value{GDBN}
368
369Richard Stallman was the original author of @value{GDBN}, and of many
370other @sc{gnu} programs. Many others have contributed to its
371development. This section attempts to credit major contributors. One
372of the virtues of free software is that everyone is free to contribute
373to it; with regret, we cannot actually acknowledge everyone here. The
374file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
375blow-by-blow account.
376
377Changes much prior to version 2.0 are lost in the mists of time.
378
379@quotation
380@emph{Plea:} Additions to this section are particularly welcome. If you
381or your friends (or enemies, to be evenhanded) have been unfairly
382omitted from this list, we would like to add your names!
383@end quotation
384
385So that they may not regard their many labors as thankless, we
386particularly thank those who shepherded @value{GDBN} through major
387releases:
7ba3cf9c 388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
389Jim Blandy (release 4.18);
390Jason Molenda (release 4.17);
391Stan Shebs (release 4.14);
392Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395Jim Kingdon (releases 3.5, 3.4, and 3.3);
396and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398Richard Stallman, assisted at various times by Peter TerMaat, Chris
399Hanson, and Richard Mlynarik, handled releases through 2.8.
400
b37052ae
EZ
401Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402in @value{GDBN}, with significant additional contributions from Per
403Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405much general update work leading to release 3.0).
c906108c 406
b37052ae 407@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
408object-file formats; BFD was a joint project of David V.
409Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411David Johnson wrote the original COFF support; Pace Willison did
412the original support for encapsulated COFF.
413
0179ffac 414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
415
416Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418support.
419Jean-Daniel Fekete contributed Sun 386i support.
420Chris Hanson improved the HP9000 support.
421Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422David Johnson contributed Encore Umax support.
423Jyrki Kuoppala contributed Altos 3068 support.
424Jeff Law contributed HP PA and SOM support.
425Keith Packard contributed NS32K support.
426Doug Rabson contributed Acorn Risc Machine support.
427Bob Rusk contributed Harris Nighthawk CX-UX support.
428Chris Smith contributed Convex support (and Fortran debugging).
429Jonathan Stone contributed Pyramid support.
430Michael Tiemann contributed SPARC support.
431Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432Pace Willison contributed Intel 386 support.
433Jay Vosburgh contributed Symmetry support.
a37295f9 434Marko Mlinar contributed OpenRISC 1000 support.
c906108c 435
1104b9e7 436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
437
438Rich Schaefer and Peter Schauer helped with support of SunOS shared
439libraries.
440
441Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442about several machine instruction sets.
443
444Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447and RDI targets, respectively.
448
449Brian Fox is the author of the readline libraries providing
450command-line editing and command history.
451
7a292a7a
SS
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 454
5d161b24 455Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 456He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 457symbols.
c906108c 458
f24c5e49
KI
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
c906108c
SS
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
f24c5e49
KI
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
c906108c
SS
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
96a2c332 471Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
472
473Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474watchpoints.
475
476Michael Snyder added support for tracepoints.
477
478Stu Grossman wrote gdbserver.
479
480Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
482
483The following people at the Hewlett-Packard Company contributed
484support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
486compiler, and the Text User Interface (nee Terminal User Interface):
487Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489provided HP-specific information in this manual.
c906108c 490
b37052ae
EZ
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
96a2c332
SS
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
496fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508Zuhn have made contributions both large and small.
c906108c 509
ffed4509
AC
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
e2e0bcd1
JB
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
c906108c 515
a9967aef
AC
516Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521with the migration of old architectures to this new framework.
522
c5e30d01
AC
523Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524unwinder framework, this consisting of a fresh new design featuring
525frame IDs, independent frame sniffers, and the sentinel frame. Mark
526Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 528trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
529complete rewrite of the architecture's frame code, were carried out by
530Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534Weigand.
535
ca3bf3bd
DJ
536Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537Tensilica, Inc.@: contributed support for Xtensa processors. Others
538who have worked on the Xtensa port of @value{GDBN} in the past include
539Steve Tjiang, John Newlin, and Scott Foehner.
540
08be9d71
ME
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
387360da
JB
544Initial support for the FreeBSD/mips target and native configuration
545was developed by SRI International and the University of Cambridge
546Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547("CTSRD"), as part of the DARPA CRASH research programme.
548
74792ff7
JB
549Initial support for the FreeBSD/riscv target and native configuration
550was developed by SRI International and the University of Cambridge
551Computer Laboratory (Department of Computer Science and Technology)
552under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553SSITH research programme.
554
a994fec4
FJ
555The original port to the OpenRISC 1000 is believed to be due to
556Alessandro Forin and Per Bothner. More recent ports have been the work
557of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558Stafford Horne.
559
39791af2
JM
560Weimin Pan, David Faust and Jose E. Marchesi contributed support for
561the Linux kernel BPF virtual architecture. This work was sponsored by
562Oracle.
563
6d2ebf8b 564@node Sample Session
c906108c
SS
565@chapter A Sample @value{GDBN} Session
566
567You can use this manual at your leisure to read all about @value{GDBN}.
568However, a handful of commands are enough to get started using the
569debugger. This chapter illustrates those commands.
570
571@iftex
572In this sample session, we emphasize user input like this: @b{input},
573to make it easier to pick out from the surrounding output.
574@end iftex
575
576@c FIXME: this example may not be appropriate for some configs, where
577@c FIXME...primary interest is in remote use.
578
579One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
580processor) exhibits the following bug: sometimes, when we change its
581quote strings from the default, the commands used to capture one macro
582definition within another stop working. In the following short @code{m4}
583session, we define a macro @code{foo} which expands to @code{0000}; we
584then use the @code{m4} built-in @code{defn} to define @code{bar} as the
585same thing. However, when we change the open quote string to
586@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
587procedure fails to define a new synonym @code{baz}:
588
589@smallexample
590$ @b{cd gnu/m4}
591$ @b{./m4}
592@b{define(foo,0000)}
593
594@b{foo}
5950000
596@b{define(bar,defn(`foo'))}
597
598@b{bar}
5990000
600@b{changequote(<QUOTE>,<UNQUOTE>)}
601
602@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
603@b{baz}
c8aa23ab 604@b{Ctrl-d}
c906108c
SS
605m4: End of input: 0: fatal error: EOF in string
606@end smallexample
607
608@noindent
609Let us use @value{GDBN} to try to see what is going on.
610
c906108c
SS
611@smallexample
612$ @b{@value{GDBP} m4}
613@c FIXME: this falsifies the exact text played out, to permit smallbook
614@c FIXME... format to come out better.
615@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 616 of it under certain conditions; type "show copying" to see
c906108c 617 the conditions.
5d161b24 618There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
619 for details.
620
621@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
622(@value{GDBP})
623@end smallexample
c906108c
SS
624
625@noindent
626@value{GDBN} reads only enough symbol data to know where to find the
627rest when needed; as a result, the first prompt comes up very quickly.
628We now tell @value{GDBN} to use a narrower display width than usual, so
629that examples fit in this manual.
630
631@smallexample
632(@value{GDBP}) @b{set width 70}
633@end smallexample
634
635@noindent
636We need to see how the @code{m4} built-in @code{changequote} works.
637Having looked at the source, we know the relevant subroutine is
638@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
639@code{break} command.
640
641@smallexample
642(@value{GDBP}) @b{break m4_changequote}
643Breakpoint 1 at 0x62f4: file builtin.c, line 879.
644@end smallexample
645
646@noindent
647Using the @code{run} command, we start @code{m4} running under @value{GDBN}
648control; as long as control does not reach the @code{m4_changequote}
649subroutine, the program runs as usual:
650
651@smallexample
652(@value{GDBP}) @b{run}
653Starting program: /work/Editorial/gdb/gnu/m4/m4
654@b{define(foo,0000)}
655
656@b{foo}
6570000
658@end smallexample
659
660@noindent
661To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
662suspends execution of @code{m4}, displaying information about the
663context where it stops.
664
665@smallexample
666@b{changequote(<QUOTE>,<UNQUOTE>)}
667
5d161b24 668Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
669 at builtin.c:879
670879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
671@end smallexample
672
673@noindent
674Now we use the command @code{n} (@code{next}) to advance execution to
675the next line of the current function.
676
677@smallexample
678(@value{GDBP}) @b{n}
679882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
680 : nil,
681@end smallexample
682
683@noindent
684@code{set_quotes} looks like a promising subroutine. We can go into it
685by using the command @code{s} (@code{step}) instead of @code{next}.
686@code{step} goes to the next line to be executed in @emph{any}
687subroutine, so it steps into @code{set_quotes}.
688
689@smallexample
690(@value{GDBP}) @b{s}
691set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
692 at input.c:530
693530 if (lquote != def_lquote)
694@end smallexample
695
696@noindent
697The display that shows the subroutine where @code{m4} is now
698suspended (and its arguments) is called a stack frame display. It
699shows a summary of the stack. We can use the @code{backtrace}
700command (which can also be spelled @code{bt}), to see where we are
701in the stack as a whole: the @code{backtrace} command displays a
702stack frame for each active subroutine.
703
704@smallexample
705(@value{GDBP}) @b{bt}
706#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
707 at input.c:530
5d161b24 708#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
709 at builtin.c:882
710#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
711#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
712 at macro.c:71
713#4 0x79dc in expand_input () at macro.c:40
714#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
715@end smallexample
716
717@noindent
718We step through a few more lines to see what happens. The first two
719times, we can use @samp{s}; the next two times we use @code{n} to avoid
720falling into the @code{xstrdup} subroutine.
721
722@smallexample
723(@value{GDBP}) @b{s}
7240x3b5c 532 if (rquote != def_rquote)
725(@value{GDBP}) @b{s}
7260x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
727def_lquote : xstrdup(lq);
728(@value{GDBP}) @b{n}
729536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
730 : xstrdup(rq);
731(@value{GDBP}) @b{n}
732538 len_lquote = strlen(rquote);
733@end smallexample
734
735@noindent
736The last line displayed looks a little odd; we can examine the variables
737@code{lquote} and @code{rquote} to see if they are in fact the new left
738and right quotes we specified. We use the command @code{p}
739(@code{print}) to see their values.
740
741@smallexample
742(@value{GDBP}) @b{p lquote}
743$1 = 0x35d40 "<QUOTE>"
744(@value{GDBP}) @b{p rquote}
745$2 = 0x35d50 "<UNQUOTE>"
746@end smallexample
747
748@noindent
749@code{lquote} and @code{rquote} are indeed the new left and right quotes.
750To look at some context, we can display ten lines of source
751surrounding the current line with the @code{l} (@code{list}) command.
752
753@smallexample
754(@value{GDBP}) @b{l}
755533 xfree(rquote);
756534
757535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
758 : xstrdup (lq);
759536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
760 : xstrdup (rq);
761537
762538 len_lquote = strlen(rquote);
763539 len_rquote = strlen(lquote);
764540 @}
765541
766542 void
767@end smallexample
768
769@noindent
770Let us step past the two lines that set @code{len_lquote} and
771@code{len_rquote}, and then examine the values of those variables.
772
773@smallexample
774(@value{GDBP}) @b{n}
775539 len_rquote = strlen(lquote);
776(@value{GDBP}) @b{n}
777540 @}
778(@value{GDBP}) @b{p len_lquote}
779$3 = 9
780(@value{GDBP}) @b{p len_rquote}
781$4 = 7
782@end smallexample
783
784@noindent
785That certainly looks wrong, assuming @code{len_lquote} and
786@code{len_rquote} are meant to be the lengths of @code{lquote} and
787@code{rquote} respectively. We can set them to better values using
788the @code{p} command, since it can print the value of
789any expression---and that expression can include subroutine calls and
790assignments.
791
792@smallexample
793(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
794$5 = 7
795(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
796$6 = 9
797@end smallexample
798
799@noindent
800Is that enough to fix the problem of using the new quotes with the
801@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
802executing with the @code{c} (@code{continue}) command, and then try the
803example that caused trouble initially:
804
805@smallexample
806(@value{GDBP}) @b{c}
807Continuing.
808
809@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
810
811baz
8120000
813@end smallexample
814
815@noindent
816Success! The new quotes now work just as well as the default ones. The
817problem seems to have been just the two typos defining the wrong
818lengths. We allow @code{m4} exit by giving it an EOF as input:
819
820@smallexample
c8aa23ab 821@b{Ctrl-d}
c906108c
SS
822Program exited normally.
823@end smallexample
824
825@noindent
826The message @samp{Program exited normally.} is from @value{GDBN}; it
827indicates @code{m4} has finished executing. We can end our @value{GDBN}
828session with the @value{GDBN} @code{quit} command.
829
830@smallexample
831(@value{GDBP}) @b{quit}
832@end smallexample
c906108c 833
6d2ebf8b 834@node Invocation
c906108c
SS
835@chapter Getting In and Out of @value{GDBN}
836
837This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 838The essentials are:
c906108c 839@itemize @bullet
5d161b24 840@item
53a5351d 841type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 842@item
c8aa23ab 843type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
844@end itemize
845
846@menu
847* Invoking GDB:: How to start @value{GDBN}
848* Quitting GDB:: How to quit @value{GDBN}
849* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 850* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
851@end menu
852
6d2ebf8b 853@node Invoking GDB
c906108c
SS
854@section Invoking @value{GDBN}
855
c906108c
SS
856Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
857@value{GDBN} reads commands from the terminal until you tell it to exit.
858
859You can also run @code{@value{GDBP}} with a variety of arguments and options,
860to specify more of your debugging environment at the outset.
861
c906108c
SS
862The command-line options described here are designed
863to cover a variety of situations; in some environments, some of these
5d161b24 864options may effectively be unavailable.
c906108c
SS
865
866The most usual way to start @value{GDBN} is with one argument,
867specifying an executable program:
868
474c8240 869@smallexample
c906108c 870@value{GDBP} @var{program}
474c8240 871@end smallexample
c906108c 872
c906108c
SS
873@noindent
874You can also start with both an executable program and a core file
875specified:
876
474c8240 877@smallexample
c906108c 878@value{GDBP} @var{program} @var{core}
474c8240 879@end smallexample
c906108c 880
4ed4690f
SM
881You can, instead, specify a process ID as a second argument or use option
882@code{-p}, if you want to debug a running process:
c906108c 883
474c8240 884@smallexample
c906108c 885@value{GDBP} @var{program} 1234
4ed4690f 886@value{GDBP} -p 1234
474c8240 887@end smallexample
c906108c
SS
888
889@noindent
4ed4690f
SM
890would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
891can omit the @var{program} filename.
c906108c 892
c906108c 893Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
894complete operating system; when you use @value{GDBN} as a remote
895debugger attached to a bare board, there may not be any notion of
896``process'', and there is often no way to get a core dump. @value{GDBN}
897will warn you if it is unable to attach or to read core dumps.
c906108c 898
aa26fa3a
TT
899You can optionally have @code{@value{GDBP}} pass any arguments after the
900executable file to the inferior using @code{--args}. This option stops
901option processing.
474c8240 902@smallexample
3f94c067 903@value{GDBP} --args gcc -O2 -c foo.c
474c8240 904@end smallexample
aa26fa3a
TT
905This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
906@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
907
96a2c332 908You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 909@value{GDBN}'s non-warranty, by specifying @code{--silent}
910(or @code{-q}/@code{--quiet}):
c906108c
SS
911
912@smallexample
adcc0a31 913@value{GDBP} --silent
c906108c
SS
914@end smallexample
915
916@noindent
917You can further control how @value{GDBN} starts up by using command-line
918options. @value{GDBN} itself can remind you of the options available.
919
920@noindent
921Type
922
474c8240 923@smallexample
c906108c 924@value{GDBP} -help
474c8240 925@end smallexample
c906108c
SS
926
927@noindent
928to display all available options and briefly describe their use
929(@samp{@value{GDBP} -h} is a shorter equivalent).
930
931All options and command line arguments you give are processed
932in sequential order. The order makes a difference when the
933@samp{-x} option is used.
934
935
936@menu
c906108c
SS
937* File Options:: Choosing files
938* Mode Options:: Choosing modes
6fc08d32 939* Startup:: What @value{GDBN} does during startup
c906108c
SS
940@end menu
941
6d2ebf8b 942@node File Options
79a6e687 943@subsection Choosing Files
c906108c 944
2df3850c 945When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
946specifying an executable file and core file (or process ID). This is
947the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 948@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
949first argument that does not have an associated option flag as
950equivalent to the @samp{-se} option followed by that argument; and the
951second argument that does not have an associated option flag, if any, as
952equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
953If the second argument begins with a decimal digit, @value{GDBN} will
954first attempt to attach to it as a process, and if that fails, attempt
955to open it as a corefile. If you have a corefile whose name begins with
b383017d 956a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 957prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
958
959If @value{GDBN} has not been configured to included core file support,
960such as for most embedded targets, then it will complain about a second
961argument and ignore it.
c906108c
SS
962
963Many options have both long and short forms; both are shown in the
964following list. @value{GDBN} also recognizes the long forms if you truncate
965them, so long as enough of the option is present to be unambiguous.
966(If you prefer, you can flag option arguments with @samp{--} rather
967than @samp{-}, though we illustrate the more usual convention.)
968
d700128c
EZ
969@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
970@c way, both those who look for -foo and --foo in the index, will find
971@c it.
972
c906108c
SS
973@table @code
974@item -symbols @var{file}
975@itemx -s @var{file}
d700128c
EZ
976@cindex @code{--symbols}
977@cindex @code{-s}
c906108c
SS
978Read symbol table from file @var{file}.
979
980@item -exec @var{file}
981@itemx -e @var{file}
d700128c
EZ
982@cindex @code{--exec}
983@cindex @code{-e}
7a292a7a
SS
984Use file @var{file} as the executable file to execute when appropriate,
985and for examining pure data in conjunction with a core dump.
c906108c
SS
986
987@item -se @var{file}
d700128c 988@cindex @code{--se}
c906108c
SS
989Read symbol table from file @var{file} and use it as the executable
990file.
991
c906108c
SS
992@item -core @var{file}
993@itemx -c @var{file}
d700128c
EZ
994@cindex @code{--core}
995@cindex @code{-c}
b383017d 996Use file @var{file} as a core dump to examine.
c906108c 997
19837790
MS
998@item -pid @var{number}
999@itemx -p @var{number}
1000@cindex @code{--pid}
1001@cindex @code{-p}
1002Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
1003
1004@item -command @var{file}
1005@itemx -x @var{file}
d700128c
EZ
1006@cindex @code{--command}
1007@cindex @code{-x}
95433b34
JB
1008Execute commands from file @var{file}. The contents of this file is
1009evaluated exactly as the @code{source} command would.
8150ff9c 1010@xref{Command Files,, Command files}.
c906108c 1011
8a5a3c82
AS
1012@item -eval-command @var{command}
1013@itemx -ex @var{command}
1014@cindex @code{--eval-command}
1015@cindex @code{-ex}
1016Execute a single @value{GDBN} command.
1017
1018This option may be used multiple times to call multiple commands. It may
1019also be interleaved with @samp{-command} as required.
1020
1021@smallexample
1022@value{GDBP} -ex 'target sim' -ex 'load' \
1023 -x setbreakpoints -ex 'run' a.out
1024@end smallexample
1025
8320cc4f
JK
1026@item -init-command @var{file}
1027@itemx -ix @var{file}
1028@cindex @code{--init-command}
1029@cindex @code{-ix}
2d7b58e8
JK
1030Execute commands from file @var{file} before loading the inferior (but
1031after loading gdbinit files).
8320cc4f
JK
1032@xref{Startup}.
1033
1034@item -init-eval-command @var{command}
1035@itemx -iex @var{command}
1036@cindex @code{--init-eval-command}
1037@cindex @code{-iex}
2d7b58e8
JK
1038Execute a single @value{GDBN} command before loading the inferior (but
1039after loading gdbinit files).
8320cc4f
JK
1040@xref{Startup}.
1041
c906108c
SS
1042@item -directory @var{directory}
1043@itemx -d @var{directory}
d700128c
EZ
1044@cindex @code{--directory}
1045@cindex @code{-d}
4b505b12 1046Add @var{directory} to the path to search for source and script files.
c906108c 1047
c906108c
SS
1048@item -r
1049@itemx -readnow
d700128c
EZ
1050@cindex @code{--readnow}
1051@cindex @code{-r}
c906108c
SS
1052Read each symbol file's entire symbol table immediately, rather than
1053the default, which is to read it incrementally as it is needed.
1054This makes startup slower, but makes future operations faster.
53a5351d 1055
97cbe998
SDJ
1056@item --readnever
1057@anchor{--readnever}
1058@cindex @code{--readnever}, command-line option
1059Do not read each symbol file's symbolic debug information. This makes
1060startup faster but at the expense of not being able to perform
1061symbolic debugging. DWARF unwind information is also not read,
1062meaning backtraces may become incomplete or inaccurate. One use of
1063this is when a user simply wants to do the following sequence: attach,
1064dump core, detach. Loading the debugging information in this case is
1065an unnecessary cause of delay.
c906108c
SS
1066@end table
1067
6d2ebf8b 1068@node Mode Options
79a6e687 1069@subsection Choosing Modes
c906108c
SS
1070
1071You can run @value{GDBN} in various alternative modes---for example, in
1072batch mode or quiet mode.
1073
1074@table @code
bf88dd68 1075@anchor{-nx}
c906108c
SS
1076@item -nx
1077@itemx -n
d700128c
EZ
1078@cindex @code{--nx}
1079@cindex @code{-n}
07540c15
DE
1080Do not execute commands found in any initialization file.
1081There are three init files, loaded in the following order:
1082
1083@table @code
1084@item @file{system.gdbinit}
1085This is the system-wide init file.
1086Its location is specified with the @code{--with-system-gdbinit}
1087configure option (@pxref{System-wide configuration}).
1088It is loaded first when @value{GDBN} starts, before command line options
1089have been processed.
ed2a2229
CB
1090@item @file{system.gdbinit.d}
1091This is the system-wide init directory.
1092Its location is specified with the @code{--with-system-gdbinit-dir}
1093configure option (@pxref{System-wide configuration}).
1094Files in this directory are loaded in alphabetical order immediately after
1095system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1096options have been processed. Files need to have a recognized scripting
1097language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1098extension to be interpreted as regular @value{GDBN} commands. @value{GDBN}
1099will not recurse into any subdirectories of this directory.
07540c15
DE
1100@item @file{~/.gdbinit}
1101This is the init file in your home directory.
1102It is loaded next, after @file{system.gdbinit}, and before
1103command options have been processed.
1104@item @file{./.gdbinit}
1105This is the init file in the current directory.
1106It is loaded last, after command line options other than @code{-x} and
1107@code{-ex} have been processed. Command line options @code{-x} and
1108@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1109@end table
1110
1111For further documentation on startup processing, @xref{Startup}.
1112For documentation on how to write command files,
1113@xref{Command Files,,Command Files}.
1114
1115@anchor{-nh}
1116@item -nh
1117@cindex @code{--nh}
1118Do not execute commands found in @file{~/.gdbinit}, the init file
1119in your home directory.
1120@xref{Startup}.
c906108c
SS
1121
1122@item -quiet
d700128c 1123@itemx -silent
c906108c 1124@itemx -q
d700128c
EZ
1125@cindex @code{--quiet}
1126@cindex @code{--silent}
1127@cindex @code{-q}
c906108c
SS
1128``Quiet''. Do not print the introductory and copyright messages. These
1129messages are also suppressed in batch mode.
1130
1131@item -batch
d700128c 1132@cindex @code{--batch}
c906108c
SS
1133Run in batch mode. Exit with status @code{0} after processing all the
1134command files specified with @samp{-x} (and all commands from
1135initialization files, if not inhibited with @samp{-n}). Exit with
1136nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1137in the command files. Batch mode also disables pagination, sets unlimited
1138terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1139off} were in effect (@pxref{Messages/Warnings}).
c906108c 1140
2df3850c
JM
1141Batch mode may be useful for running @value{GDBN} as a filter, for
1142example to download and run a program on another computer; in order to
1143make this more useful, the message
c906108c 1144
474c8240 1145@smallexample
c906108c 1146Program exited normally.
474c8240 1147@end smallexample
c906108c
SS
1148
1149@noindent
2df3850c
JM
1150(which is ordinarily issued whenever a program running under
1151@value{GDBN} control terminates) is not issued when running in batch
1152mode.
1153
1a088d06
AS
1154@item -batch-silent
1155@cindex @code{--batch-silent}
1156Run in batch mode exactly like @samp{-batch}, but totally silently. All
1157@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1158unaffected). This is much quieter than @samp{-silent} and would be useless
1159for an interactive session.
1160
1161This is particularly useful when using targets that give @samp{Loading section}
1162messages, for example.
1163
1164Note that targets that give their output via @value{GDBN}, as opposed to
1165writing directly to @code{stdout}, will also be made silent.
1166
4b0ad762
AS
1167@item -return-child-result
1168@cindex @code{--return-child-result}
1169The return code from @value{GDBN} will be the return code from the child
1170process (the process being debugged), with the following exceptions:
1171
1172@itemize @bullet
1173@item
1174@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1175internal error. In this case the exit code is the same as it would have been
1176without @samp{-return-child-result}.
1177@item
1178The user quits with an explicit value. E.g., @samp{quit 1}.
1179@item
1180The child process never runs, or is not allowed to terminate, in which case
1181the exit code will be -1.
1182@end itemize
1183
1184This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1185when @value{GDBN} is being used as a remote program loader or simulator
1186interface.
1187
2df3850c
JM
1188@item -nowindows
1189@itemx -nw
d700128c
EZ
1190@cindex @code{--nowindows}
1191@cindex @code{-nw}
2df3850c 1192``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1193(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1194interface. If no GUI is available, this option has no effect.
1195
1196@item -windows
1197@itemx -w
d700128c
EZ
1198@cindex @code{--windows}
1199@cindex @code{-w}
2df3850c
JM
1200If @value{GDBN} includes a GUI, then this option requires it to be
1201used if possible.
c906108c
SS
1202
1203@item -cd @var{directory}
d700128c 1204@cindex @code{--cd}
c906108c
SS
1205Run @value{GDBN} using @var{directory} as its working directory,
1206instead of the current directory.
1207
aae1c79a 1208@item -data-directory @var{directory}
8d551b02 1209@itemx -D @var{directory}
aae1c79a 1210@cindex @code{--data-directory}
8d551b02 1211@cindex @code{-D}
aae1c79a
DE
1212Run @value{GDBN} using @var{directory} as its data directory.
1213The data directory is where @value{GDBN} searches for its
1214auxiliary files. @xref{Data Files}.
1215
c906108c
SS
1216@item -fullname
1217@itemx -f
d700128c
EZ
1218@cindex @code{--fullname}
1219@cindex @code{-f}
7a292a7a
SS
1220@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1221subprocess. It tells @value{GDBN} to output the full file name and line
1222number in a standard, recognizable fashion each time a stack frame is
1223displayed (which includes each time your program stops). This
1224recognizable format looks like two @samp{\032} characters, followed by
1225the file name, line number and character position separated by colons,
1226and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1227@samp{\032} characters as a signal to display the source code for the
1228frame.
c906108c 1229
d700128c
EZ
1230@item -annotate @var{level}
1231@cindex @code{--annotate}
1232This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1233effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1234(@pxref{Annotations}). The annotation @var{level} controls how much
1235information @value{GDBN} prints together with its prompt, values of
1236expressions, source lines, and other types of output. Level 0 is the
1237normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1238@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1239that control @value{GDBN}, and level 2 has been deprecated.
1240
265eeb58 1241The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1242(@pxref{GDB/MI}).
d700128c 1243
aa26fa3a
TT
1244@item --args
1245@cindex @code{--args}
1246Change interpretation of command line so that arguments following the
1247executable file are passed as command line arguments to the inferior.
1248This option stops option processing.
1249
2df3850c
JM
1250@item -baud @var{bps}
1251@itemx -b @var{bps}
d700128c
EZ
1252@cindex @code{--baud}
1253@cindex @code{-b}
c906108c
SS
1254Set the line speed (baud rate or bits per second) of any serial
1255interface used by @value{GDBN} for remote debugging.
c906108c 1256
f47b1503
AS
1257@item -l @var{timeout}
1258@cindex @code{-l}
1259Set the timeout (in seconds) of any communication used by @value{GDBN}
1260for remote debugging.
1261
c906108c 1262@item -tty @var{device}
d700128c
EZ
1263@itemx -t @var{device}
1264@cindex @code{--tty}
1265@cindex @code{-t}
c906108c
SS
1266Run using @var{device} for your program's standard input and output.
1267@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1268
53a5351d 1269@c resolve the situation of these eventually
c4555f82
SC
1270@item -tui
1271@cindex @code{--tui}
d0d5df6f
AC
1272Activate the @dfn{Text User Interface} when starting. The Text User
1273Interface manages several text windows on the terminal, showing
1274source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1275(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1276option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1277Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1278
d700128c
EZ
1279@item -interpreter @var{interp}
1280@cindex @code{--interpreter}
1281Use the interpreter @var{interp} for interface with the controlling
1282program or device. This option is meant to be set by programs which
94bbb2c0 1283communicate with @value{GDBN} using it as a back end.
21c294e6 1284@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1285
b4be1b06
SM
1286@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1287@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1288The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1289version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1290included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1291interfaces are no longer supported.
d700128c
EZ
1292
1293@item -write
1294@cindex @code{--write}
1295Open the executable and core files for both reading and writing. This
1296is equivalent to the @samp{set write on} command inside @value{GDBN}
1297(@pxref{Patching}).
1298
1299@item -statistics
1300@cindex @code{--statistics}
1301This option causes @value{GDBN} to print statistics about time and
1302memory usage after it completes each command and returns to the prompt.
1303
1304@item -version
1305@cindex @code{--version}
1306This option causes @value{GDBN} to print its version number and
1307no-warranty blurb, and exit.
1308
6eaaf48b
EZ
1309@item -configuration
1310@cindex @code{--configuration}
1311This option causes @value{GDBN} to print details about its build-time
1312configuration parameters, and then exit. These details can be
1313important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1314
c906108c
SS
1315@end table
1316
6fc08d32 1317@node Startup
79a6e687 1318@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1319@cindex @value{GDBN} startup
1320
1321Here's the description of what @value{GDBN} does during session startup:
1322
1323@enumerate
1324@item
1325Sets up the command interpreter as specified by the command line
1326(@pxref{Mode Options, interpreter}).
1327
1328@item
1329@cindex init file
098b41a6
JG
1330Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1331used when building @value{GDBN}; @pxref{System-wide configuration,
ed2a2229
CB
1332 ,System-wide configuration and settings}) and the files in the system-wide
1333gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1334all the commands in those files. The files need to be named with a @file{.gdb}
1335extension to be interpreted as @value{GDBN} commands, or they can be written
1336in a supported scripting language with an appropriate file extension.
098b41a6 1337
bf88dd68 1338@anchor{Home Directory Init File}
098b41a6
JG
1339@item
1340Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1341DOS/Windows systems, the home directory is the one pointed to by the
1342@code{HOME} environment variable.} and executes all the commands in
1343that file.
1344
2d7b58e8
JK
1345@anchor{Option -init-eval-command}
1346@item
1347Executes commands and command files specified by the @samp{-iex} and
1348@samp{-ix} options in their specified order. Usually you should use the
1349@samp{-ex} and @samp{-x} options instead, but this way you can apply
1350settings before @value{GDBN} init files get executed and before inferior
1351gets loaded.
1352
6fc08d32
EZ
1353@item
1354Processes command line options and operands.
1355
bf88dd68 1356@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1357@item
1358Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1359working directory as long as @samp{set auto-load local-gdbinit} is set to
1360@samp{on} (@pxref{Init File in the Current Directory}).
1361This is only done if the current directory is
119b882a
EZ
1362different from your home directory. Thus, you can have more than one
1363init file, one generic in your home directory, and another, specific
1364to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1365@value{GDBN}.
1366
a86caf66
DE
1367@item
1368If the command line specified a program to debug, or a process to
1369attach to, or a core file, @value{GDBN} loads any auto-loaded
1370scripts provided for the program or for its loaded shared libraries.
1371@xref{Auto-loading}.
1372
1373If you wish to disable the auto-loading during startup,
1374you must do something like the following:
1375
1376@smallexample
bf88dd68 1377$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1378@end smallexample
1379
8320cc4f
JK
1380Option @samp{-ex} does not work because the auto-loading is then turned
1381off too late.
a86caf66 1382
6fc08d32 1383@item
6fe37d23
JK
1384Executes commands and command files specified by the @samp{-ex} and
1385@samp{-x} options in their specified order. @xref{Command Files}, for
1386more details about @value{GDBN} command files.
6fc08d32
EZ
1387
1388@item
1389Reads the command history recorded in the @dfn{history file}.
d620b259 1390@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1391files where @value{GDBN} records it.
1392@end enumerate
1393
1394Init files use the same syntax as @dfn{command files} (@pxref{Command
1395Files}) and are processed by @value{GDBN} in the same way. The init
1396file in your home directory can set options (such as @samp{set
1397complaints}) that affect subsequent processing of command line options
1398and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1399option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1400
098b41a6
JG
1401To display the list of init files loaded by gdb at startup, you
1402can use @kbd{gdb --help}.
1403
6fc08d32
EZ
1404@cindex init file name
1405@cindex @file{.gdbinit}
119b882a 1406@cindex @file{gdb.ini}
8807d78b 1407The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1408The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1409the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1410port of @value{GDBN} uses the standard name, but if it finds a
1411@file{gdb.ini} file in your home directory, it warns you about that
1412and suggests to rename the file to the standard name.
119b882a 1413
6fc08d32 1414
6d2ebf8b 1415@node Quitting GDB
c906108c
SS
1416@section Quitting @value{GDBN}
1417@cindex exiting @value{GDBN}
1418@cindex leaving @value{GDBN}
1419
1420@table @code
1421@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1422@kindex q @r{(@code{quit})}
96a2c332
SS
1423@item quit @r{[}@var{expression}@r{]}
1424@itemx q
1425To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1426@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1427do not supply @var{expression}, @value{GDBN} will terminate normally;
1428otherwise it will terminate using the result of @var{expression} as the
1429error code.
c906108c
SS
1430@end table
1431
1432@cindex interrupt
c8aa23ab 1433An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1434terminates the action of any @value{GDBN} command that is in progress and
1435returns to @value{GDBN} command level. It is safe to type the interrupt
1436character at any time because @value{GDBN} does not allow it to take effect
1437until a time when it is safe.
1438
c906108c
SS
1439If you have been using @value{GDBN} to control an attached process or
1440device, you can release it with the @code{detach} command
79a6e687 1441(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1442
6d2ebf8b 1443@node Shell Commands
79a6e687 1444@section Shell Commands
c906108c
SS
1445
1446If you need to execute occasional shell commands during your
1447debugging session, there is no need to leave or suspend @value{GDBN}; you can
1448just use the @code{shell} command.
1449
1450@table @code
1451@kindex shell
ed59ded5 1452@kindex !
c906108c 1453@cindex shell escape
ed59ded5
DE
1454@item shell @var{command-string}
1455@itemx !@var{command-string}
1456Invoke a standard shell to execute @var{command-string}.
1457Note that no space is needed between @code{!} and @var{command-string}.
edf92af0
EZ
1458On GNU and Unix systems, the environment variable @code{SHELL}, if it
1459exists, determines which shell to run. Otherwise @value{GDBN} uses
1460the default shell (@file{/bin/sh} on GNU and Unix systems,
1461@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1462@end table
1463
1464The utility @code{make} is often needed in development environments.
1465You do not have to use the @code{shell} command for this purpose in
1466@value{GDBN}:
1467
1468@table @code
1469@kindex make
1470@cindex calling make
1471@item make @var{make-args}
1472Execute the @code{make} program with the specified
1473arguments. This is equivalent to @samp{shell make @var{make-args}}.
1474@end table
1475
e2c52041
PW
1476@table @code
1477@kindex pipe
1478@kindex |
1479@cindex send the output of a gdb command to a shell command
1480@anchor{pipe}
1481@item pipe [@var{command}] | @var{shell_command}
1482@itemx | [@var{command}] | @var{shell_command}
1483@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1484@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1485Executes @var{command} and sends its output to @var{shell_command}.
1486Note that no space is needed around @code{|}.
1487If no @var{command} is provided, the last command executed is repeated.
1488
1489In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1490can be used to specify an alternate delimiter string @var{delim} that separates
1491the @var{command} from the @var{shell_command}.
1492
1493Example:
1494@smallexample
1495@group
1496(gdb) p var
1497$1 = @{
1498 black = 144,
1499 red = 233,
1500 green = 377,
1501 blue = 610,
1502 white = 987
1503@}
1504@end group
1505@group
1506(gdb) pipe p var|wc
1507 7 19 80
1508(gdb) |p var|wc -l
15097
1510@end group
1511@group
1512(gdb) p /x var
1513$4 = @{
1514 black = 0x90,
1515 red = 0xe9,
1516 green = 0x179,
1517 blue = 0x262,
1518 white = 0x3db
1519@}
1520(gdb) ||grep red
1521 red => 0xe9,
1522@end group
1523@group
1524(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1525this contains a PIPE char
1526(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1527this contains a PIPE char!
1528(gdb)
1529@end group
1530@end smallexample
1531@end table
1532
1533The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1534can be used to examine the exit status of the last shell command launched
1535by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1536@xref{Convenience Vars,, Convenience Variables}.
1537
79a6e687
BW
1538@node Logging Output
1539@section Logging Output
0fac0b41 1540@cindex logging @value{GDBN} output
9c16f35a 1541@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1542
1543You may want to save the output of @value{GDBN} commands to a file.
1544There are several commands to control @value{GDBN}'s logging.
1545
1546@table @code
1547@kindex set logging
1548@item set logging on
1549Enable logging.
1550@item set logging off
1551Disable logging.
9c16f35a 1552@cindex logging file name
0fac0b41
DJ
1553@item set logging file @var{file}
1554Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1555@item set logging overwrite [on|off]
1556By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1557you want @code{set logging on} to overwrite the logfile instead.
1558@item set logging redirect [on|off]
1559By default, @value{GDBN} output will go to both the terminal and the logfile.
1560Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1561@item set logging debugredirect [on|off]
1562By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1563Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1564@kindex show logging
1565@item show logging
1566Show the current values of the logging settings.
1567@end table
1568
e2c52041
PW
1569You can also redirect the output of a @value{GDBN} command to a
1570shell command. @xref{pipe}.
6d2ebf8b 1571@node Commands
c906108c
SS
1572@chapter @value{GDBN} Commands
1573
1574You can abbreviate a @value{GDBN} command to the first few letters of the command
1575name, if that abbreviation is unambiguous; and you can repeat certain
1576@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1577key to get @value{GDBN} to fill out the rest of a word in a command (or to
1578show you the alternatives available, if there is more than one possibility).
1579
1580@menu
1581* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1582* Command Settings:: How to change default behavior of commands
c906108c 1583* Completion:: Command completion
3345721a 1584* Command Options:: Command options
5b860c93 1585* Command aliases default args:: Automatically prepend default arguments to user-defined aliases
c906108c
SS
1586* Help:: How to ask @value{GDBN} for help
1587@end menu
1588
6d2ebf8b 1589@node Command Syntax
79a6e687 1590@section Command Syntax
c906108c
SS
1591
1592A @value{GDBN} command is a single line of input. There is no limit on
1593how long it can be. It starts with a command name, which is followed by
1594arguments whose meaning depends on the command name. For example, the
1595command @code{step} accepts an argument which is the number of times to
1596step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1597with no arguments. Some commands do not allow any arguments.
c906108c
SS
1598
1599@cindex abbreviation
1600@value{GDBN} command names may always be truncated if that abbreviation is
1601unambiguous. Other possible command abbreviations are listed in the
1602documentation for individual commands. In some cases, even ambiguous
1603abbreviations are allowed; for example, @code{s} is specially defined as
1604equivalent to @code{step} even though there are other commands whose
1605names start with @code{s}. You can test abbreviations by using them as
1606arguments to the @code{help} command.
1607
1608@cindex repeating commands
41afff9a 1609@kindex RET @r{(repeat last command)}
c906108c 1610A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1611repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1612will not repeat this way; these are commands whose unintentional
1613repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1614repeat. User-defined commands can disable this feature; see
1615@ref{Define, dont-repeat}.
c906108c
SS
1616
1617The @code{list} and @code{x} commands, when you repeat them with
1618@key{RET}, construct new arguments rather than repeating
1619exactly as typed. This permits easy scanning of source or memory.
1620
1621@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1622output, in a way similar to the common utility @code{more}
79a6e687 1623(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1624@key{RET} too many in this situation, @value{GDBN} disables command
1625repetition after any command that generates this sort of display.
1626
41afff9a 1627@kindex # @r{(a comment)}
c906108c
SS
1628@cindex comment
1629Any text from a @kbd{#} to the end of the line is a comment; it does
1630nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1631Files,,Command Files}).
c906108c 1632
88118b3a 1633@cindex repeating command sequences
c8aa23ab
EZ
1634@kindex Ctrl-o @r{(operate-and-get-next)}
1635The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1636commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1637then fetches the next line relative to the current line from the history
1638for editing.
1639
fdbc9870
PA
1640
1641@node Command Settings
1642@section Command Settings
1643@cindex default behavior of commands, changing
1644@cindex default settings, changing
1645
1646Many commands change their behavior according to command-specific
1647variables or settings. These settings can be changed with the
1648@code{set} subcommands. For example, the @code{print} command
1649(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1650settings changeable with the commands @code{set print elements
1651NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1652
1653You can change these settings to your preference in the gdbinit files
1654loaded at @value{GDBN} startup. @xref{Startup}.
1655
1656The settings can also be changed interactively during the debugging
1657session. For example, to change the limit of array elements to print,
1658you can do the following:
1659@smallexample
1660(@value{GDBN}) set print elements 10
1661(@value{GDBN}) print some_array
1662$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1663@end smallexample
1664
1665The above @code{set print elements 10} command changes the number of
1666elements to print from the default of 200 to 10. If you only intend
1667this limit of 10 to be used for printing @code{some_array}, then you
1668must restore the limit back to 200, with @code{set print elements
1669200}.
1670
1671Some commands allow overriding settings with command options. For
1672example, the @code{print} command supports a number of options that
1673allow overriding relevant global print settings as set by @code{set
1674print} subcommands. @xref{print options}. The example above could be
1675rewritten as:
1676@smallexample
1677(@value{GDBN}) print -elements 10 -- some_array
1678$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1679@end smallexample
1680
1681Alternatively, you can use the @code{with} command to change a setting
1682temporarily, for the duration of a command invocation.
1683
1684@table @code
1685@kindex with command
1686@kindex w @r{(@code{with})}
1687@cindex settings
1688@cindex temporarily change settings
1689@item with @var{setting} [@var{value}] [-- @var{command}]
1690@itemx w @var{setting} [@var{value}] [-- @var{command}]
1691Temporarily set @var{setting} to @var{value} for the duration of
1692@var{command}.
1693
1694@var{setting} is any setting you can change with the @code{set}
1695subcommands. @var{value} is the value to assign to @code{setting}
1696while running @code{command}.
1697
1698If no @var{command} is provided, the last command executed is
1699repeated.
1700
1701If a @var{command} is provided, it must be preceded by a double dash
1702(@code{--}) separator. This is required because some settings accept
1703free-form arguments, such as expressions or filenames.
1704
1705For example, the command
1706@smallexample
1707(@value{GDBN}) with print array on -- print some_array
1708@end smallexample
1709@noindent
1710is equivalent to the following 3 commands:
1711@smallexample
1712(@value{GDBN}) set print array on
1713(@value{GDBN}) print some_array
1714(@value{GDBN}) set print array off
1715@end smallexample
1716
1717The @code{with} command is particularly useful when you want to
1718override a setting while running user-defined commands, or commands
1719defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1720
1721@smallexample
1722(@value{GDBN}) with print pretty on -- my_complex_command
1723@end smallexample
1724
1725To change several settings for the same command, you can nest
1726@code{with} commands. For example, @code{with language ada -- with
1727print elements 10} temporarily changes the language to Ada and sets a
1728limit of 10 elements to print for arrays and strings.
1729
1730@end table
1731
6d2ebf8b 1732@node Completion
79a6e687 1733@section Command Completion
c906108c
SS
1734
1735@cindex completion
1736@cindex word completion
1737@value{GDBN} can fill in the rest of a word in a command for you, if there is
1738only one possibility; it can also show you what the valid possibilities
1739are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1740commands, @value{GDBN} subcommands, command options, and the names of symbols
1741in your program.
c906108c
SS
1742
1743Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1744of a word. If there is only one possibility, @value{GDBN} fills in the
1745word, and waits for you to finish the command (or press @key{RET} to
1746enter it). For example, if you type
1747
1748@c FIXME "@key" does not distinguish its argument sufficiently to permit
1749@c complete accuracy in these examples; space introduced for clarity.
1750@c If texinfo enhancements make it unnecessary, it would be nice to
1751@c replace " @key" by "@key" in the following...
474c8240 1752@smallexample
c906108c 1753(@value{GDBP}) info bre @key{TAB}
474c8240 1754@end smallexample
c906108c
SS
1755
1756@noindent
1757@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1758the only @code{info} subcommand beginning with @samp{bre}:
1759
474c8240 1760@smallexample
c906108c 1761(@value{GDBP}) info breakpoints
474c8240 1762@end smallexample
c906108c
SS
1763
1764@noindent
1765You can either press @key{RET} at this point, to run the @code{info
1766breakpoints} command, or backspace and enter something else, if
1767@samp{breakpoints} does not look like the command you expected. (If you
1768were sure you wanted @code{info breakpoints} in the first place, you
1769might as well just type @key{RET} immediately after @samp{info bre},
1770to exploit command abbreviations rather than command completion).
1771
1772If there is more than one possibility for the next word when you press
1773@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1774characters and try again, or just press @key{TAB} a second time;
1775@value{GDBN} displays all the possible completions for that word. For
1776example, you might want to set a breakpoint on a subroutine whose name
1777begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1778just sounds the bell. Typing @key{TAB} again displays all the
1779function names in your program that begin with those characters, for
1780example:
1781
474c8240 1782@smallexample
c906108c
SS
1783(@value{GDBP}) b make_ @key{TAB}
1784@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1785make_a_section_from_file make_environ
1786make_abs_section make_function_type
1787make_blockvector make_pointer_type
1788make_cleanup make_reference_type
c906108c
SS
1789make_command make_symbol_completion_list
1790(@value{GDBP}) b make_
474c8240 1791@end smallexample
c906108c
SS
1792
1793@noindent
1794After displaying the available possibilities, @value{GDBN} copies your
1795partial input (@samp{b make_} in the example) so you can finish the
1796command.
1797
1798If you just want to see the list of alternatives in the first place, you
b37052ae 1799can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1800means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1801key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1802one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1803
ef0b411a
GB
1804If the number of possible completions is large, @value{GDBN} will
1805print as much of the list as it has collected, as well as a message
1806indicating that the list may be truncated.
1807
1808@smallexample
1809(@value{GDBP}) b m@key{TAB}@key{TAB}
1810main
1811<... the rest of the possible completions ...>
1812*** List may be truncated, max-completions reached. ***
1813(@value{GDBP}) b m
1814@end smallexample
1815
1816@noindent
1817This behavior can be controlled with the following commands:
1818
1819@table @code
1820@kindex set max-completions
1821@item set max-completions @var{limit}
1822@itemx set max-completions unlimited
1823Set the maximum number of completion candidates. @value{GDBN} will
1824stop looking for more completions once it collects this many candidates.
1825This is useful when completing on things like function names as collecting
1826all the possible candidates can be time consuming.
1827The default value is 200. A value of zero disables tab-completion.
1828Note that setting either no limit or a very large limit can make
1829completion slow.
1830@kindex show max-completions
1831@item show max-completions
1832Show the maximum number of candidates that @value{GDBN} will collect and show
1833during completion.
1834@end table
1835
c906108c
SS
1836@cindex quotes in commands
1837@cindex completion of quoted strings
1838Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1839parentheses or other characters that @value{GDBN} normally excludes from
1840its notion of a word. To permit word completion to work in this
1841situation, you may enclose words in @code{'} (single quote marks) in
1842@value{GDBN} commands.
c906108c 1843
d044bac8
PA
1844A likely situation where you might need this is in typing an
1845expression that involves a C@t{++} symbol name with template
1846parameters. This is because when completing expressions, GDB treats
1847the @samp{<} character as word delimiter, assuming that it's the
1848less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1849Operators}).
1850
1851For example, when you want to call a C@t{++} template function
1852interactively using the @code{print} or @code{call} commands, you may
1853need to distinguish whether you mean the version of @code{name} that
1854was specialized for @code{int}, @code{name<int>()}, or the version
1855that was specialized for @code{float}, @code{name<float>()}. To use
1856the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1857@code{'} at the beginning of the function name. This alerts
1858@value{GDBN} that it may need to consider more information than usual
1859when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1860
474c8240 1861@smallexample
d044bac8
PA
1862(@value{GDBP}) p 'func< @kbd{M-?}
1863func<int>() func<float>()
1864(@value{GDBP}) p 'func<
474c8240 1865@end smallexample
c906108c 1866
d044bac8
PA
1867When setting breakpoints however (@pxref{Specify Location}), you don't
1868usually need to type a quote before the function name, because
1869@value{GDBN} understands that you want to set a breakpoint on a
1870function:
c906108c 1871
474c8240 1872@smallexample
d044bac8
PA
1873(@value{GDBP}) b func< @kbd{M-?}
1874func<int>() func<float>()
1875(@value{GDBP}) b func<
474c8240 1876@end smallexample
c906108c 1877
d044bac8
PA
1878This is true even in the case of typing the name of C@t{++} overloaded
1879functions (multiple definitions of the same function, distinguished by
1880argument type). For example, when you want to set a breakpoint you
1881don't need to distinguish whether you mean the version of @code{name}
1882that takes an @code{int} parameter, @code{name(int)}, or the version
1883that takes a @code{float} parameter, @code{name(float)}.
1884
1885@smallexample
1886(@value{GDBP}) b bubble( @kbd{M-?}
1887bubble(int) bubble(double)
1888(@value{GDBP}) b bubble(dou @kbd{M-?}
1889bubble(double)
1890@end smallexample
1891
1892See @ref{quoting names} for a description of other scenarios that
1893require quoting.
c906108c 1894
79a6e687
BW
1895For more information about overloaded functions, see @ref{C Plus Plus
1896Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1897overload-resolution off} to disable overload resolution;
79a6e687 1898see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1899
65d12d83
TT
1900@cindex completion of structure field names
1901@cindex structure field name completion
1902@cindex completion of union field names
1903@cindex union field name completion
1904When completing in an expression which looks up a field in a
1905structure, @value{GDBN} also tries@footnote{The completer can be
1906confused by certain kinds of invalid expressions. Also, it only
1907examines the static type of the expression, not the dynamic type.} to
1908limit completions to the field names available in the type of the
1909left-hand-side:
1910
1911@smallexample
1912(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1913magic to_fputs to_rewind
1914to_data to_isatty to_write
1915to_delete to_put to_write_async_safe
1916to_flush to_read
65d12d83
TT
1917@end smallexample
1918
1919@noindent
1920This is because the @code{gdb_stdout} is a variable of the type
1921@code{struct ui_file} that is defined in @value{GDBN} sources as
1922follows:
1923
1924@smallexample
1925struct ui_file
1926@{
1927 int *magic;
1928 ui_file_flush_ftype *to_flush;
1929 ui_file_write_ftype *to_write;
01124a23 1930 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1931 ui_file_fputs_ftype *to_fputs;
1932 ui_file_read_ftype *to_read;
1933 ui_file_delete_ftype *to_delete;
1934 ui_file_isatty_ftype *to_isatty;
1935 ui_file_rewind_ftype *to_rewind;
1936 ui_file_put_ftype *to_put;
1937 void *to_data;
1938@}
1939@end smallexample
1940
3345721a
PA
1941@node Command Options
1942@section Command options
1943
1944@cindex command options
1945Some commands accept options starting with a leading dash. For
1946example, @code{print -pretty}. Similarly to command names, you can
1947abbreviate a @value{GDBN} option to the first few letters of the
1948option name, if that abbreviation is unambiguous, and you can also use
1949the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1950in an option (or to show you the alternatives available, if there is
1951more than one possibility).
1952
1953@cindex command options, raw input
1954Some commands take raw input as argument. For example, the print
1955command processes arbitrary expressions in any of the languages
1956supported by @value{GDBN}. With such commands, because raw input may
1957start with a leading dash that would be confused with an option or any
d8edc8b7
PW
1958of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1959-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
1960option, then you must use a double-dash (@code{--}) delimiter to
1961indicate the end of options.
1962
1963@cindex command options, boolean
1964
1965Some options are described as accepting an argument which can be
1966either @code{on} or @code{off}. These are known as @dfn{boolean
1967options}. Similarly to boolean settings commands---@code{on} and
1968@code{off} are the typical values, but any of @code{1}, @code{yes} and
1969@code{enable} can also be used as ``true'' value, and any of @code{0},
1970@code{no} and @code{disable} can also be used as ``false'' value. You
1971can also omit a ``true'' value, as it is implied by default.
1972
1973For example, these are equivalent:
1974
1975@smallexample
1976(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1977(@value{GDBP}) p -o -p 0 -e u -- *myptr
1978@end smallexample
1979
1980You can discover the set of options some command accepts by completing
1981on @code{-} after the command name. For example:
1982
1983@smallexample
1984(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
1985-address -max-depth -raw-values -union
1986-array -null-stop -repeats -vtbl
1987-array-indexes -object -static-members
1988-elements -pretty -symbol
3345721a
PA
1989@end smallexample
1990
1991Completion will in some cases guide you with a suggestion of what kind
1992of argument an option expects. For example:
1993
1994@smallexample
1995(@value{GDBP}) print -elements @key{TAB}@key{TAB}
1996NUMBER unlimited
1997@end smallexample
1998
1999Here, the option expects a number (e.g., @code{100}), not literal
2000@code{NUMBER}. Such metasyntactical arguments are always presented in
2001uppercase.
2002
2003(For more on using the @code{print} command, see @ref{Data, ,Examining
2004Data}.)
c906108c 2005
5b860c93
PW
2006@node Command aliases default args
2007@section Automatically prepend default arguments to user-defined aliases
2008
2009You can tell @value{GDBN} to always prepend some default arguments to
2010the list of arguments provided explicitly by the user when using a
2011user-defined alias.
2012
2013If you repeatedly use the same arguments or options for a command, you
2014can define an alias for this command and tell @value{GDBN} to
2015automatically prepend these arguments or options to the list of
2016arguments you type explicitly when using the alias@footnote{@value{GDBN}
2017could easily accept default arguments for pre-defined commands and aliases,
2018but it was deemed this would be confusing, and so is not allowed.}.
2019
2020For example, if you often use the command @code{thread apply all}
2021specifying to work on the threads in ascending order and to continue in case it
2022encounters an error, you can tell @value{GDBN} to automatically preprend
2023the @code{-ascending} and @code{-c} options by using:
2024
2025@smallexample
2026(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2027@end smallexample
2028
2029Once you have defined this alias with its default args, any time you type
2030the @code{thread apply asc-all} followed by @code{some arguments},
2031@value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2032
2033To have even less to type, you can also define a one word alias:
2034@smallexample
2035(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2036@end smallexample
2037
2038As usual, unambiguous abbreviations can be used for @var{alias}
2039and @var{default-args}.
2040
2041The different aliases of a command do not share their default args.
2042For example, you define a new alias @code{bt_ALL} showing all possible
2043information and another alias @code{bt_SMALL} showing very limited information
2044using:
2045@smallexample
2046(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2047 -past-main -past-entry -full
2048(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2049 -past-main off -past-entry off
2050@end smallexample
2051
2052(For more on using the @code{alias} command, see @ref{Aliases}.)
2053
2054Default args are not limited to the arguments and options of @var{command},
2055but can specify nested commands if @var{command} accepts such a nested command
2056as argument.
2057For example, the below defines @code{faalocalsoftype} that lists the
2058frames having locals of a certain type, together with the matching
2059local vars:
2060@smallexample
2061(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2062(@value{GDBP}) faalocalsoftype int
2063#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2064i = 0
2065ret = 21845
2066@end smallexample
2067
2068This is also very useful to define an alias for a set of nested @code{with}
2069commands to have a particular combination of temporary settings. For example,
2070the below defines the alias @code{pp10} that pretty prints an expression
2071argument, with a maximum of 10 elements if the expression is a string or
2072an array:
2073@smallexample
2074(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2075@end smallexample
2076This defines the alias @code{pp10} as being a sequence of 3 commands.
2077The first part @code{with print pretty --} temporarily activates the setting
2078@code{set print pretty}, then launches the command that follows the separator
2079@code{--}.
2080The command following the first part is also a @code{with} command that
2081temporarily changes the setting @code{set print elements} to 10, then
2082launches the command that follows the second separator @code{--}.
2083The third part @code{print} is the command the @code{pp10} alias will launch,
2084using the temporary values of the settings and the arguments explicitly given
2085by the user.
2086For more information about the @code{with} command usage,
2087see @ref{Command Settings}.
2088
6d2ebf8b 2089@node Help
79a6e687 2090@section Getting Help
c906108c
SS
2091@cindex online documentation
2092@kindex help
2093
5d161b24 2094You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2095using the command @code{help}.
2096
2097@table @code
41afff9a 2098@kindex h @r{(@code{help})}
c906108c
SS
2099@item help
2100@itemx h
2101You can use @code{help} (abbreviated @code{h}) with no arguments to
2102display a short list of named classes of commands:
2103
2104@smallexample
2105(@value{GDBP}) help
2106List of classes of commands:
2107
5b860c93 2108aliases -- User-defined aliases of other commands
c906108c 2109breakpoints -- Making program stop at certain points
2df3850c 2110data -- Examining data
c906108c 2111files -- Specifying and examining files
2df3850c
JM
2112internals -- Maintenance commands
2113obscure -- Obscure features
2114running -- Running the program
2115stack -- Examining the stack
c906108c
SS
2116status -- Status inquiries
2117support -- Support facilities
12c27660 2118tracepoints -- Tracing of program execution without
96a2c332 2119 stopping the program
c906108c 2120user-defined -- User-defined commands
c906108c 2121
5d161b24 2122Type "help" followed by a class name for a list of
c906108c 2123commands in that class.
5d161b24 2124Type "help" followed by command name for full
c906108c
SS
2125documentation.
2126Command name abbreviations are allowed if unambiguous.
2127(@value{GDBP})
2128@end smallexample
96a2c332 2129@c the above line break eliminates huge line overfull...
c906108c
SS
2130
2131@item help @var{class}
2132Using one of the general help classes as an argument, you can get a
5b4a1a8d
PW
2133list of the individual commands in that class. If a command has
2134aliases, the aliases are given after the command name, separated by
5b860c93
PW
2135commas. If an alias has default arguments, the full definition of
2136the alias is given after the first line.
2137For example, here is the help display for the class @code{status}:
c906108c
SS
2138
2139@smallexample
2140(@value{GDBP}) help status
2141Status inquiries.
2142
2143List of commands:
2144
2145@c Line break in "show" line falsifies real output, but needed
2146@c to fit in smallbook page size.
5b4a1a8d 2147info, inf, i -- Generic command for showing things
12c27660 2148 about the program being debugged
5b860c93
PW
2149info address, iamain -- Describe where symbol SYM is stored.
2150 alias iamain = info address main
2151info all-registers -- List of all registers and their contents,
2152 for selected stack frame.
5b4a1a8d
PW
2153...
2154show, info set -- Generic command for showing things
12c27660 2155 about the debugger
c906108c 2156
5d161b24 2157Type "help" followed by command name for full
c906108c
SS
2158documentation.
2159Command name abbreviations are allowed if unambiguous.
2160(@value{GDBP})
2161@end smallexample
2162
2163@item help @var{command}
2164With a command name as @code{help} argument, @value{GDBN} displays a
5b4a1a8d
PW
2165short paragraph on how to use that command. If that command has
2166one or more aliases, @value{GDBN} will display a first line with
2167the command name and all its aliases separated by commas.
5b860c93
PW
2168This first line will be followed by the full definition of all aliases
2169having default arguments.
c906108c 2170
6837a0a2 2171@kindex apropos
e664d728 2172@item apropos [-v] @var{regexp}
09d4efe1 2173The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2174commands, and their documentation, for the regular expression specified in
e664d728
PW
2175@var{args}. It prints out all matches found. The optional flag @samp{-v},
2176which stands for @samp{verbose}, indicates to output the full documentation
2177of the matching commands and highlight the parts of the documentation
2178matching @var{regexp}. For example:
6837a0a2
DB
2179
2180@smallexample
16899756 2181apropos alias
6837a0a2
DB
2182@end smallexample
2183
b37052ae
EZ
2184@noindent
2185results in:
6837a0a2
DB
2186
2187@smallexample
e664d728 2188@group
16899756 2189alias -- Define a new command that is an alias of an existing command
5b860c93 2190aliases -- User-defined aliases of other commands
e664d728
PW
2191@end group
2192@end smallexample
2193
2194@noindent
2195while
2196
2197@smallexample
2198apropos -v cut.*thread apply
2199@end smallexample
2200
2201@noindent
2202results in the below output, where @samp{cut for 'thread apply}
2203is highlighted if styling is enabled.
2204
2205@smallexample
2206@group
2207taas -- Apply a command to all threads (ignoring errors
2208and empty output).
2209Usage: taas COMMAND
2210shortcut for 'thread apply all -s COMMAND'
2211
2212tfaas -- Apply a command to all frames of all threads
2213(ignoring errors and empty output).
2214Usage: tfaas COMMAND
2215shortcut for 'thread apply all -s frame apply all -s COMMAND'
2216@end group
6837a0a2
DB
2217@end smallexample
2218
c906108c
SS
2219@kindex complete
2220@item complete @var{args}
2221The @code{complete @var{args}} command lists all the possible completions
2222for the beginning of a command. Use @var{args} to specify the beginning of the
2223command you want completed. For example:
2224
2225@smallexample
2226complete i
2227@end smallexample
2228
2229@noindent results in:
2230
2231@smallexample
2232@group
2df3850c
JM
2233if
2234ignore
c906108c
SS
2235info
2236inspect
c906108c
SS
2237@end group
2238@end smallexample
2239
2240@noindent This is intended for use by @sc{gnu} Emacs.
2241@end table
2242
2243In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2244and @code{show} to inquire about the state of your program, or the state
2245of @value{GDBN} itself. Each command supports many topics of inquiry; this
2246manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2247under @code{info} and under @code{show} in the Command, Variable, and
2248Function Index point to all the sub-commands. @xref{Command and Variable
2249Index}.
c906108c
SS
2250
2251@c @group
2252@table @code
2253@kindex info
41afff9a 2254@kindex i @r{(@code{info})}
c906108c
SS
2255@item info
2256This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2257program. For example, you can show the arguments passed to a function
c906108c
SS
2258with @code{info args}, list the registers currently in use with @code{info
2259registers}, or list the breakpoints you have set with @code{info breakpoints}.
2260You can get a complete list of the @code{info} sub-commands with
2261@w{@code{help info}}.
2262
2263@kindex set
2264@item set
5d161b24 2265You can assign the result of an expression to an environment variable with
c906108c
SS
2266@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2267@code{set prompt $}.
2268
2269@kindex show
2270@item show
5d161b24 2271In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2272@value{GDBN} itself.
2273You can change most of the things you can @code{show}, by using the
2274related command @code{set}; for example, you can control what number
2275system is used for displays with @code{set radix}, or simply inquire
2276which is currently in use with @code{show radix}.
2277
2278@kindex info set
2279To display all the settable parameters and their current
2280values, you can use @code{show} with no arguments; you may also use
2281@code{info set}. Both commands produce the same display.
2282@c FIXME: "info set" violates the rule that "info" is for state of
2283@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2284@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2285@end table
2286@c @end group
2287
6eaaf48b 2288Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2289exceptional in lacking corresponding @code{set} commands:
2290
2291@table @code
2292@kindex show version
9c16f35a 2293@cindex @value{GDBN} version number
c906108c
SS
2294@item show version
2295Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2296information in @value{GDBN} bug-reports. If multiple versions of
2297@value{GDBN} are in use at your site, you may need to determine which
2298version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2299commands are introduced, and old ones may wither away. Also, many
2300system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2301variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2302The version number is the same as the one announced when you start
2303@value{GDBN}.
c906108c
SS
2304
2305@kindex show copying
09d4efe1 2306@kindex info copying
9c16f35a 2307@cindex display @value{GDBN} copyright
c906108c 2308@item show copying
09d4efe1 2309@itemx info copying
c906108c
SS
2310Display information about permission for copying @value{GDBN}.
2311
2312@kindex show warranty
09d4efe1 2313@kindex info warranty
c906108c 2314@item show warranty
09d4efe1 2315@itemx info warranty
2df3850c 2316Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2317if your version of @value{GDBN} comes with one.
2df3850c 2318
6eaaf48b
EZ
2319@kindex show configuration
2320@item show configuration
2321Display detailed information about the way @value{GDBN} was configured
2322when it was built. This displays the optional arguments passed to the
2323@file{configure} script and also configuration parameters detected
2324automatically by @command{configure}. When reporting a @value{GDBN}
2325bug (@pxref{GDB Bugs}), it is important to include this information in
2326your report.
2327
c906108c
SS
2328@end table
2329
6d2ebf8b 2330@node Running
c906108c
SS
2331@chapter Running Programs Under @value{GDBN}
2332
2333When you run a program under @value{GDBN}, you must first generate
2334debugging information when you compile it.
7a292a7a
SS
2335
2336You may start @value{GDBN} with its arguments, if any, in an environment
2337of your choice. If you are doing native debugging, you may redirect
2338your program's input and output, debug an already running process, or
2339kill a child process.
c906108c
SS
2340
2341@menu
2342* Compilation:: Compiling for debugging
2343* Starting:: Starting your program
c906108c
SS
2344* Arguments:: Your program's arguments
2345* Environment:: Your program's environment
c906108c
SS
2346
2347* Working Directory:: Your program's working directory
2348* Input/Output:: Your program's input and output
2349* Attach:: Debugging an already-running process
2350* Kill Process:: Killing the child process
65c574f6
PA
2351* Inferiors Connections and Programs:: Debugging multiple inferiors
2352 connections and programs
c906108c 2353* Threads:: Debugging programs with multiple threads
6c95b8df 2354* Forks:: Debugging forks
5c95884b 2355* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2356@end menu
2357
6d2ebf8b 2358@node Compilation
79a6e687 2359@section Compiling for Debugging
c906108c
SS
2360
2361In order to debug a program effectively, you need to generate
2362debugging information when you compile it. This debugging information
2363is stored in the object file; it describes the data type of each
2364variable or function and the correspondence between source line numbers
2365and addresses in the executable code.
2366
2367To request debugging information, specify the @samp{-g} option when you run
2368the compiler.
2369
514c4d71 2370Programs that are to be shipped to your customers are compiled with
edb3359d 2371optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2372compilers are unable to handle the @samp{-g} and @samp{-O} options
2373together. Using those compilers, you cannot generate optimized
c906108c
SS
2374executables containing debugging information.
2375
514c4d71 2376@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2377without @samp{-O}, making it possible to debug optimized code. We
2378recommend that you @emph{always} use @samp{-g} whenever you compile a
2379program. You may think your program is correct, but there is no sense
edb3359d 2380in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2381
2382Older versions of the @sc{gnu} C compiler permitted a variant option
2383@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2384format; if your @sc{gnu} C compiler has this option, do not use it.
2385
514c4d71
EZ
2386@value{GDBN} knows about preprocessor macros and can show you their
2387expansion (@pxref{Macros}). Most compilers do not include information
2388about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2389the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2390the @sc{gnu} C compiler, provides macro information if you are using
2391the DWARF debugging format, and specify the option @option{-g3}.
2392
2393@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2394gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2395information on @value{NGCC} options affecting debug information.
2396
2397You will have the best debugging experience if you use the latest
2398version of the DWARF debugging format that your compiler supports.
2399DWARF is currently the most expressive and best supported debugging
2400format in @value{GDBN}.
514c4d71 2401
c906108c 2402@need 2000
6d2ebf8b 2403@node Starting
79a6e687 2404@section Starting your Program
c906108c
SS
2405@cindex starting
2406@cindex running
2407
2408@table @code
2409@kindex run
41afff9a 2410@kindex r @r{(@code{run})}
c906108c
SS
2411@item run
2412@itemx r
7a292a7a 2413Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2414You must first specify the program name with an argument to
2415@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2416@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2417command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2418
2419@end table
2420
c906108c
SS
2421If you are running your program in an execution environment that
2422supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2423that process run your program. In some environments without processes,
2424@code{run} jumps to the start of your program. Other targets,
2425like @samp{remote}, are always running. If you get an error
2426message like this one:
2427
2428@smallexample
2429The "remote" target does not support "run".
2430Try "help target" or "continue".
2431@end smallexample
2432
2433@noindent
2434then use @code{continue} to run your program. You may need @code{load}
2435first (@pxref{load}).
c906108c
SS
2436
2437The execution of a program is affected by certain information it
2438receives from its superior. @value{GDBN} provides ways to specify this
2439information, which you must do @emph{before} starting your program. (You
2440can change it after starting your program, but such changes only affect
2441your program the next time you start it.) This information may be
2442divided into four categories:
2443
2444@table @asis
2445@item The @emph{arguments.}
2446Specify the arguments to give your program as the arguments of the
2447@code{run} command. If a shell is available on your target, the shell
2448is used to pass the arguments, so that you may use normal conventions
2449(such as wildcard expansion or variable substitution) in describing
2450the arguments.
2451In Unix systems, you can control which shell is used with the
98882a26
PA
2452@code{SHELL} environment variable. If you do not define @code{SHELL},
2453@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2454use of any shell with the @code{set startup-with-shell} command (see
2455below for details).
c906108c
SS
2456
2457@item The @emph{environment.}
2458Your program normally inherits its environment from @value{GDBN}, but you can
2459use the @value{GDBN} commands @code{set environment} and @code{unset
2460environment} to change parts of the environment that affect
79a6e687 2461your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2462
2463@item The @emph{working directory.}
d092c5a2
SDJ
2464You can set your program's working directory with the command
2465@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2466command, your program will inherit @value{GDBN}'s working directory if
2467native debugging, or the remote server's working directory if remote
2468debugging. @xref{Working Directory, ,Your Program's Working
2469Directory}.
c906108c
SS
2470
2471@item The @emph{standard input and output.}
2472Your program normally uses the same device for standard input and
2473standard output as @value{GDBN} is using. You can redirect input and output
2474in the @code{run} command line, or you can use the @code{tty} command to
2475set a different device for your program.
79a6e687 2476@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2477
2478@cindex pipes
2479@emph{Warning:} While input and output redirection work, you cannot use
2480pipes to pass the output of the program you are debugging to another
2481program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2482wrong program.
2483@end table
c906108c
SS
2484
2485When you issue the @code{run} command, your program begins to execute
79a6e687 2486immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2487of how to arrange for your program to stop. Once your program has
2488stopped, you may call functions in your program, using the @code{print}
2489or @code{call} commands. @xref{Data, ,Examining Data}.
2490
2491If the modification time of your symbol file has changed since the last
2492time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2493table, and reads it again. When it does this, @value{GDBN} tries to retain
2494your current breakpoints.
2495
4e8b0763
JB
2496@table @code
2497@kindex start
2498@item start
2499@cindex run to main procedure
2500The name of the main procedure can vary from language to language.
2501With C or C@t{++}, the main procedure name is always @code{main}, but
2502other languages such as Ada do not require a specific name for their
2503main procedure. The debugger provides a convenient way to start the
2504execution of the program and to stop at the beginning of the main
2505procedure, depending on the language used.
2506
2507The @samp{start} command does the equivalent of setting a temporary
2508breakpoint at the beginning of the main procedure and then invoking
2509the @samp{run} command.
2510
f018e82f
EZ
2511@cindex elaboration phase
2512Some programs contain an @dfn{elaboration} phase where some startup code is
2513executed before the main procedure is called. This depends on the
2514languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2515constructors for static and global objects are executed before
2516@code{main} is called. It is therefore possible that the debugger stops
2517before reaching the main procedure. However, the temporary breakpoint
2518will remain to halt execution.
2519
2520Specify the arguments to give to your program as arguments to the
2521@samp{start} command. These arguments will be given verbatim to the
2522underlying @samp{run} command. Note that the same arguments will be
2523reused if no argument is provided during subsequent calls to
2524@samp{start} or @samp{run}.
2525
2526It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2527these cases, using the @code{start} command would stop the execution
2528of your program too late, as the program would have already completed
2529the elaboration phase. Under these circumstances, either insert
2530breakpoints in your elaboration code before running your program or
2531use the @code{starti} command.
2532
2533@kindex starti
2534@item starti
2535@cindex run to first instruction
2536The @samp{starti} command does the equivalent of setting a temporary
2537breakpoint at the first instruction of a program's execution and then
2538invoking the @samp{run} command. For programs containing an
2539elaboration phase, the @code{starti} command will stop execution at
2540the start of the elaboration phase.
ccd213ac 2541
41ef2965 2542@anchor{set exec-wrapper}
ccd213ac
DJ
2543@kindex set exec-wrapper
2544@item set exec-wrapper @var{wrapper}
2545@itemx show exec-wrapper
2546@itemx unset exec-wrapper
2547When @samp{exec-wrapper} is set, the specified wrapper is used to
2548launch programs for debugging. @value{GDBN} starts your program
2549with a shell command of the form @kbd{exec @var{wrapper}
2550@var{program}}. Quoting is added to @var{program} and its
2551arguments, but not to @var{wrapper}, so you should add quotes if
2552appropriate for your shell. The wrapper runs until it executes
2553your program, and then @value{GDBN} takes control.
2554
2555You can use any program that eventually calls @code{execve} with
2556its arguments as a wrapper. Several standard Unix utilities do
2557this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2558with @code{exec "$@@"} will also work.
2559
2560For example, you can use @code{env} to pass an environment variable to
2561the debugged program, without setting the variable in your shell's
2562environment:
2563
2564@smallexample
2565(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2566(@value{GDBP}) run
2567@end smallexample
2568
2569This command is available when debugging locally on most targets, excluding
2570@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2571
98882a26 2572@kindex set startup-with-shell
aefd8b33 2573@anchor{set startup-with-shell}
98882a26
PA
2574@item set startup-with-shell
2575@itemx set startup-with-shell on
2576@itemx set startup-with-shell off
ca145713 2577@itemx show startup-with-shell
98882a26
PA
2578On Unix systems, by default, if a shell is available on your target,
2579@value{GDBN}) uses it to start your program. Arguments of the
2580@code{run} command are passed to the shell, which does variable
2581substitution, expands wildcard characters and performs redirection of
2582I/O. In some circumstances, it may be useful to disable such use of a
2583shell, for example, when debugging the shell itself or diagnosing
2584startup failures such as:
2585
2586@smallexample
2587(@value{GDBP}) run
2588Starting program: ./a.out
2589During startup program terminated with signal SIGSEGV, Segmentation fault.
2590@end smallexample
2591
2592@noindent
2593which indicates the shell or the wrapper specified with
2594@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2595caused by something odd in your shell's non-interactive mode
2596initialization file---such as @file{.cshrc} for C-shell,
2597$@file{.zshenv} for the Z shell, or the file specified in the
2598@samp{BASH_ENV} environment variable for BASH.
98882a26 2599
6a3cb8e8
PA
2600@anchor{set auto-connect-native-target}
2601@kindex set auto-connect-native-target
2602@item set auto-connect-native-target
2603@itemx set auto-connect-native-target on
2604@itemx set auto-connect-native-target off
2605@itemx show auto-connect-native-target
2606
65c574f6
PA
2607By default, if the current inferior is not connected to any target yet
2608(e.g., with @code{target remote}), the @code{run} command starts your
2609program as a native process under @value{GDBN}, on your local machine.
2610If you're sure you don't want to debug programs on your local machine,
2611you can tell @value{GDBN} to not connect to the native target
2612automatically with the @code{set auto-connect-native-target off}
2613command.
6a3cb8e8 2614
65c574f6 2615If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2616connected to a target already, the @code{run} command automaticaly
2617connects to the native target, if one is available.
2618
65c574f6
PA
2619If @code{off}, and if the current inferior is not connected to a
2620target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2621
2622@smallexample
2623(@value{GDBP}) run
2624Don't know how to run. Try "help target".
2625@end smallexample
2626
65c574f6
PA
2627If the current inferior is already connected to a target, @value{GDBN}
2628always uses it with the @code{run} command.
6a3cb8e8
PA
2629
2630In any case, you can explicitly connect to the native target with the
2631@code{target native} command. For example,
2632
2633@smallexample
2634(@value{GDBP}) set auto-connect-native-target off
2635(@value{GDBP}) run
2636Don't know how to run. Try "help target".
2637(@value{GDBP}) target native
2638(@value{GDBP}) run
2639Starting program: ./a.out
2640[Inferior 1 (process 10421) exited normally]
2641@end smallexample
2642
2643In case you connected explicitly to the @code{native} target,
2644@value{GDBN} remains connected even if all inferiors exit, ready for
2645the next @code{run} command. Use the @code{disconnect} command to
2646disconnect.
2647
2648Examples of other commands that likewise respect the
2649@code{auto-connect-native-target} setting: @code{attach}, @code{info
2650proc}, @code{info os}.
2651
10568435
JK
2652@kindex set disable-randomization
2653@item set disable-randomization
2654@itemx set disable-randomization on
2655This option (enabled by default in @value{GDBN}) will turn off the native
2656randomization of the virtual address space of the started program. This option
2657is useful for multiple debugging sessions to make the execution better
2658reproducible and memory addresses reusable across debugging sessions.
2659
03583c20
UW
2660This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2661On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2662
2663@smallexample
2664(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2665@end smallexample
2666
2667@item set disable-randomization off
2668Leave the behavior of the started executable unchanged. Some bugs rear their
2669ugly heads only when the program is loaded at certain addresses. If your bug
2670disappears when you run the program under @value{GDBN}, that might be because
2671@value{GDBN} by default disables the address randomization on platforms, such
2672as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2673disable-randomization off} to try to reproduce such elusive bugs.
2674
03583c20
UW
2675On targets where it is available, virtual address space randomization
2676protects the programs against certain kinds of security attacks. In these
10568435
JK
2677cases the attacker needs to know the exact location of a concrete executable
2678code. Randomizing its location makes it impossible to inject jumps misusing
2679a code at its expected addresses.
2680
2681Prelinking shared libraries provides a startup performance advantage but it
2682makes addresses in these libraries predictable for privileged processes by
2683having just unprivileged access at the target system. Reading the shared
2684library binary gives enough information for assembling the malicious code
2685misusing it. Still even a prelinked shared library can get loaded at a new
2686random address just requiring the regular relocation process during the
2687startup. Shared libraries not already prelinked are always loaded at
2688a randomly chosen address.
2689
2690Position independent executables (PIE) contain position independent code
2691similar to the shared libraries and therefore such executables get loaded at
2692a randomly chosen address upon startup. PIE executables always load even
2693already prelinked shared libraries at a random address. You can build such
2694executable using @command{gcc -fPIE -pie}.
2695
2696Heap (malloc storage), stack and custom mmap areas are always placed randomly
2697(as long as the randomization is enabled).
2698
2699@item show disable-randomization
2700Show the current setting of the explicit disable of the native randomization of
2701the virtual address space of the started program.
2702
4e8b0763
JB
2703@end table
2704
6d2ebf8b 2705@node Arguments
79a6e687 2706@section Your Program's Arguments
c906108c
SS
2707
2708@cindex arguments (to your program)
2709The arguments to your program can be specified by the arguments of the
5d161b24 2710@code{run} command.
c906108c
SS
2711They are passed to a shell, which expands wildcard characters and
2712performs redirection of I/O, and thence to your program. Your
2713@code{SHELL} environment variable (if it exists) specifies what shell
2714@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2715the default shell (@file{/bin/sh} on Unix).
2716
2717On non-Unix systems, the program is usually invoked directly by
2718@value{GDBN}, which emulates I/O redirection via the appropriate system
2719calls, and the wildcard characters are expanded by the startup code of
2720the program, not by the shell.
c906108c
SS
2721
2722@code{run} with no arguments uses the same arguments used by the previous
2723@code{run}, or those set by the @code{set args} command.
2724
c906108c 2725@table @code
41afff9a 2726@kindex set args
c906108c
SS
2727@item set args
2728Specify the arguments to be used the next time your program is run. If
2729@code{set args} has no arguments, @code{run} executes your program
2730with no arguments. Once you have run your program with arguments,
2731using @code{set args} before the next @code{run} is the only way to run
2732it again without arguments.
2733
2734@kindex show args
2735@item show args
2736Show the arguments to give your program when it is started.
2737@end table
2738
6d2ebf8b 2739@node Environment
79a6e687 2740@section Your Program's Environment
c906108c
SS
2741
2742@cindex environment (of your program)
2743The @dfn{environment} consists of a set of environment variables and
2744their values. Environment variables conventionally record such things as
2745your user name, your home directory, your terminal type, and your search
2746path for programs to run. Usually you set up environment variables with
2747the shell and they are inherited by all the other programs you run. When
2748debugging, it can be useful to try running your program with a modified
2749environment without having to start @value{GDBN} over again.
2750
2751@table @code
2752@kindex path
2753@item path @var{directory}
2754Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2755(the search path for executables) that will be passed to your program.
2756The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2757You may specify several directory names, separated by whitespace or by a
2758system-dependent separator character (@samp{:} on Unix, @samp{;} on
2759MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2760is moved to the front, so it is searched sooner.
c906108c
SS
2761
2762You can use the string @samp{$cwd} to refer to whatever is the current
2763working directory at the time @value{GDBN} searches the path. If you
2764use @samp{.} instead, it refers to the directory where you executed the
2765@code{path} command. @value{GDBN} replaces @samp{.} in the
2766@var{directory} argument (with the current path) before adding
2767@var{directory} to the search path.
2768@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2769@c document that, since repeating it would be a no-op.
2770
2771@kindex show paths
2772@item show paths
2773Display the list of search paths for executables (the @code{PATH}
2774environment variable).
2775
2776@kindex show environment
2777@item show environment @r{[}@var{varname}@r{]}
2778Print the value of environment variable @var{varname} to be given to
2779your program when it starts. If you do not supply @var{varname},
2780print the names and values of all environment variables to be given to
2781your program. You can abbreviate @code{environment} as @code{env}.
2782
2783@kindex set environment
0a2dde4a 2784@anchor{set environment}
53a5351d 2785@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2786Set environment variable @var{varname} to @var{value}. The value
41ef2965 2787changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2788it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2789values of environment variables are just strings, and any
2790interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2791parameter is optional; if it is eliminated, the variable is set to a
2792null value.
2793@c "any string" here does not include leading, trailing
2794@c blanks. Gnu asks: does anyone care?
2795
2796For example, this command:
2797
474c8240 2798@smallexample
c906108c 2799set env USER = foo
474c8240 2800@end smallexample
c906108c
SS
2801
2802@noindent
d4f3574e 2803tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2804@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2805are not actually required.)
2806
41ef2965
PA
2807Note that on Unix systems, @value{GDBN} runs your program via a shell,
2808which also inherits the environment set with @code{set environment}.
2809If necessary, you can avoid that by using the @samp{env} program as a
2810wrapper instead of using @code{set environment}. @xref{set
2811exec-wrapper}, for an example doing just that.
2812
0a2dde4a
SDJ
2813Environment variables that are set by the user are also transmitted to
2814@command{gdbserver} to be used when starting the remote inferior.
2815@pxref{QEnvironmentHexEncoded}.
2816
c906108c 2817@kindex unset environment
0a2dde4a 2818@anchor{unset environment}
c906108c
SS
2819@item unset environment @var{varname}
2820Remove variable @var{varname} from the environment to be passed to your
2821program. This is different from @samp{set env @var{varname} =};
2822@code{unset environment} removes the variable from the environment,
2823rather than assigning it an empty value.
0a2dde4a
SDJ
2824
2825Environment variables that are unset by the user are also unset on
2826@command{gdbserver} when starting the remote inferior.
2827@pxref{QEnvironmentUnset}.
c906108c
SS
2828@end table
2829
d4f3574e 2830@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2831the shell indicated by your @code{SHELL} environment variable if it
2832exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2833names a shell that runs an initialization file when started
2834non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2835for the Z shell, or the file specified in the @samp{BASH_ENV}
2836environment variable for BASH---any variables you set in that file
2837affect your program. You may wish to move setting of environment
2838variables to files that are only run when you sign on, such as
2839@file{.login} or @file{.profile}.
c906108c 2840
6d2ebf8b 2841@node Working Directory
79a6e687 2842@section Your Program's Working Directory
c906108c
SS
2843
2844@cindex working directory (of your program)
d092c5a2
SDJ
2845Each time you start your program with @code{run}, the inferior will be
2846initialized with the current working directory specified by the
2847@kbd{set cwd} command. If no directory has been specified by this
2848command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2849directory as its working directory if native debugging, or it will
2850inherit the remote server's current working directory if remote
2851debugging.
c906108c
SS
2852
2853@table @code
d092c5a2
SDJ
2854@kindex set cwd
2855@cindex change inferior's working directory
2856@anchor{set cwd command}
2857@item set cwd @r{[}@var{directory}@r{]}
2858Set the inferior's working directory to @var{directory}, which will be
2859@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2860argument has been specified, the command clears the setting and resets
2861it to an empty state. This setting has no effect on @value{GDBN}'s
2862working directory, and it only takes effect the next time you start
2863the inferior. The @file{~} in @var{directory} is a short for the
2864@dfn{home directory}, usually pointed to by the @env{HOME} environment
2865variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2866uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2867fallback.
2868
2869You can also change @value{GDBN}'s current working directory by using
2870the @code{cd} command.
dbfa4523 2871@xref{cd command}.
d092c5a2
SDJ
2872
2873@kindex show cwd
2874@cindex show inferior's working directory
2875@item show cwd
2876Show the inferior's working directory. If no directory has been
2877specified by @kbd{set cwd}, then the default inferior's working
2878directory is the same as @value{GDBN}'s working directory.
2879
c906108c 2880@kindex cd
d092c5a2
SDJ
2881@cindex change @value{GDBN}'s working directory
2882@anchor{cd command}
f3c8a52a
JK
2883@item cd @r{[}@var{directory}@r{]}
2884Set the @value{GDBN} working directory to @var{directory}. If not
2885given, @var{directory} uses @file{'~'}.
c906108c 2886
d092c5a2
SDJ
2887The @value{GDBN} working directory serves as a default for the
2888commands that specify files for @value{GDBN} to operate on.
2889@xref{Files, ,Commands to Specify Files}.
dbfa4523 2890@xref{set cwd command}.
d092c5a2 2891
c906108c
SS
2892@kindex pwd
2893@item pwd
2894Print the @value{GDBN} working directory.
2895@end table
2896
60bf7e09
EZ
2897It is generally impossible to find the current working directory of
2898the process being debugged (since a program can change its directory
2d97a5d9 2899during its run). If you work on a system where @value{GDBN} supports
754452f0 2900the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2901use the @code{info proc} command to find out the
60bf7e09
EZ
2902current working directory of the debuggee.
2903
6d2ebf8b 2904@node Input/Output
79a6e687 2905@section Your Program's Input and Output
c906108c
SS
2906
2907@cindex redirection
2908@cindex i/o
2909@cindex terminal
2910By default, the program you run under @value{GDBN} does input and output to
5d161b24 2911the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2912to its own terminal modes to interact with you, but it records the terminal
2913modes your program was using and switches back to them when you continue
2914running your program.
2915
2916@table @code
2917@kindex info terminal
2918@item info terminal
2919Displays information recorded by @value{GDBN} about the terminal modes your
2920program is using.
2921@end table
2922
2923You can redirect your program's input and/or output using shell
2924redirection with the @code{run} command. For example,
2925
474c8240 2926@smallexample
c906108c 2927run > outfile
474c8240 2928@end smallexample
c906108c
SS
2929
2930@noindent
2931starts your program, diverting its output to the file @file{outfile}.
2932
2933@kindex tty
2934@cindex controlling terminal
2935Another way to specify where your program should do input and output is
2936with the @code{tty} command. This command accepts a file name as
2937argument, and causes this file to be the default for future @code{run}
2938commands. It also resets the controlling terminal for the child
2939process, for future @code{run} commands. For example,
2940
474c8240 2941@smallexample
c906108c 2942tty /dev/ttyb
474c8240 2943@end smallexample
c906108c
SS
2944
2945@noindent
2946directs that processes started with subsequent @code{run} commands
2947default to do input and output on the terminal @file{/dev/ttyb} and have
2948that as their controlling terminal.
2949
2950An explicit redirection in @code{run} overrides the @code{tty} command's
2951effect on the input/output device, but not its effect on the controlling
2952terminal.
2953
2954When you use the @code{tty} command or redirect input in the @code{run}
2955command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2956for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2957for @code{set inferior-tty}.
2958
2959@cindex inferior tty
2960@cindex set inferior controlling terminal
2961You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2962display the name of the terminal that will be used for future runs of your
2963program.
2964
2965@table @code
0a1ddfa6 2966@item set inferior-tty [ @var{tty} ]
3cb3b8df 2967@kindex set inferior-tty
0a1ddfa6
SM
2968Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2969restores the default behavior, which is to use the same terminal as
2970@value{GDBN}.
3cb3b8df
BR
2971
2972@item show inferior-tty
2973@kindex show inferior-tty
2974Show the current tty for the program being debugged.
2975@end table
c906108c 2976
6d2ebf8b 2977@node Attach
79a6e687 2978@section Debugging an Already-running Process
c906108c
SS
2979@kindex attach
2980@cindex attach
2981
2982@table @code
2983@item attach @var{process-id}
2984This command attaches to a running process---one that was started
2985outside @value{GDBN}. (@code{info files} shows your active
2986targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2987find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2988or with the @samp{jobs -l} shell command.
2989
2990@code{attach} does not repeat if you press @key{RET} a second time after
2991executing the command.
2992@end table
2993
2994To use @code{attach}, your program must be running in an environment
2995which supports processes; for example, @code{attach} does not work for
2996programs on bare-board targets that lack an operating system. You must
2997also have permission to send the process a signal.
2998
2999When you use @code{attach}, the debugger finds the program running in
3000the process first by looking in the current working directory, then (if
3001the program is not found) by using the source file search path
79a6e687 3002(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
3003the @code{file} command to load the program. @xref{Files, ,Commands to
3004Specify Files}.
3005
e47e48f6 3006@anchor{set exec-file-mismatch}
98c59b52
PA
3007If the debugger can determine that the executable file running in the
3008process it is attaching to does not match the current exec-file loaded
3009by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3010handle the mismatch. @value{GDBN} tries to compare the files by
3011comparing their build IDs (@pxref{build ID}), if available.
e47e48f6
PW
3012
3013@table @code
3014@kindex exec-file-mismatch
3015@cindex set exec-file-mismatch
3016@item set exec-file-mismatch @samp{ask|warn|off}
3017
98c59b52
PA
3018Whether to detect mismatch between the current executable file loaded
3019by @value{GDBN} and the executable file used to start the process. If
3020@samp{ask}, the default, display a warning and ask the user whether to
3021load the process executable file; if @samp{warn}, just display a
3022warning; if @samp{off}, don't attempt to detect a mismatch.
0a278aa7
PW
3023If the user confirms loading the process executable file, then its symbols
3024will be loaded as well.
e47e48f6
PW
3025
3026@cindex show exec-file-mismatch
3027@item show exec-file-mismatch
3028Show the current value of @code{exec-file-mismatch}.
3029
3030@end table
3031
c906108c
SS
3032The first thing @value{GDBN} does after arranging to debug the specified
3033process is to stop it. You can examine and modify an attached process
53a5351d
JM
3034with all the @value{GDBN} commands that are ordinarily available when
3035you start processes with @code{run}. You can insert breakpoints; you
3036can step and continue; you can modify storage. If you would rather the
3037process continue running, you may use the @code{continue} command after
c906108c
SS
3038attaching @value{GDBN} to the process.
3039
3040@table @code
3041@kindex detach
3042@item detach
3043When you have finished debugging the attached process, you can use the
3044@code{detach} command to release it from @value{GDBN} control. Detaching
3045the process continues its execution. After the @code{detach} command,
3046that process and @value{GDBN} become completely independent once more, and you
3047are ready to @code{attach} another process or start one with @code{run}.
3048@code{detach} does not repeat if you press @key{RET} again after
3049executing the command.
3050@end table
3051
159fcc13
JK
3052If you exit @value{GDBN} while you have an attached process, you detach
3053that process. If you use the @code{run} command, you kill that process.
3054By default, @value{GDBN} asks for confirmation if you try to do either of these
3055things; you can control whether or not you need to confirm by using the
3056@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 3057Messages}).
c906108c 3058
6d2ebf8b 3059@node Kill Process
79a6e687 3060@section Killing the Child Process
c906108c
SS
3061
3062@table @code
3063@kindex kill
3064@item kill
3065Kill the child process in which your program is running under @value{GDBN}.
3066@end table
3067
3068This command is useful if you wish to debug a core dump instead of a
3069running process. @value{GDBN} ignores any core dump file while your program
3070is running.
3071
3072On some operating systems, a program cannot be executed outside @value{GDBN}
3073while you have breakpoints set on it inside @value{GDBN}. You can use the
3074@code{kill} command in this situation to permit running your program
3075outside the debugger.
3076
3077The @code{kill} command is also useful if you wish to recompile and
3078relink your program, since on many systems it is impossible to modify an
3079executable file while it is running in a process. In this case, when you
3080next type @code{run}, @value{GDBN} notices that the file has changed, and
3081reads the symbol table again (while trying to preserve your current
3082breakpoint settings).
3083
65c574f6
PA
3084@node Inferiors Connections and Programs
3085@section Debugging Multiple Inferiors Connections and Programs
b77209e0 3086
6c95b8df
PA
3087@value{GDBN} lets you run and debug multiple programs in a single
3088session. In addition, @value{GDBN} on some systems may let you run
3089several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
3090before starting another). On some systems @value{GDBN} may even let
3091you debug several programs simultaneously on different remote systems.
3092In the most general case, you can have multiple threads of execution
3093in each of multiple processes, launched from multiple executables,
3094running on different machines.
b77209e0
PA
3095
3096@cindex inferior
3097@value{GDBN} represents the state of each program execution with an
3098object called an @dfn{inferior}. An inferior typically corresponds to
3099a process, but is more general and applies also to targets that do not
3100have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
3101may be retained after a process exits. Inferiors have unique
3102identifiers that are different from process ids. Usually each
3103inferior will also have its own distinct address space, although some
3104embedded targets may have several inferiors running in different parts
3105of a single address space. Each inferior may in turn have multiple
3106threads running in it.
b77209e0 3107
6c95b8df
PA
3108To find out what inferiors exist at any moment, use @w{@code{info
3109inferiors}}:
b77209e0
PA
3110
3111@table @code
a3c25011 3112@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
3113@item info inferiors
3114Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
3115By default all inferiors are printed, but the argument @var{id}@dots{}
3116-- a space separated list of inferior numbers -- can be used to limit
3117the display to just the requested inferiors.
3a1ff0b6
PA
3118
3119@value{GDBN} displays for each inferior (in this order):
3120
3121@enumerate
3122@item
3123the inferior number assigned by @value{GDBN}
3124
3125@item
3126the target system's inferior identifier
6c95b8df 3127
65c574f6
PA
3128@item
3129the target connection the inferior is bound to, including the unique
3130connection number assigned by @value{GDBN}, and the protocol used by
3131the connection.
3132
6c95b8df
PA
3133@item
3134the name of the executable the inferior is running.
3135
3a1ff0b6
PA
3136@end enumerate
3137
3138@noindent
3139An asterisk @samp{*} preceding the @value{GDBN} inferior number
3140indicates the current inferior.
3141
3142For example,
2277426b 3143@end table
3a1ff0b6
PA
3144@c end table here to get a little more width for example
3145
3146@smallexample
3147(@value{GDBP}) info inferiors
65c574f6
PA
3148 Num Description Connection Executable
3149* 1 process 3401 1 (native) goodbye
3150 2 process 2307 2 (extended-remote host:10000) hello
3151@end smallexample
3152
3153To find out what open target connections exist at any moment, use
3154@w{@code{info connections}}:
3155
3156@table @code
3157@kindex info connections [ @var{id}@dots{} ]
3158@item info connections
3159Print a list of all open target connections currently being managed by
3160@value{GDBN}. By default all connections are printed, but the
3161argument @var{id}@dots{} -- a space separated list of connections
3162numbers -- can be used to limit the display to just the requested
3163connections.
3164
3165@value{GDBN} displays for each connection (in this order):
3166
3167@enumerate
3168@item
3169the connection number assigned by @value{GDBN}.
3170
3171@item
3172the protocol used by the connection.
3173
3174@item
3175a textual description of the protocol used by the connection.
3176
3177@end enumerate
3178
3179@noindent
3180An asterisk @samp{*} preceding the connection number indicates the
3181connection of the current inferior.
3182
3183For example,
3184@end table
3185@c end table here to get a little more width for example
3186
3187@smallexample
3188(@value{GDBP}) info connections
3189 Num What Description
3190* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3191 2 native Native process
3192 3 core Local core dump file
3a1ff0b6 3193@end smallexample
2277426b
PA
3194
3195To switch focus between inferiors, use the @code{inferior} command:
3196
3197@table @code
3a1ff0b6
PA
3198@kindex inferior @var{infno}
3199@item inferior @var{infno}
3200Make inferior number @var{infno} the current inferior. The argument
3201@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3202in the first field of the @samp{info inferiors} display.
2277426b
PA
3203@end table
3204
e3940304
PA
3205@vindex $_inferior@r{, convenience variable}
3206The debugger convenience variable @samp{$_inferior} contains the
3207number of the current inferior. You may find this useful in writing
3208breakpoint conditional expressions, command scripts, and so forth.
3209@xref{Convenience Vars,, Convenience Variables}, for general
3210information on convenience variables.
6c95b8df
PA
3211
3212You can get multiple executables into a debugging session via the
3213@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3214systems @value{GDBN} can add inferiors to the debug session
3215automatically by following calls to @code{fork} and @code{exec}. To
3216remove inferiors from the debugging session use the
af624141 3217@w{@code{remove-inferiors}} command.
6c95b8df
PA
3218
3219@table @code
3220@kindex add-inferior
65c574f6 3221@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3222Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3223executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3224the inferiors begins empty, with no program. You can still assign or
3225change the program assigned to the inferior at any time by using the
3226@code{file} command with the executable name as its argument.
3227
65c574f6
PA
3228By default, the new inferior begins connected to the same target
3229connection as the current inferior. For example, if the current
3230inferior was connected to @code{gdbserver} with @code{target remote},
3231then the new inferior will be connected to the same @code{gdbserver}
3232instance. The @samp{-no-connection} option starts the new inferior
3233with no connection yet. You can then for example use the @code{target
3234remote} command to connect to some other @code{gdbserver} instance,
3235use @code{run} to spawn a local program, etc.
3236
6c95b8df
PA
3237@kindex clone-inferior
3238@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3239Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3240@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3241number of the current inferior. This is a convenient command when you
3242want to run another instance of the inferior you are debugging.
3243
3244@smallexample
3245(@value{GDBP}) info inferiors
65c574f6
PA
3246 Num Description Connection Executable
3247* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3248(@value{GDBP}) clone-inferior
3249Added inferior 2.
32501 inferiors added.
3251(@value{GDBP}) info inferiors
65c574f6
PA
3252 Num Description Connection Executable
3253* 1 process 29964 1 (native) helloworld
3254 2 <null> 1 (native) helloworld
6c95b8df
PA
3255@end smallexample
3256
3257You can now simply switch focus to inferior 2 and run it.
3258
af624141
MS
3259@kindex remove-inferiors
3260@item remove-inferiors @var{infno}@dots{}
3261Removes the inferior or inferiors @var{infno}@dots{}. It is not
3262possible to remove an inferior that is running with this command. For
3263those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3264
3265@end table
3266
3267To quit debugging one of the running inferiors that is not the current
3268inferior, you can either detach from it by using the @w{@code{detach
3269inferior}} command (allowing it to run independently), or kill it
af624141 3270using the @w{@code{kill inferiors}} command:
2277426b
PA
3271
3272@table @code
af624141
MS
3273@kindex detach inferiors @var{infno}@dots{}
3274@item detach inferior @var{infno}@dots{}
3275Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3276inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3277still stays on the list of inferiors shown by @code{info inferiors},
3278but its Description will show @samp{<null>}.
3279
3280@kindex kill inferiors @var{infno}@dots{}
3281@item kill inferiors @var{infno}@dots{}
3282Kill the inferior or inferiors identified by @value{GDBN} inferior
3283number(s) @var{infno}@dots{}. Note that the inferior's entry still
3284stays on the list of inferiors shown by @code{info inferiors}, but its
3285Description will show @samp{<null>}.
2277426b
PA
3286@end table
3287
6c95b8df 3288After the successful completion of a command such as @code{detach},
af624141 3289@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3290a normal process exit, the inferior is still valid and listed with
3291@code{info inferiors}, ready to be restarted.
3292
3293
2277426b
PA
3294To be notified when inferiors are started or exit under @value{GDBN}'s
3295control use @w{@code{set print inferior-events}}:
b77209e0 3296
2277426b 3297@table @code
b77209e0
PA
3298@kindex set print inferior-events
3299@cindex print messages on inferior start and exit
3300@item set print inferior-events
3301@itemx set print inferior-events on
3302@itemx set print inferior-events off
3303The @code{set print inferior-events} command allows you to enable or
3304disable printing of messages when @value{GDBN} notices that new
3305inferiors have started or that inferiors have exited or have been
3306detached. By default, these messages will not be printed.
3307
3308@kindex show print inferior-events
3309@item show print inferior-events
3310Show whether messages will be printed when @value{GDBN} detects that
3311inferiors have started, exited or have been detached.
3312@end table
3313
6c95b8df
PA
3314Many commands will work the same with multiple programs as with a
3315single program: e.g., @code{print myglobal} will simply display the
3316value of @code{myglobal} in the current inferior.
3317
3318
6b92c0d3 3319Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3320get more info about the relationship of inferiors, programs, address
3321spaces in a debug session. You can do that with the @w{@code{maint
3322info program-spaces}} command.
3323
3324@table @code
3325@kindex maint info program-spaces
3326@item maint info program-spaces
3327Print a list of all program spaces currently being managed by
3328@value{GDBN}.
3329
3330@value{GDBN} displays for each program space (in this order):
3331
3332@enumerate
3333@item
3334the program space number assigned by @value{GDBN}
3335
3336@item
3337the name of the executable loaded into the program space, with e.g.,
3338the @code{file} command.
3339
3340@end enumerate
3341
3342@noindent
3343An asterisk @samp{*} preceding the @value{GDBN} program space number
3344indicates the current program space.
3345
3346In addition, below each program space line, @value{GDBN} prints extra
3347information that isn't suitable to display in tabular form. For
3348example, the list of inferiors bound to the program space.
3349
3350@smallexample
3351(@value{GDBP}) maint info program-spaces
3352 Id Executable
b05b1202 3353* 1 hello
6c95b8df
PA
3354 2 goodbye
3355 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3356@end smallexample
3357
3358Here we can see that no inferior is running the program @code{hello},
3359while @code{process 21561} is running the program @code{goodbye}. On
3360some targets, it is possible that multiple inferiors are bound to the
3361same program space. The most common example is that of debugging both
3362the parent and child processes of a @code{vfork} call. For example,
3363
3364@smallexample
3365(@value{GDBP}) maint info program-spaces
3366 Id Executable
3367* 1 vfork-test
3368 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3369@end smallexample
3370
3371Here, both inferior 2 and inferior 1 are running in the same program
3372space as a result of inferior 1 having executed a @code{vfork} call.
3373@end table
3374
6d2ebf8b 3375@node Threads
79a6e687 3376@section Debugging Programs with Multiple Threads
c906108c
SS
3377
3378@cindex threads of execution
3379@cindex multiple threads
3380@cindex switching threads
b1236ac3 3381In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3382may have more than one @dfn{thread} of execution. The precise semantics
3383of threads differ from one operating system to another, but in general
3384the threads of a single program are akin to multiple processes---except
3385that they share one address space (that is, they can all examine and
3386modify the same variables). On the other hand, each thread has its own
3387registers and execution stack, and perhaps private memory.
3388
3389@value{GDBN} provides these facilities for debugging multi-thread
3390programs:
3391
3392@itemize @bullet
3393@item automatic notification of new threads
5d5658a1 3394@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3395@item @samp{info threads}, a command to inquire about existing threads
0a232300 3396@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3397a command to apply a command to a list of threads
3398@item thread-specific breakpoints
93815fbf
VP
3399@item @samp{set print thread-events}, which controls printing of
3400messages on thread start and exit.
17a37d48
PP
3401@item @samp{set libthread-db-search-path @var{path}}, which lets
3402the user specify which @code{libthread_db} to use if the default choice
3403isn't compatible with the program.
c906108c
SS
3404@end itemize
3405
c906108c
SS
3406@cindex focus of debugging
3407@cindex current thread
3408The @value{GDBN} thread debugging facility allows you to observe all
3409threads while your program runs---but whenever @value{GDBN} takes
3410control, one thread in particular is always the focus of debugging.
3411This thread is called the @dfn{current thread}. Debugging commands show
3412program information from the perspective of the current thread.
3413
41afff9a 3414@cindex @code{New} @var{systag} message
c906108c
SS
3415@cindex thread identifier (system)
3416@c FIXME-implementors!! It would be more helpful if the [New...] message
3417@c included GDB's numeric thread handle, so you could just go to that
3418@c thread without first checking `info threads'.
3419Whenever @value{GDBN} detects a new thread in your program, it displays
3420the target system's identification for the thread with a message in the
697aa1b7 3421form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3422whose form varies depending on the particular system. For example, on
8807d78b 3423@sc{gnu}/Linux, you might see
c906108c 3424
474c8240 3425@smallexample
08e796bc 3426[New Thread 0x41e02940 (LWP 25582)]
474c8240 3427@end smallexample
c906108c
SS
3428
3429@noindent
b1236ac3 3430when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3431the @var{systag} is simply something like @samp{process 368}, with no
3432further qualifier.
3433
3434@c FIXME!! (1) Does the [New...] message appear even for the very first
3435@c thread of a program, or does it only appear for the
6ca652b0 3436@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3437@c program?
3438@c (2) *Is* there necessarily a first thread always? Or do some
3439@c multithread systems permit starting a program with multiple
5d161b24 3440@c threads ab initio?
c906108c 3441
5d5658a1
PA
3442@anchor{thread numbers}
3443@cindex thread number, per inferior
c906108c 3444@cindex thread identifier (GDB)
5d5658a1
PA
3445For debugging purposes, @value{GDBN} associates its own thread number
3446---always a single integer---with each thread of an inferior. This
3447number is unique between all threads of an inferior, but not unique
3448between threads of different inferiors.
3449
3450@cindex qualified thread ID
3451You can refer to a given thread in an inferior using the qualified
3452@var{inferior-num}.@var{thread-num} syntax, also known as
3453@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3454number and @var{thread-num} being the thread number of the given
3455inferior. For example, thread @code{2.3} refers to thread number 3 of
3456inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3457then @value{GDBN} infers you're referring to a thread of the current
3458inferior.
3459
3460Until you create a second inferior, @value{GDBN} does not show the
3461@var{inferior-num} part of thread IDs, even though you can always use
3462the full @var{inferior-num}.@var{thread-num} form to refer to threads
3463of inferior 1, the initial inferior.
3464
3465@anchor{thread ID lists}
3466@cindex thread ID lists
3467Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3468argument. A list element can be:
3469
3470@enumerate
3471@item
3472A thread ID as shown in the first field of the @samp{info threads}
3473display, with or without an inferior qualifier. E.g., @samp{2.1} or
3474@samp{1}.
3475
3476@item
3477A range of thread numbers, again with or without an inferior
3478qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3479@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3480
3481@item
3482All threads of an inferior, specified with a star wildcard, with or
3483without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3484@samp{1.*}) or @code{*}. The former refers to all threads of the
3485given inferior, and the latter form without an inferior qualifier
3486refers to all threads of the current inferior.
3487
3488@end enumerate
3489
3490For example, if the current inferior is 1, and inferior 7 has one
3491thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3492includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
34937 to 9 of inferior 6 and all threads of inferior 7. That is, in
3494expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
34957.1}.
3496
5d5658a1
PA
3497
3498@anchor{global thread numbers}
3499@cindex global thread number
3500@cindex global thread identifier (GDB)
3501In addition to a @emph{per-inferior} number, each thread is also
3502assigned a unique @emph{global} number, also known as @dfn{global
3503thread ID}, a single integer. Unlike the thread number component of
3504the thread ID, no two threads have the same global ID, even when
3505you're debugging multiple inferiors.
c906108c 3506
f4f4330e
PA
3507From @value{GDBN}'s perspective, a process always has at least one
3508thread. In other words, @value{GDBN} assigns a thread number to the
3509program's ``main thread'' even if the program is not multi-threaded.
3510
5d5658a1 3511@vindex $_thread@r{, convenience variable}
663f6d42
PA
3512@vindex $_gthread@r{, convenience variable}
3513The debugger convenience variables @samp{$_thread} and
3514@samp{$_gthread} contain, respectively, the per-inferior thread number
3515and the global thread number of the current thread. You may find this
5d5658a1
PA
3516useful in writing breakpoint conditional expressions, command scripts,
3517and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3518general information on convenience variables.
3519
f303dbd6
PA
3520If @value{GDBN} detects the program is multi-threaded, it augments the
3521usual message about stopping at a breakpoint with the ID and name of
3522the thread that hit the breakpoint.
3523
3524@smallexample
3525Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3526@end smallexample
3527
3528Likewise when the program receives a signal:
3529
3530@smallexample
3531Thread 1 "main" received signal SIGINT, Interrupt.
3532@end smallexample
3533
c906108c
SS
3534@table @code
3535@kindex info threads
5d5658a1
PA
3536@item info threads @r{[}@var{thread-id-list}@r{]}
3537
3538Display information about one or more threads. With no arguments
3539displays information about all threads. You can specify the list of
3540threads that you want to display using the thread ID list syntax
3541(@pxref{thread ID lists}).
3542
60f98dde 3543@value{GDBN} displays for each thread (in this order):
c906108c
SS
3544
3545@enumerate
09d4efe1 3546@item
5d5658a1 3547the per-inferior thread number assigned by @value{GDBN}
c906108c 3548
c84f6bbf
PA
3549@item
3550the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3551option was specified
3552
09d4efe1
EZ
3553@item
3554the target system's thread identifier (@var{systag})
c906108c 3555
4694da01
TT
3556@item
3557the thread's name, if one is known. A thread can either be named by
3558the user (see @code{thread name}, below), or, in some cases, by the
3559program itself.
3560
09d4efe1
EZ
3561@item
3562the current stack frame summary for that thread
c906108c
SS
3563@end enumerate
3564
3565@noindent
3566An asterisk @samp{*} to the left of the @value{GDBN} thread number
3567indicates the current thread.
3568
5d161b24 3569For example,
c906108c
SS
3570@end table
3571@c end table here to get a little more width for example
3572
3573@smallexample
3574(@value{GDBP}) info threads
e56d7f1e 3575 Id Target Id Frame
c0ecb95f 3576* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3577 2 process 35 thread 23 0x34e5 in sigpause ()
3578 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3579 at threadtest.c:68
3580@end smallexample
53a5351d 3581
5d5658a1
PA
3582If you're debugging multiple inferiors, @value{GDBN} displays thread
3583IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3584Otherwise, only @var{thread-num} is shown.
3585
3586If you specify the @samp{-gid} option, @value{GDBN} displays a column
3587indicating each thread's global thread ID:
5d5658a1
PA
3588
3589@smallexample
3590(@value{GDBP}) info threads
c84f6bbf
PA
3591 Id GId Target Id Frame
3592 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3593 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3594 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3595* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3596@end smallexample
3597
c45da7e6
EZ
3598On Solaris, you can display more information about user threads with a
3599Solaris-specific command:
3600
3601@table @code
3602@item maint info sol-threads
3603@kindex maint info sol-threads
3604@cindex thread info (Solaris)
3605Display info on Solaris user threads.
3606@end table
3607
c906108c 3608@table @code
5d5658a1
PA
3609@kindex thread @var{thread-id}
3610@item thread @var{thread-id}
3611Make thread ID @var{thread-id} the current thread. The command
3612argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3613the first field of the @samp{info threads} display, with or without an
3614inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3615
3616@value{GDBN} responds by displaying the system identifier of the
3617thread you selected, and its current stack frame summary:
c906108c
SS
3618
3619@smallexample
c906108c 3620(@value{GDBP}) thread 2
13fd8b81
TT
3621[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3622#0 some_function (ignore=0x0) at example.c:8
36238 printf ("hello\n");
c906108c
SS
3624@end smallexample
3625
3626@noindent
3627As with the @samp{[New @dots{}]} message, the form of the text after
3628@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3629threads.
c906108c 3630
3345721a 3631@anchor{thread apply all}
9c16f35a 3632@kindex thread apply
638ac427 3633@cindex apply command to several threads
0a232300 3634@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3635The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3636@var{command} to one or more threads. Specify the threads that you
3637want affected using the thread ID list syntax (@pxref{thread ID
3638lists}), or specify @code{all} to apply to all threads. To apply a
3639command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3640@var{command}}. To apply a command to all threads in ascending order,
3641type @kbd{thread apply all -ascending @var{command}}.
3642
0a232300
PW
3643The @var{flag} arguments control what output to produce and how to handle
3644errors raised when applying @var{command} to a thread. @var{flag}
3645must start with a @code{-} directly followed by one letter in
3646@code{qcs}. If several flags are provided, they must be given
3647individually, such as @code{-c -q}.
3648
3649By default, @value{GDBN} displays some thread information before the
3650output produced by @var{command}, and an error raised during the
3651execution of a @var{command} will abort @code{thread apply}. The
3652following flags can be used to fine-tune this behavior:
3653
3654@table @code
3655@item -c
3656The flag @code{-c}, which stands for @samp{continue}, causes any
3657errors in @var{command} to be displayed, and the execution of
3658@code{thread apply} then continues.
3659@item -s
3660The flag @code{-s}, which stands for @samp{silent}, causes any errors
3661or empty output produced by a @var{command} to be silently ignored.
3662That is, the execution continues, but the thread information and errors
3663are not printed.
3664@item -q
3665The flag @code{-q} (@samp{quiet}) disables printing the thread
3666information.
3667@end table
3668
3669Flags @code{-c} and @code{-s} cannot be used together.
3670
3671@kindex taas
3672@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3673@item taas [@var{option}]@dots{} @var{command}
3674Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3675Applies @var{command} on all threads, ignoring errors and empty output.
3676
3345721a
PA
3677The @code{taas} command accepts the same options as the @code{thread
3678apply all} command. @xref{thread apply all}.
3679
0a232300
PW
3680@kindex tfaas
3681@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3682@item tfaas [@var{option}]@dots{} @var{command}
3683Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3684Applies @var{command} on all frames of all threads, ignoring errors
3685and empty output. Note that the flag @code{-s} is specified twice:
3686The first @code{-s} ensures that @code{thread apply} only shows the thread
3687information of the threads for which @code{frame apply} produces
3688some output. The second @code{-s} is needed to ensure that @code{frame
3689apply} shows the frame information of a frame only if the
3690@var{command} successfully produced some output.
3691
3692It can for example be used to print a local variable or a function
3693argument without knowing the thread or frame where this variable or argument
3694is, using:
3695@smallexample
3696(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3697@end smallexample
3698
3345721a 3699The @code{tfaas} command accepts the same options as the @code{frame
ed788fee 3700apply} command. @xref{Frame Apply,,frame apply}.
93815fbf 3701
4694da01
TT
3702@kindex thread name
3703@cindex name a thread
3704@item thread name [@var{name}]
3705This command assigns a name to the current thread. If no argument is
3706given, any existing user-specified name is removed. The thread name
3707appears in the @samp{info threads} display.
3708
3709On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3710determine the name of the thread as given by the OS. On these
3711systems, a name specified with @samp{thread name} will override the
3712system-give name, and removing the user-specified name will cause
3713@value{GDBN} to once again display the system-specified name.
3714
60f98dde
MS
3715@kindex thread find
3716@cindex search for a thread
3717@item thread find [@var{regexp}]
3718Search for and display thread ids whose name or @var{systag}
3719matches the supplied regular expression.
3720
3721As well as being the complement to the @samp{thread name} command,
3722this command also allows you to identify a thread by its target
3723@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3724is the LWP id.
3725
3726@smallexample
3727(@value{GDBN}) thread find 26688
3728Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3729(@value{GDBN}) info thread 4
3730 Id Target Id Frame
3731 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3732@end smallexample
3733
93815fbf
VP
3734@kindex set print thread-events
3735@cindex print messages on thread start and exit
3736@item set print thread-events
3737@itemx set print thread-events on
3738@itemx set print thread-events off
3739The @code{set print thread-events} command allows you to enable or
3740disable printing of messages when @value{GDBN} notices that new threads have
3741started or that threads have exited. By default, these messages will
3742be printed if detection of these events is supported by the target.
3743Note that these messages cannot be disabled on all targets.
3744
3745@kindex show print thread-events
3746@item show print thread-events
3747Show whether messages will be printed when @value{GDBN} detects that threads
3748have started and exited.
c906108c
SS
3749@end table
3750
79a6e687 3751@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3752more information about how @value{GDBN} behaves when you stop and start
3753programs with multiple threads.
3754
79a6e687 3755@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3756watchpoints in programs with multiple threads.
c906108c 3757
bf88dd68 3758@anchor{set libthread-db-search-path}
17a37d48
PP
3759@table @code
3760@kindex set libthread-db-search-path
3761@cindex search path for @code{libthread_db}
3762@item set libthread-db-search-path @r{[}@var{path}@r{]}
3763If this variable is set, @var{path} is a colon-separated list of
3764directories @value{GDBN} will use to search for @code{libthread_db}.
3765If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3766its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3767Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3768macro.
17a37d48
PP
3769
3770On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3771@code{libthread_db} library to obtain information about threads in the
3772inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3773to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3774specific thread debugging library loading is enabled
3775by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3776
3777A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3778refers to the default system directories that are
bf88dd68
JK
3779normally searched for loading shared libraries. The @samp{$sdir} entry
3780is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3781(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3782
3783A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3784refers to the directory from which @code{libpthread}
3785was loaded in the inferior process.
17a37d48
PP
3786
3787For any @code{libthread_db} library @value{GDBN} finds in above directories,
3788@value{GDBN} attempts to initialize it with the current inferior process.
3789If this initialization fails (which could happen because of a version
3790mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3791will unload @code{libthread_db}, and continue with the next directory.
3792If none of @code{libthread_db} libraries initialize successfully,
3793@value{GDBN} will issue a warning and thread debugging will be disabled.
3794
3795Setting @code{libthread-db-search-path} is currently implemented
3796only on some platforms.
3797
3798@kindex show libthread-db-search-path
3799@item show libthread-db-search-path
3800Display current libthread_db search path.
02d868e8
PP
3801
3802@kindex set debug libthread-db
3803@kindex show debug libthread-db
3804@cindex debugging @code{libthread_db}
3805@item set debug libthread-db
3806@itemx show debug libthread-db
3807Turns on or off display of @code{libthread_db}-related events.
3808Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3809@end table
3810
6c95b8df
PA
3811@node Forks
3812@section Debugging Forks
c906108c
SS
3813
3814@cindex fork, debugging programs which call
3815@cindex multiple processes
3816@cindex processes, multiple
53a5351d
JM
3817On most systems, @value{GDBN} has no special support for debugging
3818programs which create additional processes using the @code{fork}
3819function. When a program forks, @value{GDBN} will continue to debug the
3820parent process and the child process will run unimpeded. If you have
3821set a breakpoint in any code which the child then executes, the child
3822will get a @code{SIGTRAP} signal which (unless it catches the signal)
3823will cause it to terminate.
c906108c
SS
3824
3825However, if you want to debug the child process there is a workaround
3826which isn't too painful. Put a call to @code{sleep} in the code which
3827the child process executes after the fork. It may be useful to sleep
3828only if a certain environment variable is set, or a certain file exists,
3829so that the delay need not occur when you don't want to run @value{GDBN}
3830on the child. While the child is sleeping, use the @code{ps} program to
3831get its process ID. Then tell @value{GDBN} (a new invocation of
3832@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3833the child process (@pxref{Attach}). From that point on you can debug
c906108c 3834the child process just like any other process which you attached to.
c906108c 3835
b1236ac3
PA
3836On some systems, @value{GDBN} provides support for debugging programs
3837that create additional processes using the @code{fork} or @code{vfork}
3838functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3839with kernel version 2.5.46 and later.
c906108c 3840
19d9d4ef
DB
3841The fork debugging commands are supported in native mode and when
3842connected to @code{gdbserver} in either @code{target remote} mode or
3843@code{target extended-remote} mode.
0d71eef5 3844
c906108c
SS
3845By default, when a program forks, @value{GDBN} will continue to debug
3846the parent process and the child process will run unimpeded.
3847
3848If you want to follow the child process instead of the parent process,
3849use the command @w{@code{set follow-fork-mode}}.
3850
3851@table @code
3852@kindex set follow-fork-mode
3853@item set follow-fork-mode @var{mode}
3854Set the debugger response to a program call of @code{fork} or
3855@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3856process. The @var{mode} argument can be:
c906108c
SS
3857
3858@table @code
3859@item parent
3860The original process is debugged after a fork. The child process runs
2df3850c 3861unimpeded. This is the default.
c906108c
SS
3862
3863@item child
3864The new process is debugged after a fork. The parent process runs
3865unimpeded.
3866
c906108c
SS
3867@end table
3868
9c16f35a 3869@kindex show follow-fork-mode
c906108c 3870@item show follow-fork-mode
2df3850c 3871Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3872@end table
3873
5c95884b
MS
3874@cindex debugging multiple processes
3875On Linux, if you want to debug both the parent and child processes, use the
3876command @w{@code{set detach-on-fork}}.
3877
3878@table @code
3879@kindex set detach-on-fork
3880@item set detach-on-fork @var{mode}
3881Tells gdb whether to detach one of the processes after a fork, or
3882retain debugger control over them both.
3883
3884@table @code
3885@item on
3886The child process (or parent process, depending on the value of
3887@code{follow-fork-mode}) will be detached and allowed to run
3888independently. This is the default.
3889
3890@item off
3891Both processes will be held under the control of @value{GDBN}.
3892One process (child or parent, depending on the value of
3893@code{follow-fork-mode}) is debugged as usual, while the other
3894is held suspended.
3895
3896@end table
3897
11310833
NR
3898@kindex show detach-on-fork
3899@item show detach-on-fork
3900Show whether detach-on-fork mode is on/off.
5c95884b
MS
3901@end table
3902
2277426b
PA
3903If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3904will retain control of all forked processes (including nested forks).
3905You can list the forked processes under the control of @value{GDBN} by
3906using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3907to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3908Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3909
3910To quit debugging one of the forked processes, you can either detach
af624141
MS
3911from it by using the @w{@code{detach inferiors}} command (allowing it
3912to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3913command. @xref{Inferiors Connections and Programs, ,Debugging
3914Multiple Inferiors Connections and Programs}.
5c95884b 3915
c906108c
SS
3916If you ask to debug a child process and a @code{vfork} is followed by an
3917@code{exec}, @value{GDBN} executes the new target up to the first
3918breakpoint in the new target. If you have a breakpoint set on
3919@code{main} in your original program, the breakpoint will also be set on
3920the child process's @code{main}.
3921
2277426b
PA
3922On some systems, when a child process is spawned by @code{vfork}, you
3923cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3924
3925If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3926call executes, the new target restarts. To restart the parent
3927process, use the @code{file} command with the parent executable name
3928as its argument. By default, after an @code{exec} call executes,
3929@value{GDBN} discards the symbols of the previous executable image.
3930You can change this behaviour with the @w{@code{set follow-exec-mode}}
3931command.
3932
3933@table @code
3934@kindex set follow-exec-mode
3935@item set follow-exec-mode @var{mode}
3936
3937Set debugger response to a program call of @code{exec}. An
3938@code{exec} call replaces the program image of a process.
3939
3940@code{follow-exec-mode} can be:
3941
3942@table @code
3943@item new
3944@value{GDBN} creates a new inferior and rebinds the process to this
3945new inferior. The program the process was running before the
3946@code{exec} call can be restarted afterwards by restarting the
3947original inferior.
3948
3949For example:
3950
3951@smallexample
3952(@value{GDBP}) info inferiors
3953(gdb) info inferior
3954 Id Description Executable
3955* 1 <null> prog1
3956(@value{GDBP}) run
3957process 12020 is executing new program: prog2
3958Program exited normally.
3959(@value{GDBP}) info inferiors
3960 Id Description Executable
c0ecb95f 3961 1 <null> prog1
b05b1202 3962* 2 <null> prog2
6c95b8df
PA
3963@end smallexample
3964
3965@item same
3966@value{GDBN} keeps the process bound to the same inferior. The new
3967executable image replaces the previous executable loaded in the
3968inferior. Restarting the inferior after the @code{exec} call, with
3969e.g., the @code{run} command, restarts the executable the process was
3970running after the @code{exec} call. This is the default mode.
3971
3972For example:
3973
3974@smallexample
3975(@value{GDBP}) info inferiors
3976 Id Description Executable
3977* 1 <null> prog1
3978(@value{GDBP}) run
3979process 12020 is executing new program: prog2
3980Program exited normally.
3981(@value{GDBP}) info inferiors
3982 Id Description Executable
3983* 1 <null> prog2
3984@end smallexample
3985
3986@end table
3987@end table
c906108c 3988
19d9d4ef
DB
3989@code{follow-exec-mode} is supported in native mode and
3990@code{target extended-remote} mode.
3991
c906108c
SS
3992You can use the @code{catch} command to make @value{GDBN} stop whenever
3993a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3994Catchpoints, ,Setting Catchpoints}.
c906108c 3995
5c95884b 3996@node Checkpoint/Restart
79a6e687 3997@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3998
3999@cindex checkpoint
4000@cindex restart
4001@cindex bookmark
4002@cindex snapshot of a process
4003@cindex rewind program state
4004
4005On certain operating systems@footnote{Currently, only
4006@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4007program's state, called a @dfn{checkpoint}, and come back to it
4008later.
4009
4010Returning to a checkpoint effectively undoes everything that has
4011happened in the program since the @code{checkpoint} was saved. This
4012includes changes in memory, registers, and even (within some limits)
4013system state. Effectively, it is like going back in time to the
4014moment when the checkpoint was saved.
4015
4016Thus, if you're stepping thru a program and you think you're
4017getting close to the point where things go wrong, you can save
4018a checkpoint. Then, if you accidentally go too far and miss
4019the critical statement, instead of having to restart your program
4020from the beginning, you can just go back to the checkpoint and
4021start again from there.
4022
4023This can be especially useful if it takes a lot of time or
4024steps to reach the point where you think the bug occurs.
4025
4026To use the @code{checkpoint}/@code{restart} method of debugging:
4027
4028@table @code
4029@kindex checkpoint
4030@item checkpoint
4031Save a snapshot of the debugged program's current execution state.
4032The @code{checkpoint} command takes no arguments, but each checkpoint
4033is assigned a small integer id, similar to a breakpoint id.
4034
4035@kindex info checkpoints
4036@item info checkpoints
4037List the checkpoints that have been saved in the current debugging
4038session. For each checkpoint, the following information will be
4039listed:
4040
4041@table @code
4042@item Checkpoint ID
4043@item Process ID
4044@item Code Address
4045@item Source line, or label
4046@end table
4047
4048@kindex restart @var{checkpoint-id}
4049@item restart @var{checkpoint-id}
4050Restore the program state that was saved as checkpoint number
4051@var{checkpoint-id}. All program variables, registers, stack frames
4052etc.@: will be returned to the values that they had when the checkpoint
4053was saved. In essence, gdb will ``wind back the clock'' to the point
4054in time when the checkpoint was saved.
4055
4056Note that breakpoints, @value{GDBN} variables, command history etc.
4057are not affected by restoring a checkpoint. In general, a checkpoint
4058only restores things that reside in the program being debugged, not in
4059the debugger.
4060
b8db102d
MS
4061@kindex delete checkpoint @var{checkpoint-id}
4062@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
4063Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4064
4065@end table
4066
4067Returning to a previously saved checkpoint will restore the user state
4068of the program being debugged, plus a significant subset of the system
4069(OS) state, including file pointers. It won't ``un-write'' data from
4070a file, but it will rewind the file pointer to the previous location,
4071so that the previously written data can be overwritten. For files
4072opened in read mode, the pointer will also be restored so that the
4073previously read data can be read again.
4074
4075Of course, characters that have been sent to a printer (or other
4076external device) cannot be ``snatched back'', and characters received
4077from eg.@: a serial device can be removed from internal program buffers,
4078but they cannot be ``pushed back'' into the serial pipeline, ready to
4079be received again. Similarly, the actual contents of files that have
4080been changed cannot be restored (at this time).
4081
4082However, within those constraints, you actually can ``rewind'' your
4083program to a previously saved point in time, and begin debugging it
4084again --- and you can change the course of events so as to debug a
4085different execution path this time.
4086
4087@cindex checkpoints and process id
4088Finally, there is one bit of internal program state that will be
4089different when you return to a checkpoint --- the program's process
4090id. Each checkpoint will have a unique process id (or @var{pid}),
4091and each will be different from the program's original @var{pid}.
4092If your program has saved a local copy of its process id, this could
4093potentially pose a problem.
4094
79a6e687 4095@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
4096
4097On some systems such as @sc{gnu}/Linux, address space randomization
4098is performed on new processes for security reasons. This makes it
4099difficult or impossible to set a breakpoint, or watchpoint, on an
4100absolute address if you have to restart the program, since the
4101absolute location of a symbol will change from one execution to the
4102next.
4103
4104A checkpoint, however, is an @emph{identical} copy of a process.
4105Therefore if you create a checkpoint at (eg.@:) the start of main,
4106and simply return to that checkpoint instead of restarting the
4107process, you can avoid the effects of address randomization and
4108your symbols will all stay in the same place.
4109
6d2ebf8b 4110@node Stopping
c906108c
SS
4111@chapter Stopping and Continuing
4112
4113The principal purposes of using a debugger are so that you can stop your
4114program before it terminates; or so that, if your program runs into
4115trouble, you can investigate and find out why.
4116
7a292a7a
SS
4117Inside @value{GDBN}, your program may stop for any of several reasons,
4118such as a signal, a breakpoint, or reaching a new line after a
4119@value{GDBN} command such as @code{step}. You may then examine and
4120change variables, set new breakpoints or remove old ones, and then
4121continue execution. Usually, the messages shown by @value{GDBN} provide
4122ample explanation of the status of your program---but you can also
4123explicitly request this information at any time.
c906108c
SS
4124
4125@table @code
4126@kindex info program
4127@item info program
4128Display information about the status of your program: whether it is
7a292a7a 4129running or not, what process it is, and why it stopped.
c906108c
SS
4130@end table
4131
4132@menu
4133* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4134* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4135* Skipping Over Functions and Files::
4136 Skipping over functions and files
c906108c 4137* Signals:: Signals
c906108c 4138* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4139@end menu
4140
6d2ebf8b 4141@node Breakpoints
79a6e687 4142@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4143
4144@cindex breakpoints
4145A @dfn{breakpoint} makes your program stop whenever a certain point in
4146the program is reached. For each breakpoint, you can add conditions to
4147control in finer detail whether your program stops. You can set
4148breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4149Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4150should stop by line number, function name or exact address in the
4151program.
4152
09d4efe1 4153On some systems, you can set breakpoints in shared libraries before
b1236ac3 4154the executable is run.
c906108c
SS
4155
4156@cindex watchpoints
fd60e0df 4157@cindex data breakpoints
c906108c
SS
4158@cindex memory tracing
4159@cindex breakpoint on memory address
4160@cindex breakpoint on variable modification
4161A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4162when the value of an expression changes. The expression may be a value
0ced0c34 4163of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4164combined by operators, such as @samp{a + b}. This is sometimes called
4165@dfn{data breakpoints}. You must use a different command to set
79a6e687 4166watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4167from that, you can manage a watchpoint like any other breakpoint: you
4168enable, disable, and delete both breakpoints and watchpoints using the
4169same commands.
c906108c
SS
4170
4171You can arrange to have values from your program displayed automatically
4172whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4173Automatic Display}.
c906108c
SS
4174
4175@cindex catchpoints
4176@cindex breakpoint on events
4177A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4178when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4179exception or the loading of a library. As with watchpoints, you use a
4180different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4181Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4182other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4183@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4184
4185@cindex breakpoint numbers
4186@cindex numbers for breakpoints
4187@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4188catchpoint when you create it; these numbers are successive integers
4189starting with one. In many of the commands for controlling various
4190features of breakpoints you use the breakpoint number to say which
4191breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4192@dfn{disabled}; if disabled, it has no effect on your program until you
4193enable it again.
4194
c5394b80 4195@cindex breakpoint ranges
18da0c51 4196@cindex breakpoint lists
c5394b80 4197@cindex ranges of breakpoints
18da0c51
MG
4198@cindex lists of breakpoints
4199Some @value{GDBN} commands accept a space-separated list of breakpoints
4200on which to operate. A list element can be either a single breakpoint number,
4201like @samp{5}, or a range of such numbers, like @samp{5-7}.
4202When a breakpoint list is given to a command, all breakpoints in that list
4203are operated on.
c5394b80 4204
c906108c
SS
4205@menu
4206* Set Breaks:: Setting breakpoints
4207* Set Watchpoints:: Setting watchpoints
4208* Set Catchpoints:: Setting catchpoints
4209* Delete Breaks:: Deleting breakpoints
4210* Disabling:: Disabling breakpoints
4211* Conditions:: Break conditions
4212* Break Commands:: Breakpoint command lists
e7e0cddf 4213* Dynamic Printf:: Dynamic printf
6149aea9 4214* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4215* Static Probe Points:: Listing static probe points
d4f3574e 4216* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4217* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4218@end menu
4219
6d2ebf8b 4220@node Set Breaks
79a6e687 4221@subsection Setting Breakpoints
c906108c 4222
5d161b24 4223@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4224@c consider in particular declaration with/without initialization.
4225@c
4226@c FIXME 2 is there stuff on this already? break at fun start, already init?
4227
4228@kindex break
41afff9a
EZ
4229@kindex b @r{(@code{break})}
4230@vindex $bpnum@r{, convenience variable}
c906108c
SS
4231@cindex latest breakpoint
4232Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4233@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4234number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4235Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4236convenience variables.
4237
c906108c 4238@table @code
2a25a5ba
EZ
4239@item break @var{location}
4240Set a breakpoint at the given @var{location}, which can specify a
4241function name, a line number, or an address of an instruction.
4242(@xref{Specify Location}, for a list of all the possible ways to
4243specify a @var{location}.) The breakpoint will stop your program just
4244before it executes any of the code in the specified @var{location}.
4245
c906108c 4246When using source languages that permit overloading of symbols, such as
2a25a5ba 4247C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4248@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4249that situation.
c906108c 4250
45ac276d 4251It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4252only if a specific thread (@pxref{Thread-Specific Breakpoints})
4253or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4254
c906108c
SS
4255@item break
4256When called without any arguments, @code{break} sets a breakpoint at
4257the next instruction to be executed in the selected stack frame
4258(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4259innermost, this makes your program stop as soon as control
4260returns to that frame. This is similar to the effect of a
4261@code{finish} command in the frame inside the selected frame---except
4262that @code{finish} does not leave an active breakpoint. If you use
4263@code{break} without an argument in the innermost frame, @value{GDBN} stops
4264the next time it reaches the current location; this may be useful
4265inside loops.
4266
4267@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4268least one instruction has been executed. If it did not do this, you
4269would be unable to proceed past a breakpoint without first disabling the
4270breakpoint. This rule applies whether or not the breakpoint already
4271existed when your program stopped.
4272
4273@item break @dots{} if @var{cond}
4274Set a breakpoint with condition @var{cond}; evaluate the expression
4275@var{cond} each time the breakpoint is reached, and stop only if the
4276value is nonzero---that is, if @var{cond} evaluates as true.
4277@samp{@dots{}} stands for one of the possible arguments described
4278above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4279,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
4280
4281@kindex tbreak
4282@item tbreak @var{args}
697aa1b7 4283Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4284same as for the @code{break} command, and the breakpoint is set in the same
4285way, but the breakpoint is automatically deleted after the first time your
79a6e687 4286program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4287
c906108c 4288@kindex hbreak
ba04e063 4289@cindex hardware breakpoints
c906108c 4290@item hbreak @var{args}
697aa1b7 4291Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4292@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4293breakpoint requires hardware support and some target hardware may not
4294have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4295debugging, so you can set a breakpoint at an instruction without
4296changing the instruction. This can be used with the new trap-generation
09d4efe1 4297provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4298will generate traps when a program accesses some data or instruction
4299address that is assigned to the debug registers. However the hardware
4300breakpoint registers can take a limited number of breakpoints. For
4301example, on the DSU, only two data breakpoints can be set at a time, and
4302@value{GDBN} will reject this command if more than two are used. Delete
4303or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4304(@pxref{Disabling, ,Disabling Breakpoints}).
4305@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4306For remote targets, you can restrict the number of hardware
4307breakpoints @value{GDBN} will use, see @ref{set remote
4308hardware-breakpoint-limit}.
501eef12 4309
c906108c
SS
4310@kindex thbreak
4311@item thbreak @var{args}
697aa1b7 4312Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4313are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4314the same way. However, like the @code{tbreak} command,
c906108c
SS
4315the breakpoint is automatically deleted after the
4316first time your program stops there. Also, like the @code{hbreak}
5d161b24 4317command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4318may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4319See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4320
4321@kindex rbreak
4322@cindex regular expression
8bd10a10 4323@cindex breakpoints at functions matching a regexp
c45da7e6 4324@cindex set breakpoints in many functions
c906108c 4325@item rbreak @var{regex}
c906108c 4326Set breakpoints on all functions matching the regular expression
11cf8741
JM
4327@var{regex}. This command sets an unconditional breakpoint on all
4328matches, printing a list of all breakpoints it set. Once these
4329breakpoints are set, they are treated just like the breakpoints set with
4330the @code{break} command. You can delete them, disable them, or make
4331them conditional the same way as any other breakpoint.
4332
20813a0b
PW
4333In programs using different languages, @value{GDBN} chooses the syntax
4334to print the list of all breakpoints it sets according to the
4335@samp{set language} value: using @samp{set language auto}
4336(see @ref{Automatically, ,Set Language Automatically}) means to use the
4337language of the breakpoint's function, other values mean to use
4338the manually specified language (see @ref{Manually, ,Set Language Manually}).
4339
11cf8741
JM
4340The syntax of the regular expression is the standard one used with tools
4341like @file{grep}. Note that this is different from the syntax used by
4342shells, so for instance @code{foo*} matches all functions that include
4343an @code{fo} followed by zero or more @code{o}s. There is an implicit
4344@code{.*} leading and trailing the regular expression you supply, so to
4345match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4346
f7dc1244 4347@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4348When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4349breakpoints on overloaded functions that are not members of any special
4350classes.
c906108c 4351
f7dc1244
EZ
4352@cindex set breakpoints on all functions
4353The @code{rbreak} command can be used to set breakpoints in
4354@strong{all} the functions in a program, like this:
4355
4356@smallexample
4357(@value{GDBP}) rbreak .
4358@end smallexample
4359
8bd10a10
CM
4360@item rbreak @var{file}:@var{regex}
4361If @code{rbreak} is called with a filename qualification, it limits
4362the search for functions matching the given regular expression to the
4363specified @var{file}. This can be used, for example, to set breakpoints on
4364every function in a given file:
4365
4366@smallexample
4367(@value{GDBP}) rbreak file.c:.
4368@end smallexample
4369
4370The colon separating the filename qualifier from the regex may
4371optionally be surrounded by spaces.
4372
c906108c
SS
4373@kindex info breakpoints
4374@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4375@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4376@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4377Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4378not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4379about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4380For each breakpoint, following columns are printed:
c906108c
SS
4381
4382@table @emph
4383@item Breakpoint Numbers
4384@item Type
4385Breakpoint, watchpoint, or catchpoint.
4386@item Disposition
4387Whether the breakpoint is marked to be disabled or deleted when hit.
4388@item Enabled or Disabled
4389Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4390that are not enabled.
c906108c 4391@item Address
fe6fbf8b 4392Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4393pending breakpoint whose address is not yet known, this field will
4394contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4395library that has the symbol or line referred by breakpoint is loaded.
4396See below for details. A breakpoint with several locations will
3b784c4f 4397have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4398@item What
4399Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4400line number. For a pending breakpoint, the original string passed to
4401the breakpoint command will be listed as it cannot be resolved until
4402the appropriate shared library is loaded in the future.
c906108c
SS
4403@end table
4404
4405@noindent
83364271
LM
4406If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4407``target''. If mode is ``host'', breakpoint condition evaluation is done by
4408@value{GDBN} on the host's side. If it is ``target'', then the condition
4409is evaluated by the target. The @code{info break} command shows
4410the condition on the line following the affected breakpoint, together with
4411its condition evaluation mode in between parentheses.
4412
4413Breakpoint commands, if any, are listed after that. A pending breakpoint is
4414allowed to have a condition specified for it. The condition is not parsed for
4415validity until a shared library is loaded that allows the pending
4416breakpoint to resolve to a valid location.
c906108c
SS
4417
4418@noindent
4419@code{info break} with a breakpoint
4420number @var{n} as argument lists only that breakpoint. The
4421convenience variable @code{$_} and the default examining-address for
4422the @code{x} command are set to the address of the last breakpoint
79a6e687 4423listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4424
4425@noindent
4426@code{info break} displays a count of the number of times the breakpoint
4427has been hit. This is especially useful in conjunction with the
4428@code{ignore} command. You can ignore a large number of breakpoint
4429hits, look at the breakpoint info to see how many times the breakpoint
4430was hit, and then run again, ignoring one less than that number. This
4431will get you quickly to the last hit of that breakpoint.
816338b5
SS
4432
4433@noindent
4434For a breakpoints with an enable count (xref) greater than 1,
4435@code{info break} also displays that count.
4436
c906108c
SS
4437@end table
4438
4439@value{GDBN} allows you to set any number of breakpoints at the same place in
4440your program. There is nothing silly or meaningless about this. When
4441the breakpoints are conditional, this is even useful
79a6e687 4442(@pxref{Conditions, ,Break Conditions}).
c906108c 4443
2e9132cc
EZ
4444@cindex multiple locations, breakpoints
4445@cindex breakpoints, multiple locations
fcda367b 4446It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4447in your program. Examples of this situation are:
4448
4449@itemize @bullet
f8eba3c6
TT
4450@item
4451Multiple functions in the program may have the same name.
4452
fe6fbf8b
VP
4453@item
4454For a C@t{++} constructor, the @value{NGCC} compiler generates several
4455instances of the function body, used in different cases.
4456
4457@item
4458For a C@t{++} template function, a given line in the function can
4459correspond to any number of instantiations.
4460
4461@item
4462For an inlined function, a given source line can correspond to
4463several places where that function is inlined.
fe6fbf8b
VP
4464@end itemize
4465
4466In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4467the relevant locations.
fe6fbf8b 4468
3b784c4f
EZ
4469A breakpoint with multiple locations is displayed in the breakpoint
4470table using several rows---one header row, followed by one row for
4471each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4472address column. The rows for individual locations contain the actual
4473addresses for locations, and show the functions to which those
4474locations belong. The number column for a location is of the form
fe6fbf8b
VP
4475@var{breakpoint-number}.@var{location-number}.
4476
4477For example:
3b784c4f 4478
fe6fbf8b
VP
4479@smallexample
4480Num Type Disp Enb Address What
44811 breakpoint keep y <MULTIPLE>
4482 stop only if i==1
4483 breakpoint already hit 1 time
44841.1 y 0x080486a2 in void foo<int>() at t.cc:8
44851.2 y 0x080486ca in void foo<double>() at t.cc:8
4486@end smallexample
4487
d0fe4701
XR
4488You cannot delete the individual locations from a breakpoint. However,
4489each location can be individually enabled or disabled by passing
fe6fbf8b 4490@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4491@code{enable} and @code{disable} commands. It's also possible to
4492@code{enable} and @code{disable} a range of @var{location-number}
4493locations using a @var{breakpoint-number} and two @var{location-number}s,
4494in increasing order, separated by a hyphen, like
4495@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4496in which case @value{GDBN} acts on all the locations in the range (inclusive).
4497Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4498all of the locations that belong to that breakpoint.
fe6fbf8b 4499
2650777c 4500@cindex pending breakpoints
fe6fbf8b 4501It's quite common to have a breakpoint inside a shared library.
3b784c4f 4502Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4503and possibly repeatedly, as the program is executed. To support
4504this use case, @value{GDBN} updates breakpoint locations whenever
4505any shared library is loaded or unloaded. Typically, you would
fcda367b 4506set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4507debugging session, when the library is not loaded, and when the
4508symbols from the library are not available. When you try to set
4509breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4510a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4511is not yet resolved.
4512
4513After the program is run, whenever a new shared library is loaded,
4514@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4515shared library contains the symbol or line referred to by some
4516pending breakpoint, that breakpoint is resolved and becomes an
4517ordinary breakpoint. When a library is unloaded, all breakpoints
4518that refer to its symbols or source lines become pending again.
4519
4520This logic works for breakpoints with multiple locations, too. For
4521example, if you have a breakpoint in a C@t{++} template function, and
4522a newly loaded shared library has an instantiation of that template,
4523a new location is added to the list of locations for the breakpoint.
4524
4525Except for having unresolved address, pending breakpoints do not
4526differ from regular breakpoints. You can set conditions or commands,
4527enable and disable them and perform other breakpoint operations.
4528
4529@value{GDBN} provides some additional commands for controlling what
4530happens when the @samp{break} command cannot resolve breakpoint
4531address specification to an address:
dd79a6cf
JJ
4532
4533@kindex set breakpoint pending
4534@kindex show breakpoint pending
4535@table @code
4536@item set breakpoint pending auto
4537This is the default behavior. When @value{GDBN} cannot find the breakpoint
4538location, it queries you whether a pending breakpoint should be created.
4539
4540@item set breakpoint pending on
4541This indicates that an unrecognized breakpoint location should automatically
4542result in a pending breakpoint being created.
4543
4544@item set breakpoint pending off
4545This indicates that pending breakpoints are not to be created. Any
4546unrecognized breakpoint location results in an error. This setting does
4547not affect any pending breakpoints previously created.
4548
4549@item show breakpoint pending
4550Show the current behavior setting for creating pending breakpoints.
4551@end table
2650777c 4552
fe6fbf8b
VP
4553The settings above only affect the @code{break} command and its
4554variants. Once breakpoint is set, it will be automatically updated
4555as shared libraries are loaded and unloaded.
2650777c 4556
765dc015
VP
4557@cindex automatic hardware breakpoints
4558For some targets, @value{GDBN} can automatically decide if hardware or
4559software breakpoints should be used, depending on whether the
4560breakpoint address is read-only or read-write. This applies to
4561breakpoints set with the @code{break} command as well as to internal
4562breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4563breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4564breakpoints.
4565
18da0c51 4566You can control this automatic behaviour with the following commands:
765dc015
VP
4567
4568@kindex set breakpoint auto-hw
4569@kindex show breakpoint auto-hw
4570@table @code
4571@item set breakpoint auto-hw on
4572This is the default behavior. When @value{GDBN} sets a breakpoint, it
4573will try to use the target memory map to decide if software or hardware
4574breakpoint must be used.
4575
4576@item set breakpoint auto-hw off
4577This indicates @value{GDBN} should not automatically select breakpoint
4578type. If the target provides a memory map, @value{GDBN} will warn when
4579trying to set software breakpoint at a read-only address.
4580@end table
4581
74960c60
VP
4582@value{GDBN} normally implements breakpoints by replacing the program code
4583at the breakpoint address with a special instruction, which, when
4584executed, given control to the debugger. By default, the program
4585code is so modified only when the program is resumed. As soon as
4586the program stops, @value{GDBN} restores the original instructions. This
4587behaviour guards against leaving breakpoints inserted in the
4588target should gdb abrubptly disconnect. However, with slow remote
4589targets, inserting and removing breakpoint can reduce the performance.
4590This behavior can be controlled with the following commands::
4591
4592@kindex set breakpoint always-inserted
4593@kindex show breakpoint always-inserted
4594@table @code
4595@item set breakpoint always-inserted off
33e5cbd6
PA
4596All breakpoints, including newly added by the user, are inserted in
4597the target only when the target is resumed. All breakpoints are
a25a5a45 4598removed from the target when it stops. This is the default mode.
74960c60
VP
4599
4600@item set breakpoint always-inserted on
4601Causes all breakpoints to be inserted in the target at all times. If
4602the user adds a new breakpoint, or changes an existing breakpoint, the
4603breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4604removed from the target only when breakpoint itself is deleted.
342cc091 4605@end table
765dc015 4606
83364271
LM
4607@value{GDBN} handles conditional breakpoints by evaluating these conditions
4608when a breakpoint breaks. If the condition is true, then the process being
4609debugged stops, otherwise the process is resumed.
4610
4611If the target supports evaluating conditions on its end, @value{GDBN} may
4612download the breakpoint, together with its conditions, to it.
4613
4614This feature can be controlled via the following commands:
4615
4616@kindex set breakpoint condition-evaluation
4617@kindex show breakpoint condition-evaluation
4618@table @code
4619@item set breakpoint condition-evaluation host
4620This option commands @value{GDBN} to evaluate the breakpoint
4621conditions on the host's side. Unconditional breakpoints are sent to
4622the target which in turn receives the triggers and reports them back to GDB
4623for condition evaluation. This is the standard evaluation mode.
4624
4625@item set breakpoint condition-evaluation target
4626This option commands @value{GDBN} to download breakpoint conditions
4627to the target at the moment of their insertion. The target
4628is responsible for evaluating the conditional expression and reporting
4629breakpoint stop events back to @value{GDBN} whenever the condition
4630is true. Due to limitations of target-side evaluation, some conditions
4631cannot be evaluated there, e.g., conditions that depend on local data
4632that is only known to the host. Examples include
4633conditional expressions involving convenience variables, complex types
4634that cannot be handled by the agent expression parser and expressions
4635that are too long to be sent over to the target, specially when the
4636target is a remote system. In these cases, the conditions will be
4637evaluated by @value{GDBN}.
4638
4639@item set breakpoint condition-evaluation auto
4640This is the default mode. If the target supports evaluating breakpoint
4641conditions on its end, @value{GDBN} will download breakpoint conditions to
4642the target (limitations mentioned previously apply). If the target does
4643not support breakpoint condition evaluation, then @value{GDBN} will fallback
4644to evaluating all these conditions on the host's side.
4645@end table
4646
4647
c906108c
SS
4648@cindex negative breakpoint numbers
4649@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4650@value{GDBN} itself sometimes sets breakpoints in your program for
4651special purposes, such as proper handling of @code{longjmp} (in C
4652programs). These internal breakpoints are assigned negative numbers,
4653starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4654You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4655@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4656
4657
6d2ebf8b 4658@node Set Watchpoints
79a6e687 4659@subsection Setting Watchpoints
c906108c
SS
4660
4661@cindex setting watchpoints
c906108c
SS
4662You can use a watchpoint to stop execution whenever the value of an
4663expression changes, without having to predict a particular place where
fd60e0df
EZ
4664this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4665The expression may be as simple as the value of a single variable, or
4666as complex as many variables combined by operators. Examples include:
4667
4668@itemize @bullet
4669@item
4670A reference to the value of a single variable.
4671
4672@item
4673An address cast to an appropriate data type. For example,
4674@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4675address (assuming an @code{int} occupies 4 bytes).
4676
4677@item
4678An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4679expression can use any operators valid in the program's native
4680language (@pxref{Languages}).
4681@end itemize
c906108c 4682
fa4727a6
DJ
4683You can set a watchpoint on an expression even if the expression can
4684not be evaluated yet. For instance, you can set a watchpoint on
4685@samp{*global_ptr} before @samp{global_ptr} is initialized.
4686@value{GDBN} will stop when your program sets @samp{global_ptr} and
4687the expression produces a valid value. If the expression becomes
4688valid in some other way than changing a variable (e.g.@: if the memory
4689pointed to by @samp{*global_ptr} becomes readable as the result of a
4690@code{malloc} call), @value{GDBN} may not stop until the next time
4691the expression changes.
4692
82f2d802
EZ
4693@cindex software watchpoints
4694@cindex hardware watchpoints
c906108c 4695Depending on your system, watchpoints may be implemented in software or
2df3850c 4696hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4697program and testing the variable's value each time, which is hundreds of
4698times slower than normal execution. (But this may still be worth it, to
4699catch errors where you have no clue what part of your program is the
4700culprit.)
4701
b1236ac3
PA
4702On some systems, such as most PowerPC or x86-based targets,
4703@value{GDBN} includes support for hardware watchpoints, which do not
4704slow down the running of your program.
c906108c
SS
4705
4706@table @code
4707@kindex watch
5d5658a1 4708@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4709Set a watchpoint for an expression. @value{GDBN} will break when the
4710expression @var{expr} is written into by the program and its value
4711changes. The simplest (and the most popular) use of this command is
4712to watch the value of a single variable:
4713
4714@smallexample
4715(@value{GDBP}) watch foo
4716@end smallexample
c906108c 4717
5d5658a1 4718If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4719argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4720@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4721change the value of @var{expr}, @value{GDBN} will not break. Note
4722that watchpoints restricted to a single thread in this way only work
4723with Hardware Watchpoints.
4724
06a64a0b
TT
4725Ordinarily a watchpoint respects the scope of variables in @var{expr}
4726(see below). The @code{-location} argument tells @value{GDBN} to
4727instead watch the memory referred to by @var{expr}. In this case,
4728@value{GDBN} will evaluate @var{expr}, take the address of the result,
4729and watch the memory at that address. The type of the result is used
4730to determine the size of the watched memory. If the expression's
4731result does not have an address, then @value{GDBN} will print an
4732error.
4733
9c06b0b4
TJB
4734The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4735of masked watchpoints, if the current architecture supports this
4736feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4737Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4738to an address to watch. The mask specifies that some bits of an address
4739(the bits which are reset in the mask) should be ignored when matching
4740the address accessed by the inferior against the watchpoint address.
4741Thus, a masked watchpoint watches many addresses simultaneously---those
4742addresses whose unmasked bits are identical to the unmasked bits in the
4743watchpoint address. The @code{mask} argument implies @code{-location}.
4744Examples:
4745
4746@smallexample
4747(@value{GDBP}) watch foo mask 0xffff00ff
4748(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4749@end smallexample
4750
c906108c 4751@kindex rwatch
5d5658a1 4752@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4753Set a watchpoint that will break when the value of @var{expr} is read
4754by the program.
c906108c
SS
4755
4756@kindex awatch
5d5658a1 4757@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4758Set a watchpoint that will break when @var{expr} is either read from
4759or written into by the program.
c906108c 4760
18da0c51
MG
4761@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4762@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4763This command prints a list of watchpoints, using the same format as
4764@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4765@end table
4766
65d79d4b
SDJ
4767If you watch for a change in a numerically entered address you need to
4768dereference it, as the address itself is just a constant number which will
4769never change. @value{GDBN} refuses to create a watchpoint that watches
4770a never-changing value:
4771
4772@smallexample
4773(@value{GDBP}) watch 0x600850
4774Cannot watch constant value 0x600850.
4775(@value{GDBP}) watch *(int *) 0x600850
4776Watchpoint 1: *(int *) 6293584
4777@end smallexample
4778
c906108c
SS
4779@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4780watchpoints execute very quickly, and the debugger reports a change in
4781value at the exact instruction where the change occurs. If @value{GDBN}
4782cannot set a hardware watchpoint, it sets a software watchpoint, which
4783executes more slowly and reports the change in value at the next
82f2d802
EZ
4784@emph{statement}, not the instruction, after the change occurs.
4785
82f2d802
EZ
4786@cindex use only software watchpoints
4787You can force @value{GDBN} to use only software watchpoints with the
4788@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4789zero, @value{GDBN} will never try to use hardware watchpoints, even if
4790the underlying system supports them. (Note that hardware-assisted
4791watchpoints that were set @emph{before} setting
4792@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4793mechanism of watching expression values.)
c906108c 4794
9c16f35a
EZ
4795@table @code
4796@item set can-use-hw-watchpoints
4797@kindex set can-use-hw-watchpoints
4798Set whether or not to use hardware watchpoints.
4799
4800@item show can-use-hw-watchpoints
4801@kindex show can-use-hw-watchpoints
4802Show the current mode of using hardware watchpoints.
4803@end table
4804
4805For remote targets, you can restrict the number of hardware
4806watchpoints @value{GDBN} will use, see @ref{set remote
4807hardware-breakpoint-limit}.
4808
c906108c
SS
4809When you issue the @code{watch} command, @value{GDBN} reports
4810
474c8240 4811@smallexample
c906108c 4812Hardware watchpoint @var{num}: @var{expr}
474c8240 4813@end smallexample
c906108c
SS
4814
4815@noindent
4816if it was able to set a hardware watchpoint.
4817
7be570e7
JM
4818Currently, the @code{awatch} and @code{rwatch} commands can only set
4819hardware watchpoints, because accesses to data that don't change the
4820value of the watched expression cannot be detected without examining
4821every instruction as it is being executed, and @value{GDBN} does not do
4822that currently. If @value{GDBN} finds that it is unable to set a
4823hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4824will print a message like this:
4825
4826@smallexample
4827Expression cannot be implemented with read/access watchpoint.
4828@end smallexample
4829
4830Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4831data type of the watched expression is wider than what a hardware
4832watchpoint on the target machine can handle. For example, some systems
4833can only watch regions that are up to 4 bytes wide; on such systems you
4834cannot set hardware watchpoints for an expression that yields a
4835double-precision floating-point number (which is typically 8 bytes
4836wide). As a work-around, it might be possible to break the large region
4837into a series of smaller ones and watch them with separate watchpoints.
4838
4839If you set too many hardware watchpoints, @value{GDBN} might be unable
4840to insert all of them when you resume the execution of your program.
4841Since the precise number of active watchpoints is unknown until such
4842time as the program is about to be resumed, @value{GDBN} might not be
4843able to warn you about this when you set the watchpoints, and the
4844warning will be printed only when the program is resumed:
4845
4846@smallexample
4847Hardware watchpoint @var{num}: Could not insert watchpoint
4848@end smallexample
4849
4850@noindent
4851If this happens, delete or disable some of the watchpoints.
4852
fd60e0df
EZ
4853Watching complex expressions that reference many variables can also
4854exhaust the resources available for hardware-assisted watchpoints.
4855That's because @value{GDBN} needs to watch every variable in the
4856expression with separately allocated resources.
4857
c906108c 4858If you call a function interactively using @code{print} or @code{call},
2df3850c 4859any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4860kind of breakpoint or the call completes.
4861
7be570e7
JM
4862@value{GDBN} automatically deletes watchpoints that watch local
4863(automatic) variables, or expressions that involve such variables, when
4864they go out of scope, that is, when the execution leaves the block in
4865which these variables were defined. In particular, when the program
4866being debugged terminates, @emph{all} local variables go out of scope,
4867and so only watchpoints that watch global variables remain set. If you
4868rerun the program, you will need to set all such watchpoints again. One
4869way of doing that would be to set a code breakpoint at the entry to the
4870@code{main} function and when it breaks, set all the watchpoints.
4871
c906108c
SS
4872@cindex watchpoints and threads
4873@cindex threads and watchpoints
d983da9c
DJ
4874In multi-threaded programs, watchpoints will detect changes to the
4875watched expression from every thread.
4876
4877@quotation
4878@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4879have only limited usefulness. If @value{GDBN} creates a software
4880watchpoint, it can only watch the value of an expression @emph{in a
4881single thread}. If you are confident that the expression can only
4882change due to the current thread's activity (and if you are also
4883confident that no other thread can become current), then you can use
4884software watchpoints as usual. However, @value{GDBN} may not notice
4885when a non-current thread's activity changes the expression. (Hardware
4886watchpoints, in contrast, watch an expression in all threads.)
c906108c 4887@end quotation
c906108c 4888
501eef12
AC
4889@xref{set remote hardware-watchpoint-limit}.
4890
6d2ebf8b 4891@node Set Catchpoints
79a6e687 4892@subsection Setting Catchpoints
d4f3574e 4893@cindex catchpoints, setting
c906108c
SS
4894@cindex exception handlers
4895@cindex event handling
4896
4897You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4898kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4899shared library. Use the @code{catch} command to set a catchpoint.
4900
4901@table @code
4902@kindex catch
4903@item catch @var{event}
697aa1b7 4904Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4905
c906108c 4906@table @code
cc16e6c9
TT
4907@item throw @r{[}@var{regexp}@r{]}
4908@itemx rethrow @r{[}@var{regexp}@r{]}
4909@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4910@kindex catch throw
4911@kindex catch rethrow
4912@kindex catch catch
4644b6e3 4913@cindex stop on C@t{++} exceptions
591f19e8
TT
4914The throwing, re-throwing, or catching of a C@t{++} exception.
4915
cc16e6c9
TT
4916If @var{regexp} is given, then only exceptions whose type matches the
4917regular expression will be caught.
4918
72f1fe8a
TT
4919@vindex $_exception@r{, convenience variable}
4920The convenience variable @code{$_exception} is available at an
4921exception-related catchpoint, on some systems. This holds the
4922exception being thrown.
4923
591f19e8
TT
4924There are currently some limitations to C@t{++} exception handling in
4925@value{GDBN}:
c906108c 4926
591f19e8
TT
4927@itemize @bullet
4928@item
4929The support for these commands is system-dependent. Currently, only
4930systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4931supported.
4932
72f1fe8a 4933@item
cc16e6c9
TT
4934The regular expression feature and the @code{$_exception} convenience
4935variable rely on the presence of some SDT probes in @code{libstdc++}.
4936If these probes are not present, then these features cannot be used.
dee368d3
TT
4937These probes were first available in the GCC 4.8 release, but whether
4938or not they are available in your GCC also depends on how it was
4939built.
72f1fe8a
TT
4940
4941@item
4942The @code{$_exception} convenience variable is only valid at the
4943instruction at which an exception-related catchpoint is set.
4944
591f19e8
TT
4945@item
4946When an exception-related catchpoint is hit, @value{GDBN} stops at a
4947location in the system library which implements runtime exception
4948support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4949(@pxref{Selection}) to get to your code.
4950
4951@item
4952If you call a function interactively, @value{GDBN} normally returns
4953control to you when the function has finished executing. If the call
4954raises an exception, however, the call may bypass the mechanism that
4955returns control to you and cause your program either to abort or to
4956simply continue running until it hits a breakpoint, catches a signal
4957that @value{GDBN} is listening for, or exits. This is the case even if
4958you set a catchpoint for the exception; catchpoints on exceptions are
4959disabled within interactive calls. @xref{Calling}, for information on
4960controlling this with @code{set unwind-on-terminating-exception}.
4961
4962@item
4963You cannot raise an exception interactively.
4964
4965@item
4966You cannot install an exception handler interactively.
4967@end itemize
c906108c 4968
b8e07335 4969@item exception @r{[}@var{name}@r{]}
1a4f73eb 4970@kindex catch exception
8936fcda
JB
4971@cindex Ada exception catching
4972@cindex catch Ada exceptions
4973An Ada exception being raised. If an exception name is specified
4974at the end of the command (eg @code{catch exception Program_Error}),
4975the debugger will stop only when this specific exception is raised.
4976Otherwise, the debugger stops execution when any Ada exception is raised.
4977
87f67dba
JB
4978When inserting an exception catchpoint on a user-defined exception whose
4979name is identical to one of the exceptions defined by the language, the
4980fully qualified name must be used as the exception name. Otherwise,
4981@value{GDBN} will assume that it should stop on the pre-defined exception
4982rather than the user-defined one. For instance, assuming an exception
4983called @code{Constraint_Error} is defined in package @code{Pck}, then
4984the command to use to catch such exceptions is @kbd{catch exception
4985Pck.Constraint_Error}.
4986
37f6a7f4
TT
4987@vindex $_ada_exception@r{, convenience variable}
4988The convenience variable @code{$_ada_exception} holds the address of
4989the exception being thrown. This can be useful when setting a
4990condition for such a catchpoint.
4991
b8e07335
TT
4992@item exception unhandled
4993@kindex catch exception unhandled
37f6a7f4
TT
4994An exception that was raised but is not handled by the program. The
4995convenience variable @code{$_ada_exception} is set as for @code{catch
4996exception}.
b8e07335
TT
4997
4998@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
4999@kindex catch handlers
5000@cindex Ada exception handlers catching
5001@cindex catch Ada exceptions when handled
5002An Ada exception being handled. If an exception name is
5003specified at the end of the command
5004 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5005only when this specific exception is handled.
5006Otherwise, the debugger stops execution when any Ada exception is handled.
5007
5008When inserting a handlers catchpoint on a user-defined
5009exception whose name is identical to one of the exceptions
5010defined by the language, the fully qualified name must be used
5011as the exception name. Otherwise, @value{GDBN} will assume that it
5012should stop on the pre-defined exception rather than the
5013user-defined one. For instance, assuming an exception called
5014 @code{Constraint_Error} is defined in package @code{Pck}, then the
5015command to use to catch such exceptions handling is
5016@kbd{catch handlers Pck.Constraint_Error}.
5017
37f6a7f4
TT
5018The convenience variable @code{$_ada_exception} is set as for
5019@code{catch exception}.
5020
8936fcda 5021@item assert
1a4f73eb 5022@kindex catch assert
37f6a7f4
TT
5023A failed Ada assertion. Note that the convenience variable
5024@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 5025
c906108c 5026@item exec
1a4f73eb 5027@kindex catch exec
4644b6e3 5028@cindex break on fork/exec
b1236ac3 5029A call to @code{exec}.
c906108c 5030
e9076973 5031@anchor{catch syscall}
a96d9b2e 5032@item syscall
e3487908 5033@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 5034@kindex catch syscall
a96d9b2e
SDJ
5035@cindex break on a system call.
5036A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5037syscall is a mechanism for application programs to request a service
5038from the operating system (OS) or one of the OS system services.
5039@value{GDBN} can catch some or all of the syscalls issued by the
5040debuggee, and show the related information for each syscall. If no
5041argument is specified, calls to and returns from all system calls
5042will be caught.
5043
5044@var{name} can be any system call name that is valid for the
5045underlying OS. Just what syscalls are valid depends on the OS. On
5046GNU and Unix systems, you can find the full list of valid syscall
5047names on @file{/usr/include/asm/unistd.h}.
5048
5049@c For MS-Windows, the syscall names and the corresponding numbers
5050@c can be found, e.g., on this URL:
5051@c http://www.metasploit.com/users/opcode/syscalls.html
5052@c but we don't support Windows syscalls yet.
5053
5054Normally, @value{GDBN} knows in advance which syscalls are valid for
5055each OS, so you can use the @value{GDBN} command-line completion
5056facilities (@pxref{Completion,, command completion}) to list the
5057available choices.
5058
5059You may also specify the system call numerically. A syscall's
5060number is the value passed to the OS's syscall dispatcher to
5061identify the requested service. When you specify the syscall by its
5062name, @value{GDBN} uses its database of syscalls to convert the name
5063into the corresponding numeric code, but using the number directly
5064may be useful if @value{GDBN}'s database does not have the complete
5065list of syscalls on your system (e.g., because @value{GDBN} lags
5066behind the OS upgrades).
5067
e3487908
GKB
5068You may specify a group of related syscalls to be caught at once using
5069the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5070instance, on some platforms @value{GDBN} allows you to catch all
5071network related syscalls, by passing the argument @code{group:network}
5072to @code{catch syscall}. Note that not all syscall groups are
5073available in every system. You can use the command completion
5074facilities (@pxref{Completion,, command completion}) to list the
5075syscall groups available on your environment.
5076
a96d9b2e
SDJ
5077The example below illustrates how this command works if you don't provide
5078arguments to it:
5079
5080@smallexample
5081(@value{GDBP}) catch syscall
5082Catchpoint 1 (syscall)
5083(@value{GDBP}) r
5084Starting program: /tmp/catch-syscall
5085
5086Catchpoint 1 (call to syscall 'close'), \
5087 0xffffe424 in __kernel_vsyscall ()
5088(@value{GDBP}) c
5089Continuing.
5090
5091Catchpoint 1 (returned from syscall 'close'), \
5092 0xffffe424 in __kernel_vsyscall ()
5093(@value{GDBP})
5094@end smallexample
5095
5096Here is an example of catching a system call by name:
5097
5098@smallexample
5099(@value{GDBP}) catch syscall chroot
5100Catchpoint 1 (syscall 'chroot' [61])
5101(@value{GDBP}) r
5102Starting program: /tmp/catch-syscall
5103
5104Catchpoint 1 (call to syscall 'chroot'), \
5105 0xffffe424 in __kernel_vsyscall ()
5106(@value{GDBP}) c
5107Continuing.
5108
5109Catchpoint 1 (returned from syscall 'chroot'), \
5110 0xffffe424 in __kernel_vsyscall ()
5111(@value{GDBP})
5112@end smallexample
5113
5114An example of specifying a system call numerically. In the case
5115below, the syscall number has a corresponding entry in the XML
5116file, so @value{GDBN} finds its name and prints it:
5117
5118@smallexample
5119(@value{GDBP}) catch syscall 252
5120Catchpoint 1 (syscall(s) 'exit_group')
5121(@value{GDBP}) r
5122Starting program: /tmp/catch-syscall
5123
5124Catchpoint 1 (call to syscall 'exit_group'), \
5125 0xffffe424 in __kernel_vsyscall ()
5126(@value{GDBP}) c
5127Continuing.
5128
5129Program exited normally.
5130(@value{GDBP})
5131@end smallexample
5132
e3487908
GKB
5133Here is an example of catching a syscall group:
5134
5135@smallexample
5136(@value{GDBP}) catch syscall group:process
5137Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5138'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5139'exit_group' [252] 'waitid' [284] 'unshare' [310])
5140(@value{GDBP}) r
5141Starting program: /tmp/catch-syscall
5142
5143Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5144 from /lib64/ld-linux-x86-64.so.2
5145
5146(@value{GDBP}) c
5147Continuing.
5148@end smallexample
5149
a96d9b2e
SDJ
5150However, there can be situations when there is no corresponding name
5151in XML file for that syscall number. In this case, @value{GDBN} prints
5152a warning message saying that it was not able to find the syscall name,
5153but the catchpoint will be set anyway. See the example below:
5154
5155@smallexample
5156(@value{GDBP}) catch syscall 764
5157warning: The number '764' does not represent a known syscall.
5158Catchpoint 2 (syscall 764)
5159(@value{GDBP})
5160@end smallexample
5161
5162If you configure @value{GDBN} using the @samp{--without-expat} option,
5163it will not be able to display syscall names. Also, if your
5164architecture does not have an XML file describing its system calls,
5165you will not be able to see the syscall names. It is important to
5166notice that these two features are used for accessing the syscall
5167name database. In either case, you will see a warning like this:
5168
5169@smallexample
5170(@value{GDBP}) catch syscall
5171warning: Could not open "syscalls/i386-linux.xml"
5172warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5173GDB will not be able to display syscall names.
5174Catchpoint 1 (syscall)
5175(@value{GDBP})
5176@end smallexample
5177
5178Of course, the file name will change depending on your architecture and system.
5179
5180Still using the example above, you can also try to catch a syscall by its
5181number. In this case, you would see something like:
5182
5183@smallexample
5184(@value{GDBP}) catch syscall 252
5185Catchpoint 1 (syscall(s) 252)
5186@end smallexample
5187
5188Again, in this case @value{GDBN} would not be able to display syscall's names.
5189
c906108c 5190@item fork
1a4f73eb 5191@kindex catch fork
b1236ac3 5192A call to @code{fork}.
c906108c
SS
5193
5194@item vfork
1a4f73eb 5195@kindex catch vfork
b1236ac3 5196A call to @code{vfork}.
c906108c 5197
b8e07335
TT
5198@item load @r{[}@var{regexp}@r{]}
5199@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5200@kindex catch load
5201@kindex catch unload
edcc5120
TT
5202The loading or unloading of a shared library. If @var{regexp} is
5203given, then the catchpoint will stop only if the regular expression
5204matches one of the affected libraries.
5205
ab04a2af 5206@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5207@kindex catch signal
ab04a2af
TT
5208The delivery of a signal.
5209
5210With no arguments, this catchpoint will catch any signal that is not
5211used internally by @value{GDBN}, specifically, all signals except
5212@samp{SIGTRAP} and @samp{SIGINT}.
5213
5214With the argument @samp{all}, all signals, including those used by
5215@value{GDBN}, will be caught. This argument cannot be used with other
5216signal names.
5217
5218Otherwise, the arguments are a list of signal names as given to
5219@code{handle} (@pxref{Signals}). Only signals specified in this list
5220will be caught.
5221
5222One reason that @code{catch signal} can be more useful than
5223@code{handle} is that you can attach commands and conditions to the
5224catchpoint.
5225
5226When a signal is caught by a catchpoint, the signal's @code{stop} and
5227@code{print} settings, as specified by @code{handle}, are ignored.
5228However, whether the signal is still delivered to the inferior depends
5229on the @code{pass} setting; this can be changed in the catchpoint's
5230commands.
5231
c906108c
SS
5232@end table
5233
5234@item tcatch @var{event}
1a4f73eb 5235@kindex tcatch
c906108c
SS
5236Set a catchpoint that is enabled only for one stop. The catchpoint is
5237automatically deleted after the first time the event is caught.
5238
5239@end table
5240
5241Use the @code{info break} command to list the current catchpoints.
5242
c906108c 5243
6d2ebf8b 5244@node Delete Breaks
79a6e687 5245@subsection Deleting Breakpoints
c906108c
SS
5246
5247@cindex clearing breakpoints, watchpoints, catchpoints
5248@cindex deleting breakpoints, watchpoints, catchpoints
5249It is often necessary to eliminate a breakpoint, watchpoint, or
5250catchpoint once it has done its job and you no longer want your program
5251to stop there. This is called @dfn{deleting} the breakpoint. A
5252breakpoint that has been deleted no longer exists; it is forgotten.
5253
5254With the @code{clear} command you can delete breakpoints according to
5255where they are in your program. With the @code{delete} command you can
5256delete individual breakpoints, watchpoints, or catchpoints by specifying
5257their breakpoint numbers.
5258
5259It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5260automatically ignores breakpoints on the first instruction to be executed
5261when you continue execution without changing the execution address.
5262
5263@table @code
5264@kindex clear
5265@item clear
5266Delete any breakpoints at the next instruction to be executed in the
79a6e687 5267selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5268the innermost frame is selected, this is a good way to delete a
5269breakpoint where your program just stopped.
5270
2a25a5ba
EZ
5271@item clear @var{location}
5272Delete any breakpoints set at the specified @var{location}.
5273@xref{Specify Location}, for the various forms of @var{location}; the
5274most useful ones are listed below:
5275
5276@table @code
c906108c
SS
5277@item clear @var{function}
5278@itemx clear @var{filename}:@var{function}
09d4efe1 5279Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5280
5281@item clear @var{linenum}
5282@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5283Delete any breakpoints set at or within the code of the specified
5284@var{linenum} of the specified @var{filename}.
2a25a5ba 5285@end table
c906108c
SS
5286
5287@cindex delete breakpoints
5288@kindex delete
41afff9a 5289@kindex d @r{(@code{delete})}
18da0c51 5290@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5291Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5292list specified as argument. If no argument is specified, delete all
c906108c
SS
5293breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5294confirm off}). You can abbreviate this command as @code{d}.
5295@end table
5296
6d2ebf8b 5297@node Disabling
79a6e687 5298@subsection Disabling Breakpoints
c906108c 5299
4644b6e3 5300@cindex enable/disable a breakpoint
c906108c
SS
5301Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5302prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5303it had been deleted, but remembers the information on the breakpoint so
5304that you can @dfn{enable} it again later.
5305
5306You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5307the @code{enable} and @code{disable} commands, optionally specifying
5308one or more breakpoint numbers as arguments. Use @code{info break} to
5309print a list of all breakpoints, watchpoints, and catchpoints if you
5310do not know which numbers to use.
c906108c 5311
3b784c4f
EZ
5312Disabling and enabling a breakpoint that has multiple locations
5313affects all of its locations.
5314
816338b5
SS
5315A breakpoint, watchpoint, or catchpoint can have any of several
5316different states of enablement:
c906108c
SS
5317
5318@itemize @bullet
5319@item
5320Enabled. The breakpoint stops your program. A breakpoint set
5321with the @code{break} command starts out in this state.
5322@item
5323Disabled. The breakpoint has no effect on your program.
5324@item
5325Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5326disabled.
c906108c 5327@item
816338b5
SS
5328Enabled for a count. The breakpoint stops your program for the next
5329N times, then becomes disabled.
5330@item
c906108c 5331Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5332immediately after it does so it is deleted permanently. A breakpoint
5333set with the @code{tbreak} command starts out in this state.
c906108c
SS
5334@end itemize
5335
5336You can use the following commands to enable or disable breakpoints,
5337watchpoints, and catchpoints:
5338
5339@table @code
c906108c 5340@kindex disable
41afff9a 5341@kindex dis @r{(@code{disable})}
18da0c51 5342@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5343Disable the specified breakpoints---or all breakpoints, if none are
5344listed. A disabled breakpoint has no effect but is not forgotten. All
5345options such as ignore-counts, conditions and commands are remembered in
5346case the breakpoint is enabled again later. You may abbreviate
5347@code{disable} as @code{dis}.
5348
c906108c 5349@kindex enable
18da0c51 5350@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5351Enable the specified breakpoints (or all defined breakpoints). They
5352become effective once again in stopping your program.
5353
18da0c51 5354@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5355Enable the specified breakpoints temporarily. @value{GDBN} disables any
5356of these breakpoints immediately after stopping your program.
5357
18da0c51 5358@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5359Enable the specified breakpoints temporarily. @value{GDBN} records
5360@var{count} with each of the specified breakpoints, and decrements a
5361breakpoint's count when it is hit. When any count reaches 0,
5362@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5363count (@pxref{Conditions, ,Break Conditions}), that will be
5364decremented to 0 before @var{count} is affected.
5365
18da0c51 5366@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5367Enable the specified breakpoints to work once, then die. @value{GDBN}
5368deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5369Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5370@end table
5371
d4f3574e
SS
5372@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5373@c confusing: tbreak is also initially enabled.
c906108c 5374Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5375,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5376subsequently, they become disabled or enabled only when you use one of
5377the commands above. (The command @code{until} can set and delete a
5378breakpoint of its own, but it does not change the state of your other
5379breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5380Stepping}.)
c906108c 5381
6d2ebf8b 5382@node Conditions
79a6e687 5383@subsection Break Conditions
c906108c
SS
5384@cindex conditional breakpoints
5385@cindex breakpoint conditions
5386
5387@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5388@c in particular for a watchpoint?
c906108c
SS
5389The simplest sort of breakpoint breaks every time your program reaches a
5390specified place. You can also specify a @dfn{condition} for a
5391breakpoint. A condition is just a Boolean expression in your
5392programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5393a condition evaluates the expression each time your program reaches it,
5394and your program stops only if the condition is @emph{true}.
5395
5396This is the converse of using assertions for program validation; in that
5397situation, you want to stop when the assertion is violated---that is,
5398when the condition is false. In C, if you want to test an assertion expressed
5399by the condition @var{assert}, you should set the condition
5400@samp{! @var{assert}} on the appropriate breakpoint.
5401
5402Conditions are also accepted for watchpoints; you may not need them,
5403since a watchpoint is inspecting the value of an expression anyhow---but
5404it might be simpler, say, to just set a watchpoint on a variable name,
5405and specify a condition that tests whether the new value is an interesting
5406one.
5407
5408Break conditions can have side effects, and may even call functions in
5409your program. This can be useful, for example, to activate functions
5410that log program progress, or to use your own print functions to
99e008fe 5411format special data structures. The effects are completely predictable
c906108c
SS
5412unless there is another enabled breakpoint at the same address. (In
5413that case, @value{GDBN} might see the other breakpoint first and stop your
5414program without checking the condition of this one.) Note that
d4f3574e
SS
5415breakpoint commands are usually more convenient and flexible than break
5416conditions for the
c906108c 5417purpose of performing side effects when a breakpoint is reached
79a6e687 5418(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5419
83364271
LM
5420Breakpoint conditions can also be evaluated on the target's side if
5421the target supports it. Instead of evaluating the conditions locally,
5422@value{GDBN} encodes the expression into an agent expression
5423(@pxref{Agent Expressions}) suitable for execution on the target,
5424independently of @value{GDBN}. Global variables become raw memory
5425locations, locals become stack accesses, and so forth.
5426
5427In this case, @value{GDBN} will only be notified of a breakpoint trigger
5428when its condition evaluates to true. This mechanism may provide faster
5429response times depending on the performance characteristics of the target
5430since it does not need to keep @value{GDBN} informed about
5431every breakpoint trigger, even those with false conditions.
5432
c906108c
SS
5433Break conditions can be specified when a breakpoint is set, by using
5434@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5435Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5436with the @code{condition} command.
53a5351d 5437
c906108c
SS
5438You can also use the @code{if} keyword with the @code{watch} command.
5439The @code{catch} command does not recognize the @code{if} keyword;
5440@code{condition} is the only way to impose a further condition on a
5441catchpoint.
c906108c
SS
5442
5443@table @code
5444@kindex condition
5445@item condition @var{bnum} @var{expression}
5446Specify @var{expression} as the break condition for breakpoint,
5447watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5448breakpoint @var{bnum} stops your program only if the value of
5449@var{expression} is true (nonzero, in C). When you use
5450@code{condition}, @value{GDBN} checks @var{expression} immediately for
5451syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5452referents in the context of your breakpoint. If @var{expression} uses
5453symbols not referenced in the context of the breakpoint, @value{GDBN}
5454prints an error message:
5455
474c8240 5456@smallexample
d4f3574e 5457No symbol "foo" in current context.
474c8240 5458@end smallexample
d4f3574e
SS
5459
5460@noindent
c906108c
SS
5461@value{GDBN} does
5462not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5463command (or a command that sets a breakpoint with a condition, like
5464@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
5465
5466@item condition @var{bnum}
5467Remove the condition from breakpoint number @var{bnum}. It becomes
5468an ordinary unconditional breakpoint.
5469@end table
5470
5471@cindex ignore count (of breakpoint)
5472A special case of a breakpoint condition is to stop only when the
5473breakpoint has been reached a certain number of times. This is so
5474useful that there is a special way to do it, using the @dfn{ignore
5475count} of the breakpoint. Every breakpoint has an ignore count, which
5476is an integer. Most of the time, the ignore count is zero, and
5477therefore has no effect. But if your program reaches a breakpoint whose
5478ignore count is positive, then instead of stopping, it just decrements
5479the ignore count by one and continues. As a result, if the ignore count
5480value is @var{n}, the breakpoint does not stop the next @var{n} times
5481your program reaches it.
5482
5483@table @code
5484@kindex ignore
5485@item ignore @var{bnum} @var{count}
5486Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5487The next @var{count} times the breakpoint is reached, your program's
5488execution does not stop; other than to decrement the ignore count, @value{GDBN}
5489takes no action.
5490
5491To make the breakpoint stop the next time it is reached, specify
5492a count of zero.
5493
5494When you use @code{continue} to resume execution of your program from a
5495breakpoint, you can specify an ignore count directly as an argument to
5496@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5497Stepping,,Continuing and Stepping}.
c906108c
SS
5498
5499If a breakpoint has a positive ignore count and a condition, the
5500condition is not checked. Once the ignore count reaches zero,
5501@value{GDBN} resumes checking the condition.
5502
5503You could achieve the effect of the ignore count with a condition such
5504as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5505is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5506Variables}.
c906108c
SS
5507@end table
5508
5509Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5510
5511
6d2ebf8b 5512@node Break Commands
79a6e687 5513@subsection Breakpoint Command Lists
c906108c
SS
5514
5515@cindex breakpoint commands
5516You can give any breakpoint (or watchpoint or catchpoint) a series of
5517commands to execute when your program stops due to that breakpoint. For
5518example, you might want to print the values of certain expressions, or
5519enable other breakpoints.
5520
5521@table @code
5522@kindex commands
ca91424e 5523@kindex end@r{ (breakpoint commands)}
18da0c51 5524@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5525@itemx @dots{} @var{command-list} @dots{}
5526@itemx end
95a42b64 5527Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5528themselves appear on the following lines. Type a line containing just
5529@code{end} to terminate the commands.
5530
5531To remove all commands from a breakpoint, type @code{commands} and
5532follow it immediately with @code{end}; that is, give no commands.
5533
95a42b64
TT
5534With no argument, @code{commands} refers to the last breakpoint,
5535watchpoint, or catchpoint set (not to the breakpoint most recently
5536encountered). If the most recent breakpoints were set with a single
5537command, then the @code{commands} will apply to all the breakpoints
5538set by that command. This applies to breakpoints set by
86b17b60
PA
5539@code{rbreak}, and also applies when a single @code{break} command
5540creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5541Expressions}).
c906108c
SS
5542@end table
5543
5544Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5545disabled within a @var{command-list}.
5546
5547You can use breakpoint commands to start your program up again. Simply
5548use the @code{continue} command, or @code{step}, or any other command
5549that resumes execution.
5550
5551Any other commands in the command list, after a command that resumes
5552execution, are ignored. This is because any time you resume execution
5553(even with a simple @code{next} or @code{step}), you may encounter
5554another breakpoint---which could have its own command list, leading to
5555ambiguities about which list to execute.
5556
5557@kindex silent
5558If the first command you specify in a command list is @code{silent}, the
5559usual message about stopping at a breakpoint is not printed. This may
5560be desirable for breakpoints that are to print a specific message and
5561then continue. If none of the remaining commands print anything, you
5562see no sign that the breakpoint was reached. @code{silent} is
5563meaningful only at the beginning of a breakpoint command list.
5564
5565The commands @code{echo}, @code{output}, and @code{printf} allow you to
5566print precisely controlled output, and are often useful in silent
79a6e687 5567breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5568
5569For example, here is how you could use breakpoint commands to print the
5570value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5571
474c8240 5572@smallexample
c906108c
SS
5573break foo if x>0
5574commands
5575silent
5576printf "x is %d\n",x
5577cont
5578end
474c8240 5579@end smallexample
c906108c
SS
5580
5581One application for breakpoint commands is to compensate for one bug so
5582you can test for another. Put a breakpoint just after the erroneous line
5583of code, give it a condition to detect the case in which something
5584erroneous has been done, and give it commands to assign correct values
5585to any variables that need them. End with the @code{continue} command
5586so that your program does not stop, and start with the @code{silent}
5587command so that no output is produced. Here is an example:
5588
474c8240 5589@smallexample
c906108c
SS
5590break 403
5591commands
5592silent
5593set x = y + 4
5594cont
5595end
474c8240 5596@end smallexample
c906108c 5597
e7e0cddf
SS
5598@node Dynamic Printf
5599@subsection Dynamic Printf
5600
5601@cindex dynamic printf
5602@cindex dprintf
5603The dynamic printf command @code{dprintf} combines a breakpoint with
5604formatted printing of your program's data to give you the effect of
5605inserting @code{printf} calls into your program on-the-fly, without
5606having to recompile it.
5607
5608In its most basic form, the output goes to the GDB console. However,
5609you can set the variable @code{dprintf-style} for alternate handling.
5610For instance, you can ask to format the output by calling your
5611program's @code{printf} function. This has the advantage that the
5612characters go to the program's output device, so they can recorded in
5613redirects to files and so forth.
5614
d3ce09f5
SS
5615If you are doing remote debugging with a stub or agent, you can also
5616ask to have the printf handled by the remote agent. In addition to
5617ensuring that the output goes to the remote program's device along
5618with any other output the program might produce, you can also ask that
5619the dprintf remain active even after disconnecting from the remote
5620target. Using the stub/agent is also more efficient, as it can do
5621everything without needing to communicate with @value{GDBN}.
5622
e7e0cddf
SS
5623@table @code
5624@kindex dprintf
5625@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5626Whenever execution reaches @var{location}, print the values of one or
5627more @var{expressions} under the control of the string @var{template}.
5628To print several values, separate them with commas.
5629
5630@item set dprintf-style @var{style}
5631Set the dprintf output to be handled in one of several different
5632styles enumerated below. A change of style affects all existing
5633dynamic printfs immediately. (If you need individual control over the
5634print commands, simply define normal breakpoints with
5635explicitly-supplied command lists.)
5636
18da0c51 5637@table @code
e7e0cddf
SS
5638@item gdb
5639@kindex dprintf-style gdb
5640Handle the output using the @value{GDBN} @code{printf} command.
5641
5642@item call
5643@kindex dprintf-style call
5644Handle the output by calling a function in your program (normally
5645@code{printf}).
5646
d3ce09f5
SS
5647@item agent
5648@kindex dprintf-style agent
5649Have the remote debugging agent (such as @code{gdbserver}) handle
5650the output itself. This style is only available for agents that
5651support running commands on the target.
18da0c51 5652@end table
d3ce09f5 5653
e7e0cddf
SS
5654@item set dprintf-function @var{function}
5655Set the function to call if the dprintf style is @code{call}. By
5656default its value is @code{printf}. You may set it to any expression.
5657that @value{GDBN} can evaluate to a function, as per the @code{call}
5658command.
5659
5660@item set dprintf-channel @var{channel}
5661Set a ``channel'' for dprintf. If set to a non-empty value,
5662@value{GDBN} will evaluate it as an expression and pass the result as
5663a first argument to the @code{dprintf-function}, in the manner of
5664@code{fprintf} and similar functions. Otherwise, the dprintf format
5665string will be the first argument, in the manner of @code{printf}.
5666
5667As an example, if you wanted @code{dprintf} output to go to a logfile
5668that is a standard I/O stream assigned to the variable @code{mylog},
5669you could do the following:
5670
5671@example
5672(gdb) set dprintf-style call
5673(gdb) set dprintf-function fprintf
5674(gdb) set dprintf-channel mylog
5675(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5676Dprintf 1 at 0x123456: file main.c, line 25.
5677(gdb) info break
56781 dprintf keep y 0x00123456 in main at main.c:25
5679 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5680 continue
5681(gdb)
5682@end example
5683
5684Note that the @code{info break} displays the dynamic printf commands
5685as normal breakpoint commands; you can thus easily see the effect of
5686the variable settings.
5687
d3ce09f5
SS
5688@item set disconnected-dprintf on
5689@itemx set disconnected-dprintf off
5690@kindex set disconnected-dprintf
5691Choose whether @code{dprintf} commands should continue to run if
5692@value{GDBN} has disconnected from the target. This only applies
5693if the @code{dprintf-style} is @code{agent}.
5694
5695@item show disconnected-dprintf off
5696@kindex show disconnected-dprintf
5697Show the current choice for disconnected @code{dprintf}.
5698
e7e0cddf
SS
5699@end table
5700
5701@value{GDBN} does not check the validity of function and channel,
5702relying on you to supply values that are meaningful for the contexts
5703in which they are being used. For instance, the function and channel
5704may be the values of local variables, but if that is the case, then
5705all enabled dynamic prints must be at locations within the scope of
5706those locals. If evaluation fails, @value{GDBN} will report an error.
5707
6149aea9
PA
5708@node Save Breakpoints
5709@subsection How to save breakpoints to a file
5710
5711To save breakpoint definitions to a file use the @w{@code{save
5712breakpoints}} command.
5713
5714@table @code
5715@kindex save breakpoints
5716@cindex save breakpoints to a file for future sessions
5717@item save breakpoints [@var{filename}]
5718This command saves all current breakpoint definitions together with
5719their commands and ignore counts, into a file @file{@var{filename}}
5720suitable for use in a later debugging session. This includes all
5721types of breakpoints (breakpoints, watchpoints, catchpoints,
5722tracepoints). To read the saved breakpoint definitions, use the
5723@code{source} command (@pxref{Command Files}). Note that watchpoints
5724with expressions involving local variables may fail to be recreated
5725because it may not be possible to access the context where the
5726watchpoint is valid anymore. Because the saved breakpoint definitions
5727are simply a sequence of @value{GDBN} commands that recreate the
5728breakpoints, you can edit the file in your favorite editing program,
5729and remove the breakpoint definitions you're not interested in, or
5730that can no longer be recreated.
5731@end table
5732
62e5f89c
SDJ
5733@node Static Probe Points
5734@subsection Static Probe Points
5735
5736@cindex static probe point, SystemTap
3133f8c1 5737@cindex static probe point, DTrace
62e5f89c
SDJ
5738@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5739for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5740runtime code and data footprint, and no dynamic relocations.
5741
5742Currently, the following types of probes are supported on
5743ELF-compatible systems:
5744
5745@itemize @bullet
62e5f89c 5746
3133f8c1
JM
5747@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5748@acronym{SDT} probes@footnote{See
62e5f89c 5749@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5750for more information on how to add @code{SystemTap} @acronym{SDT}
5751probes in your applications.}. @code{SystemTap} probes are usable
5752from assembly, C and C@t{++} languages@footnote{See
5753@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5754for a good reference on how the @acronym{SDT} probes are implemented.}.
5755
5756@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5757@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5758C@t{++} languages.
5759@end itemize
62e5f89c
SDJ
5760
5761@cindex semaphores on static probe points
3133f8c1
JM
5762Some @code{SystemTap} probes have an associated semaphore variable;
5763for instance, this happens automatically if you defined your probe
5764using a DTrace-style @file{.d} file. If your probe has a semaphore,
5765@value{GDBN} will automatically enable it when you specify a
5766breakpoint using the @samp{-probe-stap} notation. But, if you put a
5767breakpoint at a probe's location by some other method (e.g.,
5768@code{break file:line}), then @value{GDBN} will not automatically set
5769the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5770
5771You can examine the available static static probes using @code{info
5772probes}, with optional arguments:
5773
5774@table @code
5775@kindex info probes
3133f8c1
JM
5776@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5777If given, @var{type} is either @code{stap} for listing
5778@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5779probes. If omitted all probes are listed regardless of their types.
5780
62e5f89c
SDJ
5781If given, @var{provider} is a regular expression used to match against provider
5782names when selecting which probes to list. If omitted, probes by all
5783probes from all providers are listed.
5784
5785If given, @var{name} is a regular expression to match against probe names
5786when selecting which probes to list. If omitted, probe names are not
5787considered when deciding whether to display them.
5788
5789If given, @var{objfile} is a regular expression used to select which
5790object files (executable or shared libraries) to examine. If not
5791given, all object files are considered.
5792
5793@item info probes all
5794List the available static probes, from all types.
5795@end table
5796
9aca2ff8
JM
5797@cindex enabling and disabling probes
5798Some probe points can be enabled and/or disabled. The effect of
5799enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5800handled. Some @code{DTrace} probes can be enabled or
5801disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5802
5803You can enable (or disable) one or more probes using the following
5804commands, with optional arguments:
5805
5806@table @code
5807@kindex enable probes
5808@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5809If given, @var{provider} is a regular expression used to match against
5810provider names when selecting which probes to enable. If omitted,
5811all probes from all providers are enabled.
5812
5813If given, @var{name} is a regular expression to match against probe
5814names when selecting which probes to enable. If omitted, probe names
5815are not considered when deciding whether to enable them.
5816
5817If given, @var{objfile} is a regular expression used to select which
5818object files (executable or shared libraries) to examine. If not
5819given, all object files are considered.
5820
5821@kindex disable probes
5822@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5823See the @code{enable probes} command above for a description of the
5824optional arguments accepted by this command.
5825@end table
5826
62e5f89c
SDJ
5827@vindex $_probe_arg@r{, convenience variable}
5828A probe may specify up to twelve arguments. These are available at the
5829point at which the probe is defined---that is, when the current PC is
5830at the probe's location. The arguments are available using the
5831convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5832@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5833probes each probe argument is an integer of the appropriate size;
5834types are not preserved. In @code{DTrace} probes types are preserved
5835provided that they are recognized as such by @value{GDBN}; otherwise
5836the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5837convenience variable @code{$_probe_argc} holds the number of arguments
5838at the current probe point.
5839
5840These variables are always available, but attempts to access them at
5841any location other than a probe point will cause @value{GDBN} to give
5842an error message.
5843
5844
c906108c 5845@c @ifclear BARETARGET
6d2ebf8b 5846@node Error in Breakpoints
d4f3574e 5847@subsection ``Cannot insert breakpoints''
c906108c 5848
fa3a767f
PA
5849If you request too many active hardware-assisted breakpoints and
5850watchpoints, you will see this error message:
d4f3574e
SS
5851
5852@c FIXME: the precise wording of this message may change; the relevant
5853@c source change is not committed yet (Sep 3, 1999).
5854@smallexample
5855Stopped; cannot insert breakpoints.
5856You may have requested too many hardware breakpoints and watchpoints.
5857@end smallexample
5858
5859@noindent
5860This message is printed when you attempt to resume the program, since
5861only then @value{GDBN} knows exactly how many hardware breakpoints and
5862watchpoints it needs to insert.
5863
5864When this message is printed, you need to disable or remove some of the
5865hardware-assisted breakpoints and watchpoints, and then continue.
5866
79a6e687 5867@node Breakpoint-related Warnings
1485d690
KB
5868@subsection ``Breakpoint address adjusted...''
5869@cindex breakpoint address adjusted
5870
5871Some processor architectures place constraints on the addresses at
5872which breakpoints may be placed. For architectures thus constrained,
5873@value{GDBN} will attempt to adjust the breakpoint's address to comply
5874with the constraints dictated by the architecture.
5875
5876One example of such an architecture is the Fujitsu FR-V. The FR-V is
5877a VLIW architecture in which a number of RISC-like instructions may be
5878bundled together for parallel execution. The FR-V architecture
5879constrains the location of a breakpoint instruction within such a
5880bundle to the instruction with the lowest address. @value{GDBN}
5881honors this constraint by adjusting a breakpoint's address to the
5882first in the bundle.
5883
5884It is not uncommon for optimized code to have bundles which contain
5885instructions from different source statements, thus it may happen that
5886a breakpoint's address will be adjusted from one source statement to
5887another. Since this adjustment may significantly alter @value{GDBN}'s
5888breakpoint related behavior from what the user expects, a warning is
5889printed when the breakpoint is first set and also when the breakpoint
5890is hit.
5891
5892A warning like the one below is printed when setting a breakpoint
5893that's been subject to address adjustment:
5894
5895@smallexample
5896warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5897@end smallexample
5898
5899Such warnings are printed both for user settable and @value{GDBN}'s
5900internal breakpoints. If you see one of these warnings, you should
5901verify that a breakpoint set at the adjusted address will have the
5902desired affect. If not, the breakpoint in question may be removed and
b383017d 5903other breakpoints may be set which will have the desired behavior.
1485d690
KB
5904E.g., it may be sufficient to place the breakpoint at a later
5905instruction. A conditional breakpoint may also be useful in some
5906cases to prevent the breakpoint from triggering too often.
5907
5908@value{GDBN} will also issue a warning when stopping at one of these
5909adjusted breakpoints:
5910
5911@smallexample
5912warning: Breakpoint 1 address previously adjusted from 0x00010414
5913to 0x00010410.
5914@end smallexample
5915
5916When this warning is encountered, it may be too late to take remedial
5917action except in cases where the breakpoint is hit earlier or more
5918frequently than expected.
d4f3574e 5919
6d2ebf8b 5920@node Continuing and Stepping
79a6e687 5921@section Continuing and Stepping
c906108c
SS
5922
5923@cindex stepping
5924@cindex continuing
5925@cindex resuming execution
5926@dfn{Continuing} means resuming program execution until your program
5927completes normally. In contrast, @dfn{stepping} means executing just
5928one more ``step'' of your program, where ``step'' may mean either one
5929line of source code, or one machine instruction (depending on what
7a292a7a
SS
5930particular command you use). Either when continuing or when stepping,
5931your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5932it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5933@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5934or you may step into the signal's handler (@pxref{stepping and signal
5935handlers}).)
c906108c
SS
5936
5937@table @code
5938@kindex continue
41afff9a
EZ
5939@kindex c @r{(@code{continue})}
5940@kindex fg @r{(resume foreground execution)}
c906108c
SS
5941@item continue @r{[}@var{ignore-count}@r{]}
5942@itemx c @r{[}@var{ignore-count}@r{]}
5943@itemx fg @r{[}@var{ignore-count}@r{]}
5944Resume program execution, at the address where your program last stopped;
5945any breakpoints set at that address are bypassed. The optional argument
5946@var{ignore-count} allows you to specify a further number of times to
5947ignore a breakpoint at this location; its effect is like that of
79a6e687 5948@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5949
5950The argument @var{ignore-count} is meaningful only when your program
5951stopped due to a breakpoint. At other times, the argument to
5952@code{continue} is ignored.
5953
d4f3574e
SS
5954The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5955debugged program is deemed to be the foreground program) are provided
5956purely for convenience, and have exactly the same behavior as
5957@code{continue}.
c906108c
SS
5958@end table
5959
5960To resume execution at a different place, you can use @code{return}
79a6e687 5961(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5962calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5963Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5964
5965A typical technique for using stepping is to set a breakpoint
79a6e687 5966(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5967beginning of the function or the section of your program where a problem
5968is believed to lie, run your program until it stops at that breakpoint,
5969and then step through the suspect area, examining the variables that are
5970interesting, until you see the problem happen.
5971
5972@table @code
5973@kindex step
41afff9a 5974@kindex s @r{(@code{step})}
c906108c
SS
5975@item step
5976Continue running your program until control reaches a different source
5977line, then stop it and return control to @value{GDBN}. This command is
5978abbreviated @code{s}.
5979
5980@quotation
5981@c "without debugging information" is imprecise; actually "without line
5982@c numbers in the debugging information". (gcc -g1 has debugging info but
5983@c not line numbers). But it seems complex to try to make that
5984@c distinction here.
5985@emph{Warning:} If you use the @code{step} command while control is
5986within a function that was compiled without debugging information,
5987execution proceeds until control reaches a function that does have
5988debugging information. Likewise, it will not step into a function which
5989is compiled without debugging information. To step through functions
5990without debugging information, use the @code{stepi} command, described
5991below.
5992@end quotation
5993
4a92d011
EZ
5994The @code{step} command only stops at the first instruction of a source
5995line. This prevents the multiple stops that could otherwise occur in
5996@code{switch} statements, @code{for} loops, etc. @code{step} continues
5997to stop if a function that has debugging information is called within
5998the line. In other words, @code{step} @emph{steps inside} any functions
5999called within the line.
c906108c 6000
d4f3574e
SS
6001Also, the @code{step} command only enters a function if there is line
6002number information for the function. Otherwise it acts like the
5d161b24 6003@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 6004on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 6005was any debugging information about the routine.
c906108c
SS
6006
6007@item step @var{count}
6008Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
6009breakpoint is reached, or a signal not related to stepping occurs before
6010@var{count} steps, stepping stops right away.
c906108c
SS
6011
6012@kindex next
41afff9a 6013@kindex n @r{(@code{next})}
c906108c
SS
6014@item next @r{[}@var{count}@r{]}
6015Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
6016This is similar to @code{step}, but function calls that appear within
6017the line of code are executed without stopping. Execution stops when
6018control reaches a different line of code at the original stack level
6019that was executing when you gave the @code{next} command. This command
6020is abbreviated @code{n}.
c906108c
SS
6021
6022An argument @var{count} is a repeat count, as for @code{step}.
6023
6024
6025@c FIX ME!! Do we delete this, or is there a way it fits in with
6026@c the following paragraph? --- Vctoria
6027@c
6028@c @code{next} within a function that lacks debugging information acts like
6029@c @code{step}, but any function calls appearing within the code of the
6030@c function are executed without stopping.
6031
d4f3574e
SS
6032The @code{next} command only stops at the first instruction of a
6033source line. This prevents multiple stops that could otherwise occur in
4a92d011 6034@code{switch} statements, @code{for} loops, etc.
c906108c 6035
b90a5f51
CF
6036@kindex set step-mode
6037@item set step-mode
6038@cindex functions without line info, and stepping
6039@cindex stepping into functions with no line info
6040@itemx set step-mode on
4a92d011 6041The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
6042stop at the first instruction of a function which contains no debug line
6043information rather than stepping over it.
6044
4a92d011
EZ
6045This is useful in cases where you may be interested in inspecting the
6046machine instructions of a function which has no symbolic info and do not
6047want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
6048
6049@item set step-mode off
4a92d011 6050Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
6051debug information. This is the default.
6052
9c16f35a
EZ
6053@item show step-mode
6054Show whether @value{GDBN} will stop in or step over functions without
6055source line debug information.
6056
c906108c 6057@kindex finish
8dfa32fc 6058@kindex fin @r{(@code{finish})}
c906108c
SS
6059@item finish
6060Continue running until just after function in the selected stack frame
8dfa32fc
JB
6061returns. Print the returned value (if any). This command can be
6062abbreviated as @code{fin}.
c906108c
SS
6063
6064Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 6065,Returning from a Function}).
c906108c 6066
000439d5
TT
6067@kindex set print finish
6068@kindex show print finish
6069@item set print finish @r{[}on|off@r{]}
6070@itemx show print finish
6071By default the @code{finish} command will show the value that is
6072returned by the function. This can be disabled using @code{set print
6073finish off}. When disabled, the value is still entered into the value
6074history (@pxref{Value History}), but not displayed.
6075
c906108c 6076@kindex until
41afff9a 6077@kindex u @r{(@code{until})}
09d4efe1 6078@cindex run until specified location
c906108c
SS
6079@item until
6080@itemx u
6081Continue running until a source line past the current line, in the
6082current stack frame, is reached. This command is used to avoid single
6083stepping through a loop more than once. It is like the @code{next}
6084command, except that when @code{until} encounters a jump, it
6085automatically continues execution until the program counter is greater
6086than the address of the jump.
6087
6088This means that when you reach the end of a loop after single stepping
6089though it, @code{until} makes your program continue execution until it
6090exits the loop. In contrast, a @code{next} command at the end of a loop
6091simply steps back to the beginning of the loop, which forces you to step
6092through the next iteration.
6093
6094@code{until} always stops your program if it attempts to exit the current
6095stack frame.
6096
6097@code{until} may produce somewhat counterintuitive results if the order
6098of machine code does not match the order of the source lines. For
6099example, in the following excerpt from a debugging session, the @code{f}
6100(@code{frame}) command shows that execution is stopped at line
6101@code{206}; yet when we use @code{until}, we get to line @code{195}:
6102
474c8240 6103@smallexample
c906108c
SS
6104(@value{GDBP}) f
6105#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6106206 expand_input();
6107(@value{GDBP}) until
6108195 for ( ; argc > 0; NEXTARG) @{
474c8240 6109@end smallexample
c906108c
SS
6110
6111This happened because, for execution efficiency, the compiler had
6112generated code for the loop closure test at the end, rather than the
6113start, of the loop---even though the test in a C @code{for}-loop is
6114written before the body of the loop. The @code{until} command appeared
6115to step back to the beginning of the loop when it advanced to this
6116expression; however, it has not really gone to an earlier
6117statement---not in terms of the actual machine code.
6118
6119@code{until} with no argument works by means of single
6120instruction stepping, and hence is slower than @code{until} with an
6121argument.
6122
6123@item until @var{location}
6124@itemx u @var{location}
697aa1b7
EZ
6125Continue running your program until either the specified @var{location} is
6126reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6127the forms described in @ref{Specify Location}.
6128This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6129hence is quicker than @code{until} without an argument. The specified
6130location is actually reached only if it is in the current frame. This
6131implies that @code{until} can be used to skip over recursive function
6132invocations. For instance in the code below, if the current location is
6133line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6134line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6135invocations have returned.
6136
6137@smallexample
613894 int factorial (int value)
613995 @{
614096 if (value > 1) @{
614197 value *= factorial (value - 1);
614298 @}
614399 return (value);
6144100 @}
6145@end smallexample
6146
6147
6148@kindex advance @var{location}
984359d2 6149@item advance @var{location}
09d4efe1 6150Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6151required, which should be of one of the forms described in
6152@ref{Specify Location}.
6153Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6154frame. This command is similar to @code{until}, but @code{advance} will
6155not skip over recursive function calls, and the target location doesn't
6156have to be in the same frame as the current one.
6157
c906108c
SS
6158
6159@kindex stepi
41afff9a 6160@kindex si @r{(@code{stepi})}
c906108c 6161@item stepi
96a2c332 6162@itemx stepi @var{arg}
c906108c
SS
6163@itemx si
6164Execute one machine instruction, then stop and return to the debugger.
6165
6166It is often useful to do @samp{display/i $pc} when stepping by machine
6167instructions. This makes @value{GDBN} automatically display the next
6168instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6169Display,, Automatic Display}.
c906108c
SS
6170
6171An argument is a repeat count, as in @code{step}.
6172
6173@need 750
6174@kindex nexti
41afff9a 6175@kindex ni @r{(@code{nexti})}
c906108c 6176@item nexti
96a2c332 6177@itemx nexti @var{arg}
c906108c
SS
6178@itemx ni
6179Execute one machine instruction, but if it is a function call,
6180proceed until the function returns.
6181
6182An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6183
6184@end table
6185
6186@anchor{range stepping}
6187@cindex range stepping
6188@cindex target-assisted range stepping
6189By default, and if available, @value{GDBN} makes use of
6190target-assisted @dfn{range stepping}. In other words, whenever you
6191use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6192tells the target to step the corresponding range of instruction
6193addresses instead of issuing multiple single-steps. This speeds up
6194line stepping, particularly for remote targets. Ideally, there should
6195be no reason you would want to turn range stepping off. However, it's
6196possible that a bug in the debug info, a bug in the remote stub (for
6197remote targets), or even a bug in @value{GDBN} could make line
6198stepping behave incorrectly when target-assisted range stepping is
6199enabled. You can use the following command to turn off range stepping
6200if necessary:
6201
6202@table @code
6203@kindex set range-stepping
6204@kindex show range-stepping
6205@item set range-stepping
6206@itemx show range-stepping
6207Control whether range stepping is enabled.
6208
6209If @code{on}, and the target supports it, @value{GDBN} tells the
6210target to step a range of addresses itself, instead of issuing
6211multiple single-steps. If @code{off}, @value{GDBN} always issues
6212single-steps, even if range stepping is supported by the target. The
6213default is @code{on}.
6214
c906108c
SS
6215@end table
6216
aad1c02c
TT
6217@node Skipping Over Functions and Files
6218@section Skipping Over Functions and Files
1bfeeb0f
JL
6219@cindex skipping over functions and files
6220
6221The program you are debugging may contain some functions which are
8244c20d 6222uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6223skip a function, all functions in a file or a particular function in
6224a particular file when stepping.
1bfeeb0f
JL
6225
6226For example, consider the following C function:
6227
6228@smallexample
6229101 int func()
6230102 @{
6231103 foo(boring());
6232104 bar(boring());
6233105 @}
6234@end smallexample
6235
6236@noindent
6237Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6238are not interested in stepping through @code{boring}. If you run @code{step}
6239at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6240step over both @code{foo} and @code{boring}!
6241
6242One solution is to @code{step} into @code{boring} and use the @code{finish}
6243command to immediately exit it. But this can become tedious if @code{boring}
6244is called from many places.
6245
6246A more flexible solution is to execute @kbd{skip boring}. This instructs
6247@value{GDBN} never to step into @code{boring}. Now when you execute
6248@code{step} at line 103, you'll step over @code{boring} and directly into
6249@code{foo}.
6250
cce0e923
DE
6251Functions may be skipped by providing either a function name, linespec
6252(@pxref{Specify Location}), regular expression that matches the function's
6253name, file name or a @code{glob}-style pattern that matches the file name.
6254
6255On Posix systems the form of the regular expression is
6256``Extended Regular Expressions''. See for example @samp{man 7 regex}
6257on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6258expression is whatever is provided by the @code{regcomp} function of
6259the underlying system.
6260See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6261description of @code{glob}-style patterns.
6262
6263@table @code
6264@kindex skip
6265@item skip @r{[}@var{options}@r{]}
6266The basic form of the @code{skip} command takes zero or more options
6267that specify what to skip.
6268The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6269
6270@table @code
cce0e923
DE
6271@item -file @var{file}
6272@itemx -fi @var{file}
6273Functions in @var{file} will be skipped over when stepping.
6274
6275@item -gfile @var{file-glob-pattern}
6276@itemx -gfi @var{file-glob-pattern}
6277@cindex skipping over files via glob-style patterns
6278Functions in files matching @var{file-glob-pattern} will be skipped
6279over when stepping.
6280
6281@smallexample
6282(gdb) skip -gfi utils/*.c
6283@end smallexample
6284
6285@item -function @var{linespec}
6286@itemx -fu @var{linespec}
6287Functions named by @var{linespec} or the function containing the line
6288named by @var{linespec} will be skipped over when stepping.
6289@xref{Specify Location}.
6290
6291@item -rfunction @var{regexp}
6292@itemx -rfu @var{regexp}
6293@cindex skipping over functions via regular expressions
6294Functions whose name matches @var{regexp} will be skipped over when stepping.
6295
6296This form is useful for complex function names.
6297For example, there is generally no need to step into C@t{++} @code{std::string}
6298constructors or destructors. Plus with C@t{++} templates it can be hard to
6299write out the full name of the function, and often it doesn't matter what
6300the template arguments are. Specifying the function to be skipped as a
6301regular expression makes this easier.
6302
6303@smallexample
6304(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6305@end smallexample
6306
6307If you want to skip every templated C@t{++} constructor and destructor
6308in the @code{std} namespace you can do:
6309
6310@smallexample
6311(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6312@end smallexample
6313@end table
6314
6315If no options are specified, the function you're currently debugging
6316will be skipped.
6317
1bfeeb0f 6318@kindex skip function
cce0e923 6319@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6320After running this command, the function named by @var{linespec} or the
6321function containing the line named by @var{linespec} will be skipped over when
983fb131 6322stepping. @xref{Specify Location}.
1bfeeb0f
JL
6323
6324If you do not specify @var{linespec}, the function you're currently debugging
6325will be skipped.
6326
6327(If you have a function called @code{file} that you want to skip, use
6328@kbd{skip function file}.)
6329
6330@kindex skip file
6331@item skip file @r{[}@var{filename}@r{]}
6332After running this command, any function whose source lives in @var{filename}
6333will be skipped over when stepping.
6334
cce0e923
DE
6335@smallexample
6336(gdb) skip file boring.c
6337File boring.c will be skipped when stepping.
6338@end smallexample
6339
1bfeeb0f
JL
6340If you do not specify @var{filename}, functions whose source lives in the file
6341you're currently debugging will be skipped.
6342@end table
6343
6344Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6345These are the commands for managing your list of skips:
6346
6347@table @code
6348@kindex info skip
6349@item info skip @r{[}@var{range}@r{]}
6350Print details about the specified skip(s). If @var{range} is not specified,
6351print a table with details about all functions and files marked for skipping.
6352@code{info skip} prints the following information about each skip:
6353
6354@table @emph
6355@item Identifier
6356A number identifying this skip.
1bfeeb0f 6357@item Enabled or Disabled
cce0e923
DE
6358Enabled skips are marked with @samp{y}.
6359Disabled skips are marked with @samp{n}.
6360@item Glob
6361If the file name is a @samp{glob} pattern this is @samp{y}.
6362Otherwise it is @samp{n}.
6363@item File
6364The name or @samp{glob} pattern of the file to be skipped.
6365If no file is specified this is @samp{<none>}.
6366@item RE
6367If the function name is a @samp{regular expression} this is @samp{y}.
6368Otherwise it is @samp{n}.
6369@item Function
6370The name or regular expression of the function to skip.
6371If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6372@end table
6373
6374@kindex skip delete
6375@item skip delete @r{[}@var{range}@r{]}
6376Delete the specified skip(s). If @var{range} is not specified, delete all
6377skips.
6378
6379@kindex skip enable
6380@item skip enable @r{[}@var{range}@r{]}
6381Enable the specified skip(s). If @var{range} is not specified, enable all
6382skips.
6383
6384@kindex skip disable
6385@item skip disable @r{[}@var{range}@r{]}
6386Disable the specified skip(s). If @var{range} is not specified, disable all
6387skips.
6388
3e68067f
SM
6389@kindex set debug skip
6390@item set debug skip @r{[}on|off@r{]}
6391Set whether to print the debug output about skipping files and functions.
6392
6393@kindex show debug skip
6394@item show debug skip
6395Show whether the debug output about skipping files and functions is printed.
6396
1bfeeb0f
JL
6397@end table
6398
6d2ebf8b 6399@node Signals
c906108c
SS
6400@section Signals
6401@cindex signals
6402
6403A signal is an asynchronous event that can happen in a program. The
6404operating system defines the possible kinds of signals, and gives each
6405kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6406signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6407@code{SIGSEGV} is the signal a program gets from referencing a place in
6408memory far away from all the areas in use; @code{SIGALRM} occurs when
6409the alarm clock timer goes off (which happens only if your program has
6410requested an alarm).
6411
6412@cindex fatal signals
6413Some signals, including @code{SIGALRM}, are a normal part of the
6414functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6415errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6416program has not specified in advance some other way to handle the signal.
6417@code{SIGINT} does not indicate an error in your program, but it is normally
6418fatal so it can carry out the purpose of the interrupt: to kill the program.
6419
6420@value{GDBN} has the ability to detect any occurrence of a signal in your
6421program. You can tell @value{GDBN} in advance what to do for each kind of
6422signal.
6423
6424@cindex handling signals
24f93129
EZ
6425Normally, @value{GDBN} is set up to let the non-erroneous signals like
6426@code{SIGALRM} be silently passed to your program
6427(so as not to interfere with their role in the program's functioning)
c906108c
SS
6428but to stop your program immediately whenever an error signal happens.
6429You can change these settings with the @code{handle} command.
6430
6431@table @code
6432@kindex info signals
09d4efe1 6433@kindex info handle
c906108c 6434@item info signals
96a2c332 6435@itemx info handle
c906108c
SS
6436Print a table of all the kinds of signals and how @value{GDBN} has been told to
6437handle each one. You can use this to see the signal numbers of all
6438the defined types of signals.
6439
45ac1734
EZ
6440@item info signals @var{sig}
6441Similar, but print information only about the specified signal number.
6442
d4f3574e 6443@code{info handle} is an alias for @code{info signals}.
c906108c 6444
ab04a2af
TT
6445@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6446Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6447for details about this command.
6448
c906108c 6449@kindex handle
45ac1734 6450@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6451Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6452can be the number of a signal or its name (with or without the
24f93129 6453@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6454@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6455known signals. Optional arguments @var{keywords}, described below,
6456say what change to make.
c906108c
SS
6457@end table
6458
6459@c @group
6460The keywords allowed by the @code{handle} command can be abbreviated.
6461Their full names are:
6462
6463@table @code
6464@item nostop
6465@value{GDBN} should not stop your program when this signal happens. It may
6466still print a message telling you that the signal has come in.
6467
6468@item stop
6469@value{GDBN} should stop your program when this signal happens. This implies
6470the @code{print} keyword as well.
6471
6472@item print
6473@value{GDBN} should print a message when this signal happens.
6474
6475@item noprint
6476@value{GDBN} should not mention the occurrence of the signal at all. This
6477implies the @code{nostop} keyword as well.
6478
6479@item pass
5ece1a18 6480@itemx noignore
c906108c
SS
6481@value{GDBN} should allow your program to see this signal; your program
6482can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6483and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6484
6485@item nopass
5ece1a18 6486@itemx ignore
c906108c 6487@value{GDBN} should not allow your program to see this signal.
5ece1a18 6488@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6489@end table
6490@c @end group
6491
d4f3574e
SS
6492When a signal stops your program, the signal is not visible to the
6493program until you
c906108c
SS
6494continue. Your program sees the signal then, if @code{pass} is in
6495effect for the signal in question @emph{at that time}. In other words,
6496after @value{GDBN} reports a signal, you can use the @code{handle}
6497command with @code{pass} or @code{nopass} to control whether your
6498program sees that signal when you continue.
6499
24f93129
EZ
6500The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6501non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6502@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6503erroneous signals.
6504
c906108c
SS
6505You can also use the @code{signal} command to prevent your program from
6506seeing a signal, or cause it to see a signal it normally would not see,
6507or to give it any signal at any time. For example, if your program stopped
6508due to some sort of memory reference error, you might store correct
6509values into the erroneous variables and continue, hoping to see more
6510execution; but your program would probably terminate immediately as
6511a result of the fatal signal once it saw the signal. To prevent this,
6512you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6513Program a Signal}.
c906108c 6514
e5f8a7cc
PA
6515@cindex stepping and signal handlers
6516@anchor{stepping and signal handlers}
6517
6518@value{GDBN} optimizes for stepping the mainline code. If a signal
6519that has @code{handle nostop} and @code{handle pass} set arrives while
6520a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6521in progress, @value{GDBN} lets the signal handler run and then resumes
6522stepping the mainline code once the signal handler returns. In other
6523words, @value{GDBN} steps over the signal handler. This prevents
6524signals that you've specified as not interesting (with @code{handle
6525nostop}) from changing the focus of debugging unexpectedly. Note that
6526the signal handler itself may still hit a breakpoint, stop for another
6527signal that has @code{handle stop} in effect, or for any other event
6528that normally results in stopping the stepping command sooner. Also
6529note that @value{GDBN} still informs you that the program received a
6530signal if @code{handle print} is set.
6531
6532@anchor{stepping into signal handlers}
6533
6534If you set @code{handle pass} for a signal, and your program sets up a
6535handler for it, then issuing a stepping command, such as @code{step}
6536or @code{stepi}, when your program is stopped due to the signal will
6537step @emph{into} the signal handler (if the target supports that).
6538
6539Likewise, if you use the @code{queue-signal} command to queue a signal
6540to be delivered to the current thread when execution of the thread
6541resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6542stepping command will step into the signal handler.
6543
6544Here's an example, using @code{stepi} to step to the first instruction
6545of @code{SIGUSR1}'s handler:
6546
6547@smallexample
6548(@value{GDBP}) handle SIGUSR1
6549Signal Stop Print Pass to program Description
6550SIGUSR1 Yes Yes Yes User defined signal 1
6551(@value{GDBP}) c
6552Continuing.
6553
6554Program received signal SIGUSR1, User defined signal 1.
6555main () sigusr1.c:28
655628 p = 0;
6557(@value{GDBP}) si
6558sigusr1_handler () at sigusr1.c:9
65599 @{
6560@end smallexample
6561
6562The same, but using @code{queue-signal} instead of waiting for the
6563program to receive the signal first:
6564
6565@smallexample
6566(@value{GDBP}) n
656728 p = 0;
6568(@value{GDBP}) queue-signal SIGUSR1
6569(@value{GDBP}) si
6570sigusr1_handler () at sigusr1.c:9
65719 @{
6572(@value{GDBP})
6573@end smallexample
6574
4aa995e1
PA
6575@cindex extra signal information
6576@anchor{extra signal information}
6577
6578On some targets, @value{GDBN} can inspect extra signal information
6579associated with the intercepted signal, before it is actually
6580delivered to the program being debugged. This information is exported
6581by the convenience variable @code{$_siginfo}, and consists of data
6582that is passed by the kernel to the signal handler at the time of the
6583receipt of a signal. The data type of the information itself is
6584target dependent. You can see the data type using the @code{ptype
6585$_siginfo} command. On Unix systems, it typically corresponds to the
6586standard @code{siginfo_t} type, as defined in the @file{signal.h}
6587system header.
6588
6589Here's an example, on a @sc{gnu}/Linux system, printing the stray
6590referenced address that raised a segmentation fault.
6591
6592@smallexample
6593@group
6594(@value{GDBP}) continue
6595Program received signal SIGSEGV, Segmentation fault.
65960x0000000000400766 in main ()
659769 *(int *)p = 0;
6598(@value{GDBP}) ptype $_siginfo
6599type = struct @{
6600 int si_signo;
6601 int si_errno;
6602 int si_code;
6603 union @{
6604 int _pad[28];
6605 struct @{...@} _kill;
6606 struct @{...@} _timer;
6607 struct @{...@} _rt;
6608 struct @{...@} _sigchld;
6609 struct @{...@} _sigfault;
6610 struct @{...@} _sigpoll;
6611 @} _sifields;
6612@}
6613(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6614type = struct @{
6615 void *si_addr;
6616@}
6617(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6618$1 = (void *) 0x7ffff7ff7000
6619@end group
6620@end smallexample
6621
6622Depending on target support, @code{$_siginfo} may also be writable.
6623
012b3a21
WT
6624@cindex Intel MPX boundary violations
6625@cindex boundary violations, Intel MPX
6626On some targets, a @code{SIGSEGV} can be caused by a boundary
6627violation, i.e., accessing an address outside of the allowed range.
6628In those cases @value{GDBN} may displays additional information,
6629depending on how @value{GDBN} has been told to handle the signal.
6630With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6631kind: "Upper" or "Lower", the memory address accessed and the
6632bounds, while with @code{handle nostop SIGSEGV} no additional
6633information is displayed.
6634
6635The usual output of a segfault is:
6636@smallexample
6637Program received signal SIGSEGV, Segmentation fault
66380x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
663968 value = *(p + len);
6640@end smallexample
6641
6642While a bound violation is presented as:
6643@smallexample
6644Program received signal SIGSEGV, Segmentation fault
6645Upper bound violation while accessing address 0x7fffffffc3b3
6646Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
66470x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
664868 value = *(p + len);
6649@end smallexample
6650
6d2ebf8b 6651@node Thread Stops
79a6e687 6652@section Stopping and Starting Multi-thread Programs
c906108c 6653
0606b73b
SL
6654@cindex stopped threads
6655@cindex threads, stopped
6656
6657@cindex continuing threads
6658@cindex threads, continuing
6659
6660@value{GDBN} supports debugging programs with multiple threads
6661(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6662are two modes of controlling execution of your program within the
6663debugger. In the default mode, referred to as @dfn{all-stop mode},
6664when any thread in your program stops (for example, at a breakpoint
6665or while being stepped), all other threads in the program are also stopped by
6666@value{GDBN}. On some targets, @value{GDBN} also supports
6667@dfn{non-stop mode}, in which other threads can continue to run freely while
6668you examine the stopped thread in the debugger.
6669
6670@menu
6671* All-Stop Mode:: All threads stop when GDB takes control
6672* Non-Stop Mode:: Other threads continue to execute
6673* Background Execution:: Running your program asynchronously
6674* Thread-Specific Breakpoints:: Controlling breakpoints
6675* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6676* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6677@end menu
6678
6679@node All-Stop Mode
6680@subsection All-Stop Mode
6681
6682@cindex all-stop mode
6683
6684In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6685@emph{all} threads of execution stop, not just the current thread. This
6686allows you to examine the overall state of the program, including
6687switching between threads, without worrying that things may change
6688underfoot.
6689
6690Conversely, whenever you restart the program, @emph{all} threads start
6691executing. @emph{This is true even when single-stepping} with commands
6692like @code{step} or @code{next}.
6693
6694In particular, @value{GDBN} cannot single-step all threads in lockstep.
6695Since thread scheduling is up to your debugging target's operating
6696system (not controlled by @value{GDBN}), other threads may
6697execute more than one statement while the current thread completes a
6698single step. Moreover, in general other threads stop in the middle of a
6699statement, rather than at a clean statement boundary, when the program
6700stops.
6701
6702You might even find your program stopped in another thread after
6703continuing or even single-stepping. This happens whenever some other
6704thread runs into a breakpoint, a signal, or an exception before the
6705first thread completes whatever you requested.
6706
6707@cindex automatic thread selection
6708@cindex switching threads automatically
6709@cindex threads, automatic switching
6710Whenever @value{GDBN} stops your program, due to a breakpoint or a
6711signal, it automatically selects the thread where that breakpoint or
6712signal happened. @value{GDBN} alerts you to the context switch with a
6713message such as @samp{[Switching to Thread @var{n}]} to identify the
6714thread.
6715
6716On some OSes, you can modify @value{GDBN}'s default behavior by
6717locking the OS scheduler to allow only a single thread to run.
6718
6719@table @code
6720@item set scheduler-locking @var{mode}
6721@cindex scheduler locking mode
6722@cindex lock scheduler
f2665db5
MM
6723Set the scheduler locking mode. It applies to normal execution,
6724record mode, and replay mode. If it is @code{off}, then there is no
6725locking and any thread may run at any time. If @code{on}, then only
6726the current thread may run when the inferior is resumed. The
6727@code{step} mode optimizes for single-stepping; it prevents other
6728threads from preempting the current thread while you are stepping, so
6729that the focus of debugging does not change unexpectedly. Other
6730threads never get a chance to run when you step, and they are
6731completely free to run when you use commands like @samp{continue},
6732@samp{until}, or @samp{finish}. However, unless another thread hits a
6733breakpoint during its timeslice, @value{GDBN} does not change the
6734current thread away from the thread that you are debugging. The
6735@code{replay} mode behaves like @code{off} in record mode and like
6736@code{on} in replay mode.
0606b73b
SL
6737
6738@item show scheduler-locking
6739Display the current scheduler locking mode.
6740@end table
6741
d4db2f36
PA
6742@cindex resume threads of multiple processes simultaneously
6743By default, when you issue one of the execution commands such as
6744@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6745threads of the current inferior to run. For example, if @value{GDBN}
6746is attached to two inferiors, each with two threads, the
6747@code{continue} command resumes only the two threads of the current
6748inferior. This is useful, for example, when you debug a program that
6749forks and you want to hold the parent stopped (so that, for instance,
6750it doesn't run to exit), while you debug the child. In other
6751situations, you may not be interested in inspecting the current state
6752of any of the processes @value{GDBN} is attached to, and you may want
6753to resume them all until some breakpoint is hit. In the latter case,
6754you can instruct @value{GDBN} to allow all threads of all the
6755inferiors to run with the @w{@code{set schedule-multiple}} command.
6756
6757@table @code
6758@kindex set schedule-multiple
6759@item set schedule-multiple
6760Set the mode for allowing threads of multiple processes to be resumed
6761when an execution command is issued. When @code{on}, all threads of
6762all processes are allowed to run. When @code{off}, only the threads
6763of the current process are resumed. The default is @code{off}. The
6764@code{scheduler-locking} mode takes precedence when set to @code{on},
6765or while you are stepping and set to @code{step}.
6766
6767@item show schedule-multiple
6768Display the current mode for resuming the execution of threads of
6769multiple processes.
6770@end table
6771
0606b73b
SL
6772@node Non-Stop Mode
6773@subsection Non-Stop Mode
6774
6775@cindex non-stop mode
6776
6777@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6778@c with more details.
0606b73b
SL
6779
6780For some multi-threaded targets, @value{GDBN} supports an optional
6781mode of operation in which you can examine stopped program threads in
6782the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6783minimizes intrusion when debugging live systems, such as programs
6784where some threads have real-time constraints or must continue to
0606b73b
SL
6785respond to external events. This is referred to as @dfn{non-stop} mode.
6786
6787In non-stop mode, when a thread stops to report a debugging event,
6788@emph{only} that thread is stopped; @value{GDBN} does not stop other
6789threads as well, in contrast to the all-stop mode behavior. Additionally,
6790execution commands such as @code{continue} and @code{step} apply by default
6791only to the current thread in non-stop mode, rather than all threads as
6792in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6793ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6794one thread while allowing others to run freely, stepping
97d8f0ee 6795one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6796independently and simultaneously.
6797
6798To enter non-stop mode, use this sequence of commands before you run
6799or attach to your program:
6800
0606b73b 6801@smallexample
0606b73b
SL
6802# If using the CLI, pagination breaks non-stop.
6803set pagination off
6804
6805# Finally, turn it on!
6806set non-stop on
6807@end smallexample
6808
6809You can use these commands to manipulate the non-stop mode setting:
6810
6811@table @code
6812@kindex set non-stop
6813@item set non-stop on
6814Enable selection of non-stop mode.
6815@item set non-stop off
6816Disable selection of non-stop mode.
6817@kindex show non-stop
6818@item show non-stop
6819Show the current non-stop enablement setting.
6820@end table
6821
6822Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6823not whether the currently-executing program is being run in non-stop mode.
0606b73b 6824In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6825@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6826not possible to switch modes once debugging has started. Furthermore,
6827since not all targets support non-stop mode, even when you have enabled
6828non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6829default.
6830
6831In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6832by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6833To continue all threads, issue @code{continue -a} or @code{c -a}.
6834
97d8f0ee 6835You can use @value{GDBN}'s background execution commands
0606b73b 6836(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6837while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6838The MI execution commands (@pxref{GDB/MI Program Execution}) are
6839always executed asynchronously in non-stop mode.
6840
6841Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6842running in the background, or @kbd{Ctrl-c} during foreground execution.
6843In all-stop mode, this stops the whole process;
6844but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6845To stop the whole program, use @code{interrupt -a}.
6846
6847Other execution commands do not currently support the @code{-a} option.
6848
6849In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6850that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6851thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6852command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6853changed to a different thread just as you entered a command to operate on the
6854previously current thread.
6855
6856@node Background Execution
6857@subsection Background Execution
6858
6859@cindex foreground execution
6860@cindex background execution
6861@cindex asynchronous execution
6862@cindex execution, foreground, background and asynchronous
6863
6864@value{GDBN}'s execution commands have two variants: the normal
6865foreground (synchronous) behavior, and a background
97d8f0ee 6866(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6867the program to report that some thread has stopped before prompting for
6868another command. In background execution, @value{GDBN} immediately gives
6869a command prompt so that you can issue other commands while your program runs.
6870
32fc0df9
PA
6871If the target doesn't support async mode, @value{GDBN} issues an error
6872message if you attempt to use the background execution commands.
6873
74fdb8ff 6874@cindex @code{&}, background execution of commands
0606b73b
SL
6875To specify background execution, add a @code{&} to the command. For example,
6876the background form of the @code{continue} command is @code{continue&}, or
6877just @code{c&}. The execution commands that accept background execution
6878are:
6879
6880@table @code
6881@kindex run&
6882@item run
6883@xref{Starting, , Starting your Program}.
6884
6885@item attach
6886@kindex attach&
6887@xref{Attach, , Debugging an Already-running Process}.
6888
6889@item step
6890@kindex step&
6891@xref{Continuing and Stepping, step}.
6892
6893@item stepi
6894@kindex stepi&
6895@xref{Continuing and Stepping, stepi}.
6896
6897@item next
6898@kindex next&
6899@xref{Continuing and Stepping, next}.
6900
7ce58dd2
DE
6901@item nexti
6902@kindex nexti&
6903@xref{Continuing and Stepping, nexti}.
6904
0606b73b
SL
6905@item continue
6906@kindex continue&
6907@xref{Continuing and Stepping, continue}.
6908
6909@item finish
6910@kindex finish&
6911@xref{Continuing and Stepping, finish}.
6912
6913@item until
6914@kindex until&
6915@xref{Continuing and Stepping, until}.
6916
6917@end table
6918
6919Background execution is especially useful in conjunction with non-stop
6920mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6921However, you can also use these commands in the normal all-stop mode with
6922the restriction that you cannot issue another execution command until the
6923previous one finishes. Examples of commands that are valid in all-stop
6924mode while the program is running include @code{help} and @code{info break}.
6925
6926You can interrupt your program while it is running in the background by
6927using the @code{interrupt} command.
6928
6929@table @code
6930@kindex interrupt
6931@item interrupt
6932@itemx interrupt -a
6933
97d8f0ee 6934Suspend execution of the running program. In all-stop mode,
0606b73b 6935@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6936only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6937use @code{interrupt -a}.
6938@end table
6939
0606b73b
SL
6940@node Thread-Specific Breakpoints
6941@subsection Thread-Specific Breakpoints
6942
c906108c 6943When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6944Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6945breakpoints on all threads, or on a particular thread.
6946
6947@table @code
6948@cindex breakpoints and threads
6949@cindex thread breakpoints
5d5658a1
PA
6950@kindex break @dots{} thread @var{thread-id}
6951@item break @var{location} thread @var{thread-id}
6952@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6953@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6954writing them (@pxref{Specify Location}), but the effect is always to
6955specify some source line.
c906108c 6956
5d5658a1 6957Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6958to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6959particular thread reaches this breakpoint. The @var{thread-id} specifier
6960is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6961in the first column of the @samp{info threads} display.
c906108c 6962
5d5658a1 6963If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6964breakpoint, the breakpoint applies to @emph{all} threads of your
6965program.
6966
6967You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6968well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6969after the breakpoint condition, like this:
c906108c
SS
6970
6971@smallexample
2df3850c 6972(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6973@end smallexample
6974
6975@end table
6976
f4fb82a1
PA
6977Thread-specific breakpoints are automatically deleted when
6978@value{GDBN} detects the corresponding thread is no longer in the
6979thread list. For example:
6980
6981@smallexample
6982(@value{GDBP}) c
6983Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6984@end smallexample
6985
6986There are several ways for a thread to disappear, such as a regular
6987thread exit, but also when you detach from the process with the
6988@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6989Process}), or if @value{GDBN} loses the remote connection
6990(@pxref{Remote Debugging}), etc. Note that with some targets,
6991@value{GDBN} is only able to detect a thread has exited when the user
6992explictly asks for the thread list with the @code{info threads}
6993command.
6994
0606b73b
SL
6995@node Interrupted System Calls
6996@subsection Interrupted System Calls
c906108c 6997
36d86913
MC
6998@cindex thread breakpoints and system calls
6999@cindex system calls and thread breakpoints
7000@cindex premature return from system calls
0606b73b
SL
7001There is an unfortunate side effect when using @value{GDBN} to debug
7002multi-threaded programs. If one thread stops for a
36d86913
MC
7003breakpoint, or for some other reason, and another thread is blocked in a
7004system call, then the system call may return prematurely. This is a
7005consequence of the interaction between multiple threads and the signals
7006that @value{GDBN} uses to implement breakpoints and other events that
7007stop execution.
7008
7009To handle this problem, your program should check the return value of
7010each system call and react appropriately. This is good programming
7011style anyways.
7012
7013For example, do not write code like this:
7014
7015@smallexample
7016 sleep (10);
7017@end smallexample
7018
7019The call to @code{sleep} will return early if a different thread stops
7020at a breakpoint or for some other reason.
7021
7022Instead, write this:
7023
7024@smallexample
7025 int unslept = 10;
7026 while (unslept > 0)
7027 unslept = sleep (unslept);
7028@end smallexample
7029
7030A system call is allowed to return early, so the system is still
7031conforming to its specification. But @value{GDBN} does cause your
7032multi-threaded program to behave differently than it would without
7033@value{GDBN}.
7034
7035Also, @value{GDBN} uses internal breakpoints in the thread library to
7036monitor certain events such as thread creation and thread destruction.
7037When such an event happens, a system call in another thread may return
7038prematurely, even though your program does not appear to stop.
7039
d914c394
SS
7040@node Observer Mode
7041@subsection Observer Mode
7042
7043If you want to build on non-stop mode and observe program behavior
7044without any chance of disruption by @value{GDBN}, you can set
7045variables to disable all of the debugger's attempts to modify state,
7046whether by writing memory, inserting breakpoints, etc. These operate
7047at a low level, intercepting operations from all commands.
7048
7049When all of these are set to @code{off}, then @value{GDBN} is said to
7050be @dfn{observer mode}. As a convenience, the variable
7051@code{observer} can be set to disable these, plus enable non-stop
7052mode.
7053
7054Note that @value{GDBN} will not prevent you from making nonsensical
7055combinations of these settings. For instance, if you have enabled
7056@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7057then breakpoints that work by writing trap instructions into the code
7058stream will still not be able to be placed.
7059
7060@table @code
7061
7062@kindex observer
7063@item set observer on
7064@itemx set observer off
7065When set to @code{on}, this disables all the permission variables
7066below (except for @code{insert-fast-tracepoints}), plus enables
7067non-stop debugging. Setting this to @code{off} switches back to
7068normal debugging, though remaining in non-stop mode.
7069
7070@item show observer
7071Show whether observer mode is on or off.
7072
7073@kindex may-write-registers
7074@item set may-write-registers on
7075@itemx set may-write-registers off
7076This controls whether @value{GDBN} will attempt to alter the values of
7077registers, such as with assignment expressions in @code{print}, or the
7078@code{jump} command. It defaults to @code{on}.
7079
7080@item show may-write-registers
7081Show the current permission to write registers.
7082
7083@kindex may-write-memory
7084@item set may-write-memory on
7085@itemx set may-write-memory off
7086This controls whether @value{GDBN} will attempt to alter the contents
7087of memory, such as with assignment expressions in @code{print}. It
7088defaults to @code{on}.
7089
7090@item show may-write-memory
7091Show the current permission to write memory.
7092
7093@kindex may-insert-breakpoints
7094@item set may-insert-breakpoints on
7095@itemx set may-insert-breakpoints off
7096This controls whether @value{GDBN} will attempt to insert breakpoints.
7097This affects all breakpoints, including internal breakpoints defined
7098by @value{GDBN}. It defaults to @code{on}.
7099
7100@item show may-insert-breakpoints
7101Show the current permission to insert breakpoints.
7102
7103@kindex may-insert-tracepoints
7104@item set may-insert-tracepoints on
7105@itemx set may-insert-tracepoints off
7106This controls whether @value{GDBN} will attempt to insert (regular)
7107tracepoints at the beginning of a tracing experiment. It affects only
7108non-fast tracepoints, fast tracepoints being under the control of
7109@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7110
7111@item show may-insert-tracepoints
7112Show the current permission to insert tracepoints.
7113
7114@kindex may-insert-fast-tracepoints
7115@item set may-insert-fast-tracepoints on
7116@itemx set may-insert-fast-tracepoints off
7117This controls whether @value{GDBN} will attempt to insert fast
7118tracepoints at the beginning of a tracing experiment. It affects only
7119fast tracepoints, regular (non-fast) tracepoints being under the
7120control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7121
7122@item show may-insert-fast-tracepoints
7123Show the current permission to insert fast tracepoints.
7124
7125@kindex may-interrupt
7126@item set may-interrupt on
7127@itemx set may-interrupt off
7128This controls whether @value{GDBN} will attempt to interrupt or stop
7129program execution. When this variable is @code{off}, the
7130@code{interrupt} command will have no effect, nor will
7131@kbd{Ctrl-c}. It defaults to @code{on}.
7132
7133@item show may-interrupt
7134Show the current permission to interrupt or stop the program.
7135
7136@end table
c906108c 7137
bacec72f
MS
7138@node Reverse Execution
7139@chapter Running programs backward
7140@cindex reverse execution
7141@cindex running programs backward
7142
7143When you are debugging a program, it is not unusual to realize that
7144you have gone too far, and some event of interest has already happened.
7145If the target environment supports it, @value{GDBN} can allow you to
7146``rewind'' the program by running it backward.
7147
7148A target environment that supports reverse execution should be able
7149to ``undo'' the changes in machine state that have taken place as the
7150program was executing normally. Variables, registers etc.@: should
7151revert to their previous values. Obviously this requires a great
7152deal of sophistication on the part of the target environment; not
7153all target environments can support reverse execution.
7154
7155When a program is executed in reverse, the instructions that
7156have most recently been executed are ``un-executed'', in reverse
7157order. The program counter runs backward, following the previous
7158thread of execution in reverse. As each instruction is ``un-executed'',
7159the values of memory and/or registers that were changed by that
7160instruction are reverted to their previous states. After executing
7161a piece of source code in reverse, all side effects of that code
7162should be ``undone'', and all variables should be returned to their
7163prior values@footnote{
7164Note that some side effects are easier to undo than others. For instance,
7165memory and registers are relatively easy, but device I/O is hard. Some
7166targets may be able undo things like device I/O, and some may not.
7167
7168The contract between @value{GDBN} and the reverse executing target
7169requires only that the target do something reasonable when
7170@value{GDBN} tells it to execute backwards, and then report the
7171results back to @value{GDBN}. Whatever the target reports back to
7172@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7173assumes that the memory and registers that the target reports are in a
6b92c0d3 7174consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7175}.
7176
73f8a590
PA
7177On some platforms, @value{GDBN} has built-in support for reverse
7178execution, activated with the @code{record} or @code{record btrace}
7179commands. @xref{Process Record and Replay}. Some remote targets,
7180typically full system emulators, support reverse execution directly
7181without requiring any special command.
7182
bacec72f
MS
7183If you are debugging in a target environment that supports
7184reverse execution, @value{GDBN} provides the following commands.
7185
7186@table @code
7187@kindex reverse-continue
7188@kindex rc @r{(@code{reverse-continue})}
7189@item reverse-continue @r{[}@var{ignore-count}@r{]}
7190@itemx rc @r{[}@var{ignore-count}@r{]}
7191Beginning at the point where your program last stopped, start executing
7192in reverse. Reverse execution will stop for breakpoints and synchronous
7193exceptions (signals), just like normal execution. Behavior of
7194asynchronous signals depends on the target environment.
7195
7196@kindex reverse-step
7197@kindex rs @r{(@code{step})}
7198@item reverse-step @r{[}@var{count}@r{]}
7199Run the program backward until control reaches the start of a
7200different source line; then stop it, and return control to @value{GDBN}.
7201
7202Like the @code{step} command, @code{reverse-step} will only stop
7203at the beginning of a source line. It ``un-executes'' the previously
7204executed source line. If the previous source line included calls to
7205debuggable functions, @code{reverse-step} will step (backward) into
7206the called function, stopping at the beginning of the @emph{last}
7207statement in the called function (typically a return statement).
7208
7209Also, as with the @code{step} command, if non-debuggable functions are
7210called, @code{reverse-step} will run thru them backward without stopping.
7211
7212@kindex reverse-stepi
7213@kindex rsi @r{(@code{reverse-stepi})}
7214@item reverse-stepi @r{[}@var{count}@r{]}
7215Reverse-execute one machine instruction. Note that the instruction
7216to be reverse-executed is @emph{not} the one pointed to by the program
7217counter, but the instruction executed prior to that one. For instance,
7218if the last instruction was a jump, @code{reverse-stepi} will take you
7219back from the destination of the jump to the jump instruction itself.
7220
7221@kindex reverse-next
7222@kindex rn @r{(@code{reverse-next})}
7223@item reverse-next @r{[}@var{count}@r{]}
7224Run backward to the beginning of the previous line executed in
7225the current (innermost) stack frame. If the line contains function
7226calls, they will be ``un-executed'' without stopping. Starting from
7227the first line of a function, @code{reverse-next} will take you back
7228to the caller of that function, @emph{before} the function was called,
7229just as the normal @code{next} command would take you from the last
7230line of a function back to its return to its caller
16af530a 7231@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7232
7233@kindex reverse-nexti
7234@kindex rni @r{(@code{reverse-nexti})}
7235@item reverse-nexti @r{[}@var{count}@r{]}
7236Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7237in reverse, except that called functions are ``un-executed'' atomically.
7238That is, if the previously executed instruction was a return from
540aa8e7 7239another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7240in reverse until the call to that function (from the current stack
7241frame) is reached.
7242
7243@kindex reverse-finish
7244@item reverse-finish
7245Just as the @code{finish} command takes you to the point where the
7246current function returns, @code{reverse-finish} takes you to the point
7247where it was called. Instead of ending up at the end of the current
7248function invocation, you end up at the beginning.
7249
7250@kindex set exec-direction
7251@item set exec-direction
7252Set the direction of target execution.
984359d2 7253@item set exec-direction reverse
bacec72f
MS
7254@cindex execute forward or backward in time
7255@value{GDBN} will perform all execution commands in reverse, until the
7256exec-direction mode is changed to ``forward''. Affected commands include
7257@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7258command cannot be used in reverse mode.
7259@item set exec-direction forward
7260@value{GDBN} will perform all execution commands in the normal fashion.
7261This is the default.
7262@end table
7263
c906108c 7264
a2311334
EZ
7265@node Process Record and Replay
7266@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7267@cindex process record and replay
7268@cindex recording inferior's execution and replaying it
7269
8e05493c
EZ
7270On some platforms, @value{GDBN} provides a special @dfn{process record
7271and replay} target that can record a log of the process execution, and
7272replay it later with both forward and reverse execution commands.
a2311334
EZ
7273
7274@cindex replay mode
7275When this target is in use, if the execution log includes the record
7276for the next instruction, @value{GDBN} will debug in @dfn{replay
7277mode}. In the replay mode, the inferior does not really execute code
7278instructions. Instead, all the events that normally happen during
7279code execution are taken from the execution log. While code is not
7280really executed in replay mode, the values of registers (including the
7281program counter register) and the memory of the inferior are still
8e05493c
EZ
7282changed as they normally would. Their contents are taken from the
7283execution log.
a2311334
EZ
7284
7285@cindex record mode
7286If the record for the next instruction is not in the execution log,
7287@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7288inferior executes normally, and @value{GDBN} records the execution log
7289for future replay.
7290
8e05493c
EZ
7291The process record and replay target supports reverse execution
7292(@pxref{Reverse Execution}), even if the platform on which the
7293inferior runs does not. However, the reverse execution is limited in
7294this case by the range of the instructions recorded in the execution
7295log. In other words, reverse execution on platforms that don't
7296support it directly can only be done in the replay mode.
7297
7298When debugging in the reverse direction, @value{GDBN} will work in
7299replay mode as long as the execution log includes the record for the
7300previous instruction; otherwise, it will work in record mode, if the
7301platform supports reverse execution, or stop if not.
7302
73f8a590
PA
7303Currently, process record and replay is supported on ARM, Aarch64,
7304Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7305GNU/Linux. Process record and replay can be used both when native
7306debugging, and when remote debugging via @code{gdbserver}.
7307
a2311334
EZ
7308For architecture environments that support process record and replay,
7309@value{GDBN} provides the following commands:
53cc454a
HZ
7310
7311@table @code
7312@kindex target record
59ea5688
MM
7313@kindex target record-full
7314@kindex target record-btrace
53cc454a 7315@kindex record
59ea5688
MM
7316@kindex record full
7317@kindex record btrace
f4abbc16 7318@kindex record btrace bts
b20a6524 7319@kindex record btrace pt
f4abbc16 7320@kindex record bts
b20a6524 7321@kindex record pt
53cc454a 7322@kindex rec
59ea5688
MM
7323@kindex rec full
7324@kindex rec btrace
f4abbc16 7325@kindex rec btrace bts
b20a6524 7326@kindex rec btrace pt
f4abbc16 7327@kindex rec bts
b20a6524 7328@kindex rec pt
59ea5688
MM
7329@item record @var{method}
7330This command starts the process record and replay target. The
7331recording method can be specified as parameter. Without a parameter
7332the command uses the @code{full} recording method. The following
7333recording methods are available:
a2311334 7334
59ea5688
MM
7335@table @code
7336@item full
7337Full record/replay recording using @value{GDBN}'s software record and
7338replay implementation. This method allows replaying and reverse
7339execution.
7340
f4abbc16 7341@item btrace @var{format}
73f8a590
PA
7342Hardware-supported instruction recording, supported on Intel
7343processors. This method does not record data. Further, the data is
7344collected in a ring buffer so old data will be overwritten when the
7345buffer is full. It allows limited reverse execution. Variables and
7346registers are not available during reverse execution. In remote
7347debugging, recording continues on disconnect. Recorded data can be
7348inspected after reconnecting. The recording may be stopped using
7349@code{record stop}.
59ea5688 7350
f4abbc16
MM
7351The recording format can be specified as parameter. Without a parameter
7352the command chooses the recording format. The following recording
7353formats are available:
7354
7355@table @code
7356@item bts
7357@cindex branch trace store
7358Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7359this format, the processor stores a from/to record for each executed
7360branch in the btrace ring buffer.
b20a6524
MM
7361
7362@item pt
bc504a31
PA
7363@cindex Intel Processor Trace
7364Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7365format, the processor stores the execution trace in a compressed form
7366that is afterwards decoded by @value{GDBN}.
7367
7368The trace can be recorded with very low overhead. The compressed
7369trace format also allows small trace buffers to already contain a big
7370number of instructions compared to @acronym{BTS}.
7371
7372Decoding the recorded execution trace, on the other hand, is more
7373expensive than decoding @acronym{BTS} trace. This is mostly due to the
7374increased number of instructions to process. You should increase the
7375buffer-size with care.
f4abbc16
MM
7376@end table
7377
7378Not all recording formats may be available on all processors.
59ea5688
MM
7379@end table
7380
7381The process record and replay target can only debug a process that is
7382already running. Therefore, you need first to start the process with
7383the @kbd{run} or @kbd{start} commands, and then start the recording
7384with the @kbd{record @var{method}} command.
7385
a2311334
EZ
7386@cindex displaced stepping, and process record and replay
7387Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7388will be automatically disabled when process record and replay target
7389is started. That's because the process record and replay target
7390doesn't support displaced stepping.
7391
7392@cindex non-stop mode, and process record and replay
7393@cindex asynchronous execution, and process record and replay
7394If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7395the asynchronous execution mode (@pxref{Background Execution}), not
7396all recording methods are available. The @code{full} recording method
7397does not support these two modes.
53cc454a
HZ
7398
7399@kindex record stop
7400@kindex rec s
7401@item record stop
a2311334
EZ
7402Stop the process record and replay target. When process record and
7403replay target stops, the entire execution log will be deleted and the
7404inferior will either be terminated, or will remain in its final state.
53cc454a 7405
a2311334
EZ
7406When you stop the process record and replay target in record mode (at
7407the end of the execution log), the inferior will be stopped at the
7408next instruction that would have been recorded. In other words, if
7409you record for a while and then stop recording, the inferior process
7410will be left in the same state as if the recording never happened.
53cc454a 7411
a2311334
EZ
7412On the other hand, if the process record and replay target is stopped
7413while in replay mode (that is, not at the end of the execution log,
7414but at some earlier point), the inferior process will become ``live''
7415at that earlier state, and it will then be possible to continue the
7416usual ``live'' debugging of the process from that state.
53cc454a 7417
a2311334
EZ
7418When the inferior process exits, or @value{GDBN} detaches from it,
7419process record and replay target will automatically stop itself.
53cc454a 7420
742ce053
MM
7421@kindex record goto
7422@item record goto
7423Go to a specific location in the execution log. There are several
7424ways to specify the location to go to:
7425
7426@table @code
7427@item record goto begin
7428@itemx record goto start
7429Go to the beginning of the execution log.
7430
7431@item record goto end
7432Go to the end of the execution log.
7433
7434@item record goto @var{n}
7435Go to instruction number @var{n} in the execution log.
7436@end table
7437
24e933df
HZ
7438@kindex record save
7439@item record save @var{filename}
7440Save the execution log to a file @file{@var{filename}}.
7441Default filename is @file{gdb_record.@var{process_id}}, where
7442@var{process_id} is the process ID of the inferior.
7443
59ea5688
MM
7444This command may not be available for all recording methods.
7445
24e933df
HZ
7446@kindex record restore
7447@item record restore @var{filename}
7448Restore the execution log from a file @file{@var{filename}}.
7449File must have been created with @code{record save}.
7450
59ea5688
MM
7451@kindex set record full
7452@item set record full insn-number-max @var{limit}
f81d1120 7453@itemx set record full insn-number-max unlimited
59ea5688
MM
7454Set the limit of instructions to be recorded for the @code{full}
7455recording method. Default value is 200000.
53cc454a 7456
a2311334
EZ
7457If @var{limit} is a positive number, then @value{GDBN} will start
7458deleting instructions from the log once the number of the record
7459instructions becomes greater than @var{limit}. For every new recorded
7460instruction, @value{GDBN} will delete the earliest recorded
7461instruction to keep the number of recorded instructions at the limit.
7462(Since deleting recorded instructions loses information, @value{GDBN}
7463lets you control what happens when the limit is reached, by means of
7464the @code{stop-at-limit} option, described below.)
53cc454a 7465
f81d1120
PA
7466If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7467delete recorded instructions from the execution log. The number of
7468recorded instructions is limited only by the available memory.
53cc454a 7469
59ea5688
MM
7470@kindex show record full
7471@item show record full insn-number-max
7472Show the limit of instructions to be recorded with the @code{full}
7473recording method.
53cc454a 7474
59ea5688
MM
7475@item set record full stop-at-limit
7476Control the behavior of the @code{full} recording method when the
7477number of recorded instructions reaches the limit. If ON (the
7478default), @value{GDBN} will stop when the limit is reached for the
7479first time and ask you whether you want to stop the inferior or
7480continue running it and recording the execution log. If you decide
7481to continue recording, each new recorded instruction will cause the
7482oldest one to be deleted.
53cc454a 7483
a2311334
EZ
7484If this option is OFF, @value{GDBN} will automatically delete the
7485oldest record to make room for each new one, without asking.
53cc454a 7486
59ea5688 7487@item show record full stop-at-limit
a2311334 7488Show the current setting of @code{stop-at-limit}.
53cc454a 7489
59ea5688 7490@item set record full memory-query
bb08c432 7491Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7492changes caused by an instruction for the @code{full} recording method.
7493If ON, @value{GDBN} will query whether to stop the inferior in that
7494case.
bb08c432
HZ
7495
7496If this option is OFF (the default), @value{GDBN} will automatically
7497ignore the effect of such instructions on memory. Later, when
7498@value{GDBN} replays this execution log, it will mark the log of this
7499instruction as not accessible, and it will not affect the replay
7500results.
7501
59ea5688 7502@item show record full memory-query
bb08c432
HZ
7503Show the current setting of @code{memory-query}.
7504
67b5c0c1
MM
7505@kindex set record btrace
7506The @code{btrace} record target does not trace data. As a
7507convenience, when replaying, @value{GDBN} reads read-only memory off
7508the live program directly, assuming that the addresses of the
7509read-only areas don't change. This for example makes it possible to
7510disassemble code while replaying, but not to print variables.
7511In some cases, being able to inspect variables might be useful.
7512You can use the following command for that:
7513
7514@item set record btrace replay-memory-access
7515Control the behavior of the @code{btrace} recording method when
7516accessing memory during replay. If @code{read-only} (the default),
7517@value{GDBN} will only allow accesses to read-only memory.
7518If @code{read-write}, @value{GDBN} will allow accesses to read-only
7519and to read-write memory. Beware that the accessed memory corresponds
7520to the live target and not necessarily to the current replay
7521position.
7522
4a4495d6
MM
7523@item set record btrace cpu @var{identifier}
7524Set the processor to be used for enabling workarounds for processor
7525errata when decoding the trace.
7526
7527Processor errata are defects in processor operation, caused by its
7528design or manufacture. They can cause a trace not to match the
7529specification. This, in turn, may cause trace decode to fail.
7530@value{GDBN} can detect erroneous trace packets and correct them, thus
7531avoiding the decoding failures. These corrections are known as
7532@dfn{errata workarounds}, and are enabled based on the processor on
7533which the trace was recorded.
7534
7535By default, @value{GDBN} attempts to detect the processor
7536automatically, and apply the necessary workarounds for it. However,
7537you may need to specify the processor if @value{GDBN} does not yet
7538support it. This command allows you to do that, and also allows to
7539disable the workarounds.
7540
7541The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7542form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7543there are two special identifiers, @code{none} and @code{auto}
7544(default).
7545
7546The following vendor identifiers and corresponding processor
7547identifiers are currently supported:
7548
7549@multitable @columnfractions .1 .9
7550
7551@item @code{intel}
7552@tab @var{family}/@var{model}[/@var{stepping}]
7553
7554@end multitable
7555
7556On GNU/Linux systems, the processor @var{family}, @var{model}, and
7557@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7558
7559If @var{identifier} is @code{auto}, enable errata workarounds for the
7560processor on which the trace was recorded. If @var{identifier} is
7561@code{none}, errata workarounds are disabled.
7562
7563For example, when using an old @value{GDBN} on a new system, decode
7564may fail because @value{GDBN} does not support the new processor. It
7565often suffices to specify an older processor that @value{GDBN}
7566supports.
7567
7568@smallexample
7569(gdb) info record
7570Active record target: record-btrace
7571Recording format: Intel Processor Trace.
7572Buffer size: 16kB.
7573Failed to configure the Intel Processor Trace decoder: unknown cpu.
7574(gdb) set record btrace cpu intel:6/158
7575(gdb) info record
7576Active record target: record-btrace
7577Recording format: Intel Processor Trace.
7578Buffer size: 16kB.
7579Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7580@end smallexample
7581
67b5c0c1
MM
7582@kindex show record btrace
7583@item show record btrace replay-memory-access
7584Show the current setting of @code{replay-memory-access}.
7585
4a4495d6
MM
7586@item show record btrace cpu
7587Show the processor to be used for enabling trace decode errata
7588workarounds.
7589
d33501a5
MM
7590@kindex set record btrace bts
7591@item set record btrace bts buffer-size @var{size}
7592@itemx set record btrace bts buffer-size unlimited
7593Set the requested ring buffer size for branch tracing in @acronym{BTS}
7594format. Default is 64KB.
7595
7596If @var{size} is a positive number, then @value{GDBN} will try to
7597allocate a buffer of at least @var{size} bytes for each new thread
7598that uses the btrace recording method and the @acronym{BTS} format.
7599The actually obtained buffer size may differ from the requested
7600@var{size}. Use the @code{info record} command to see the actual
7601buffer size for each thread that uses the btrace recording method and
7602the @acronym{BTS} format.
7603
7604If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7605allocate a buffer of 4MB.
7606
7607Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7608also need longer to process the branch trace data before it can be used.
7609
7610@item show record btrace bts buffer-size @var{size}
7611Show the current setting of the requested ring buffer size for branch
7612tracing in @acronym{BTS} format.
7613
b20a6524
MM
7614@kindex set record btrace pt
7615@item set record btrace pt buffer-size @var{size}
7616@itemx set record btrace pt buffer-size unlimited
bc504a31 7617Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7618Processor Trace format. Default is 16KB.
7619
7620If @var{size} is a positive number, then @value{GDBN} will try to
7621allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7622that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7623format. The actually obtained buffer size may differ from the
7624requested @var{size}. Use the @code{info record} command to see the
7625actual buffer size for each thread.
7626
7627If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7628allocate a buffer of 4MB.
7629
7630Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7631also need longer to process the branch trace data before it can be used.
7632
7633@item show record btrace pt buffer-size @var{size}
7634Show the current setting of the requested ring buffer size for branch
bc504a31 7635tracing in Intel Processor Trace format.
b20a6524 7636
29153c24
MS
7637@kindex info record
7638@item info record
59ea5688
MM
7639Show various statistics about the recording depending on the recording
7640method:
7641
7642@table @code
7643@item full
7644For the @code{full} recording method, it shows the state of process
7645record and its in-memory execution log buffer, including:
29153c24
MS
7646
7647@itemize @bullet
7648@item
7649Whether in record mode or replay mode.
7650@item
7651Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7652@item
7653Highest recorded instruction number.
7654@item
7655Current instruction about to be replayed (if in replay mode).
7656@item
7657Number of instructions contained in the execution log.
7658@item
7659Maximum number of instructions that may be contained in the execution log.
7660@end itemize
53cc454a 7661
59ea5688 7662@item btrace
d33501a5
MM
7663For the @code{btrace} recording method, it shows:
7664
7665@itemize @bullet
7666@item
7667Recording format.
7668@item
7669Number of instructions that have been recorded.
7670@item
7671Number of blocks of sequential control-flow formed by the recorded
7672instructions.
7673@item
7674Whether in record mode or replay mode.
7675@end itemize
7676
7677For the @code{bts} recording format, it also shows:
7678@itemize @bullet
7679@item
7680Size of the perf ring buffer.
7681@end itemize
b20a6524
MM
7682
7683For the @code{pt} recording format, it also shows:
7684@itemize @bullet
7685@item
7686Size of the perf ring buffer.
7687@end itemize
59ea5688
MM
7688@end table
7689
53cc454a
HZ
7690@kindex record delete
7691@kindex rec del
7692@item record delete
a2311334 7693When record target runs in replay mode (``in the past''), delete the
53cc454a 7694subsequent execution log and begin to record a new execution log starting
a2311334 7695from the current address. This means you will abandon the previously
53cc454a 7696recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7697
7698@kindex record instruction-history
7699@kindex rec instruction-history
7700@item record instruction-history
7701Disassembles instructions from the recorded execution log. By
7702default, ten instructions are disassembled. This can be changed using
7703the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7704are printed in execution order.
7705
0c532a29
MM
7706It can also print mixed source+disassembly if you specify the the
7707@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7708as well as in symbolic form by specifying the @code{/r} modifier.
7709
7710The current position marker is printed for the instruction at the
7711current program counter value. This instruction can appear multiple
7712times in the trace and the current position marker will be printed
7713every time. To omit the current position marker, specify the
7714@code{/p} modifier.
7715
7716To better align the printed instructions when the trace contains
7717instructions from more than one function, the function name may be
7718omitted by specifying the @code{/f} modifier.
7719
da8c46d2
MM
7720Speculatively executed instructions are prefixed with @samp{?}. This
7721feature is not available for all recording formats.
7722
7723There are several ways to specify what part of the execution log to
7724disassemble:
59ea5688
MM
7725
7726@table @code
7727@item record instruction-history @var{insn}
7728Disassembles ten instructions starting from instruction number
7729@var{insn}.
7730
7731@item record instruction-history @var{insn}, +/-@var{n}
7732Disassembles @var{n} instructions around instruction number
7733@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7734@var{n} instructions after instruction number @var{insn}. If
7735@var{n} is preceded with @code{-}, disassembles @var{n}
7736instructions before instruction number @var{insn}.
7737
7738@item record instruction-history
7739Disassembles ten more instructions after the last disassembly.
7740
7741@item record instruction-history -
7742Disassembles ten more instructions before the last disassembly.
7743
792005b0 7744@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7745Disassembles instructions beginning with instruction number
7746@var{begin} until instruction number @var{end}. The instruction
0688d04e 7747number @var{end} is included.
59ea5688
MM
7748@end table
7749
7750This command may not be available for all recording methods.
7751
7752@kindex set record
f81d1120
PA
7753@item set record instruction-history-size @var{size}
7754@itemx set record instruction-history-size unlimited
59ea5688
MM
7755Define how many instructions to disassemble in the @code{record
7756instruction-history} command. The default value is 10.
f81d1120 7757A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7758
7759@kindex show record
7760@item show record instruction-history-size
7761Show how many instructions to disassemble in the @code{record
7762instruction-history} command.
7763
7764@kindex record function-call-history
7765@kindex rec function-call-history
7766@item record function-call-history
7767Prints the execution history at function granularity. It prints one
7768line for each sequence of instructions that belong to the same
7769function giving the name of that function, the source lines
7770for this instruction sequence (if the @code{/l} modifier is
7771specified), and the instructions numbers that form the sequence (if
8710b709
MM
7772the @code{/i} modifier is specified). The function names are indented
7773to reflect the call stack depth if the @code{/c} modifier is
7774specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7775given together.
59ea5688
MM
7776
7777@smallexample
7778(@value{GDBP}) @b{list 1, 10}
77791 void foo (void)
77802 @{
77813 @}
77824
77835 void bar (void)
77846 @{
77857 ...
77868 foo ();
77879 ...
778810 @}
8710b709
MM
7789(@value{GDBP}) @b{record function-call-history /ilc}
77901 bar inst 1,4 at foo.c:6,8
77912 foo inst 5,10 at foo.c:2,3
77923 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7793@end smallexample
7794
7795By default, ten lines are printed. This can be changed using the
7796@code{set record function-call-history-size} command. Functions are
7797printed in execution order. There are several ways to specify what
7798to print:
7799
7800@table @code
7801@item record function-call-history @var{func}
7802Prints ten functions starting from function number @var{func}.
7803
7804@item record function-call-history @var{func}, +/-@var{n}
7805Prints @var{n} functions around function number @var{func}. If
7806@var{n} is preceded with @code{+}, prints @var{n} functions after
7807function number @var{func}. If @var{n} is preceded with @code{-},
7808prints @var{n} functions before function number @var{func}.
7809
7810@item record function-call-history
7811Prints ten more functions after the last ten-line print.
7812
7813@item record function-call-history -
7814Prints ten more functions before the last ten-line print.
7815
792005b0 7816@item record function-call-history @var{begin}, @var{end}
59ea5688 7817Prints functions beginning with function number @var{begin} until
0688d04e 7818function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7819@end table
7820
7821This command may not be available for all recording methods.
7822
f81d1120
PA
7823@item set record function-call-history-size @var{size}
7824@itemx set record function-call-history-size unlimited
59ea5688
MM
7825Define how many lines to print in the
7826@code{record function-call-history} command. The default value is 10.
f81d1120 7827A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7828
7829@item show record function-call-history-size
7830Show how many lines to print in the
7831@code{record function-call-history} command.
53cc454a
HZ
7832@end table
7833
7834
6d2ebf8b 7835@node Stack
c906108c
SS
7836@chapter Examining the Stack
7837
7838When your program has stopped, the first thing you need to know is where it
7839stopped and how it got there.
7840
7841@cindex call stack
5d161b24
DB
7842Each time your program performs a function call, information about the call
7843is generated.
7844That information includes the location of the call in your program,
7845the arguments of the call,
c906108c 7846and the local variables of the function being called.
5d161b24 7847The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7848The stack frames are allocated in a region of memory called the @dfn{call
7849stack}.
7850
7851When your program stops, the @value{GDBN} commands for examining the
7852stack allow you to see all of this information.
7853
7854@cindex selected frame
7855One of the stack frames is @dfn{selected} by @value{GDBN} and many
7856@value{GDBN} commands refer implicitly to the selected frame. In
7857particular, whenever you ask @value{GDBN} for the value of a variable in
7858your program, the value is found in the selected frame. There are
7859special @value{GDBN} commands to select whichever frame you are
79a6e687 7860interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7861
7862When your program stops, @value{GDBN} automatically selects the
5d161b24 7863currently executing frame and describes it briefly, similar to the
79a6e687 7864@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7865
7866@menu
7867* Frames:: Stack frames
7868* Backtrace:: Backtraces
7869* Selection:: Selecting a frame
7870* Frame Info:: Information on a frame
0a232300 7871* Frame Apply:: Applying a command to several frames
0f59c28f 7872* Frame Filter Management:: Managing frame filters
c906108c
SS
7873
7874@end menu
7875
6d2ebf8b 7876@node Frames
79a6e687 7877@section Stack Frames
c906108c 7878
d4f3574e 7879@cindex frame, definition
c906108c
SS
7880@cindex stack frame
7881The call stack is divided up into contiguous pieces called @dfn{stack
7882frames}, or @dfn{frames} for short; each frame is the data associated
7883with one call to one function. The frame contains the arguments given
7884to the function, the function's local variables, and the address at
7885which the function is executing.
7886
7887@cindex initial frame
7888@cindex outermost frame
7889@cindex innermost frame
7890When your program is started, the stack has only one frame, that of the
7891function @code{main}. This is called the @dfn{initial} frame or the
7892@dfn{outermost} frame. Each time a function is called, a new frame is
7893made. Each time a function returns, the frame for that function invocation
7894is eliminated. If a function is recursive, there can be many frames for
7895the same function. The frame for the function in which execution is
7896actually occurring is called the @dfn{innermost} frame. This is the most
7897recently created of all the stack frames that still exist.
7898
7899@cindex frame pointer
7900Inside your program, stack frames are identified by their addresses. A
7901stack frame consists of many bytes, each of which has its own address; each
7902kind of computer has a convention for choosing one byte whose
7903address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7904in a register called the @dfn{frame pointer register}
7905(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7906
f67ffa6a 7907@cindex frame level
c906108c 7908@cindex frame number
f67ffa6a
AB
7909@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7910number that is zero for the innermost frame, one for the frame that
7911called it, and so on upward. These level numbers give you a way of
7912designating stack frames in @value{GDBN} commands. The terms
7913@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7914describe this number.
c906108c 7915
6d2ebf8b
SS
7916@c The -fomit-frame-pointer below perennially causes hbox overflow
7917@c underflow problems.
c906108c
SS
7918@cindex frameless execution
7919Some compilers provide a way to compile functions so that they operate
e22ea452 7920without stack frames. (For example, the @value{NGCC} option
474c8240 7921@smallexample
6d2ebf8b 7922@samp{-fomit-frame-pointer}
474c8240 7923@end smallexample
6d2ebf8b 7924generates functions without a frame.)
c906108c
SS
7925This is occasionally done with heavily used library functions to save
7926the frame setup time. @value{GDBN} has limited facilities for dealing
7927with these function invocations. If the innermost function invocation
7928has no stack frame, @value{GDBN} nevertheless regards it as though
7929it had a separate frame, which is numbered zero as usual, allowing
7930correct tracing of the function call chain. However, @value{GDBN} has
7931no provision for frameless functions elsewhere in the stack.
7932
6d2ebf8b 7933@node Backtrace
c906108c
SS
7934@section Backtraces
7935
09d4efe1
EZ
7936@cindex traceback
7937@cindex call stack traces
c906108c
SS
7938A backtrace is a summary of how your program got where it is. It shows one
7939line per frame, for many frames, starting with the currently executing
7940frame (frame zero), followed by its caller (frame one), and on up the
7941stack.
7942
1e611234 7943@anchor{backtrace-command}
c906108c 7944@kindex backtrace
41afff9a 7945@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
7946To print a backtrace of the entire stack, use the @code{backtrace}
7947command, or its alias @code{bt}. This command will print one line per
7948frame for frames in the stack. By default, all stack frames are
7949printed. You can stop the backtrace at any time by typing the system
7950interrupt character, normally @kbd{Ctrl-c}.
7951
7952@table @code
3345721a
PA
7953@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7954@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7955Print the backtrace of the entire stack.
7956
7957The optional @var{count} can be one of the following:
ea3b0687
TT
7958
7959@table @code
7960@item @var{n}
7961@itemx @var{n}
7962Print only the innermost @var{n} frames, where @var{n} is a positive
7963number.
7964
7965@item -@var{n}
7966@itemx -@var{n}
7967Print only the outermost @var{n} frames, where @var{n} is a positive
7968number.
3345721a 7969@end table
ea3b0687 7970
3345721a
PA
7971Options:
7972
7973@table @code
7974@item -full
ea3b0687 7975Print the values of the local variables also. This can be combined
3345721a 7976with the optional @var{count} to limit the number of frames shown.
ea3b0687 7977
3345721a 7978@item -no-filters
1e611234
PM
7979Do not run Python frame filters on this backtrace. @xref{Frame
7980Filter API}, for more information. Additionally use @ref{disable
7981frame-filter all} to turn off all frame filters. This is only
7982relevant when @value{GDBN} has been configured with @code{Python}
7983support.
978d6c75 7984
3345721a 7985@item -hide
978d6c75
TT
7986A Python frame filter might decide to ``elide'' some frames. Normally
7987such elided frames are still printed, but they are indented relative
3345721a 7988to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 7989option causes elided frames to not be printed at all.
c906108c 7990@end table
3345721a
PA
7991
7992The @code{backtrace} command also supports a number of options that
7993allow overriding relevant global print settings as set by @code{set
7994backtrace} and @code{set print} subcommands:
7995
7996@table @code
7997@item -past-main [@code{on}|@code{off}]
7998Set whether backtraces should continue past @code{main}. Related setting:
7999@ref{set backtrace past-main}.
8000
8001@item -past-entry [@code{on}|@code{off}]
8002Set whether backtraces should continue past the entry point of a program.
8003Related setting: @ref{set backtrace past-entry}.
8004
8005@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8006Set printing of function arguments at function entry.
8007Related setting: @ref{set print entry-values}.
8008
8009@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8010Set printing of non-scalar frame arguments.
8011Related setting: @ref{set print frame-arguments}.
8012
8013@item -raw-frame-arguments [@code{on}|@code{off}]
8014Set whether to print frame arguments in raw form.
8015Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
8016
8017@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8018Set printing of frame information.
8019Related setting: @ref{set print frame-info}.
3345721a
PA
8020@end table
8021
8022The optional @var{qualifier} is maintained for backward compatibility.
8023It can be one of the following:
8024
8025@table @code
8026@item full
8027Equivalent to the @code{-full} option.
8028
8029@item no-filters
8030Equivalent to the @code{-no-filters} option.
8031
8032@item hide
8033Equivalent to the @code{-hide} option.
8034@end table
8035
ea3b0687 8036@end table
c906108c
SS
8037
8038@kindex where
8039@kindex info stack
c906108c
SS
8040The names @code{where} and @code{info stack} (abbreviated @code{info s})
8041are additional aliases for @code{backtrace}.
8042
839c27b7
EZ
8043@cindex multiple threads, backtrace
8044In a multi-threaded program, @value{GDBN} by default shows the
8045backtrace only for the current thread. To display the backtrace for
8046several or all of the threads, use the command @code{thread apply}
8047(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8048apply all backtrace}, @value{GDBN} will display the backtrace for all
8049the threads; this is handy when you debug a core dump of a
8050multi-threaded program.
8051
c906108c
SS
8052Each line in the backtrace shows the frame number and the function name.
8053The program counter value is also shown---unless you use @code{set
8054print address off}. The backtrace also shows the source file name and
8055line number, as well as the arguments to the function. The program
8056counter value is omitted if it is at the beginning of the code for that
8057line number.
8058
8059Here is an example of a backtrace. It was made with the command
8060@samp{bt 3}, so it shows the innermost three frames.
8061
8062@smallexample
8063@group
5d161b24 8064#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 8065 at builtin.c:993
4f5376b2 8066#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
8067#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8068 at macro.c:71
8069(More stack frames follow...)
8070@end group
8071@end smallexample
8072
8073@noindent
8074The display for frame zero does not begin with a program counter
8075value, indicating that your program has stopped at the beginning of the
8076code for line @code{993} of @code{builtin.c}.
8077
4f5376b2
JB
8078@noindent
8079The value of parameter @code{data} in frame 1 has been replaced by
8080@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8081only if it is a scalar (integer, pointer, enumeration, etc). See command
8082@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8083on how to configure the way function parameter values are printed.
bc4268a5
PW
8084The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8085what frame information is printed.
4f5376b2 8086
585fdaa1 8087@cindex optimized out, in backtrace
18999be5
EZ
8088@cindex function call arguments, optimized out
8089If your program was compiled with optimizations, some compilers will
8090optimize away arguments passed to functions if those arguments are
8091never used after the call. Such optimizations generate code that
8092passes arguments through registers, but doesn't store those arguments
8093in the stack frame. @value{GDBN} has no way of displaying such
8094arguments in stack frames other than the innermost one. Here's what
8095such a backtrace might look like:
8096
8097@smallexample
8098@group
8099#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8100 at builtin.c:993
585fdaa1
PA
8101#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8102#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
8103 at macro.c:71
8104(More stack frames follow...)
8105@end group
8106@end smallexample
8107
8108@noindent
8109The values of arguments that were not saved in their stack frames are
585fdaa1 8110shown as @samp{<optimized out>}.
18999be5
EZ
8111
8112If you need to display the values of such optimized-out arguments,
8113either deduce that from other variables whose values depend on the one
8114you are interested in, or recompile without optimizations.
8115
a8f24a35
EZ
8116@cindex backtrace beyond @code{main} function
8117@cindex program entry point
8118@cindex startup code, and backtrace
25d29d70
AC
8119Most programs have a standard user entry point---a place where system
8120libraries and startup code transition into user code. For C this is
d416eeec
EZ
8121@code{main}@footnote{
8122Note that embedded programs (the so-called ``free-standing''
8123environment) are not required to have a @code{main} function as the
8124entry point. They could even have multiple entry points.}.
8125When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8126it will terminate the backtrace, to avoid tracing into highly
8127system-specific (and generally uninteresting) code.
8128
8129If you need to examine the startup code, or limit the number of levels
8130in a backtrace, you can change this behavior:
95f90d25
DJ
8131
8132@table @code
25d29d70
AC
8133@item set backtrace past-main
8134@itemx set backtrace past-main on
3345721a 8135@anchor{set backtrace past-main}
4644b6e3 8136@kindex set backtrace
25d29d70
AC
8137Backtraces will continue past the user entry point.
8138
8139@item set backtrace past-main off
95f90d25
DJ
8140Backtraces will stop when they encounter the user entry point. This is the
8141default.
8142
25d29d70 8143@item show backtrace past-main
4644b6e3 8144@kindex show backtrace
25d29d70
AC
8145Display the current user entry point backtrace policy.
8146
2315ffec
RC
8147@item set backtrace past-entry
8148@itemx set backtrace past-entry on
3345721a 8149@anchor{set backtrace past-entry}
a8f24a35 8150Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8151This entry point is encoded by the linker when the application is built,
8152and is likely before the user entry point @code{main} (or equivalent) is called.
8153
8154@item set backtrace past-entry off
d3e8051b 8155Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8156application. This is the default.
8157
8158@item show backtrace past-entry
8159Display the current internal entry point backtrace policy.
8160
25d29d70
AC
8161@item set backtrace limit @var{n}
8162@itemx set backtrace limit 0
f81d1120 8163@itemx set backtrace limit unlimited
3345721a 8164@anchor{set backtrace limit}
25d29d70 8165@cindex backtrace limit
f81d1120
PA
8166Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8167or zero means unlimited levels.
95f90d25 8168
25d29d70
AC
8169@item show backtrace limit
8170Display the current limit on backtrace levels.
95f90d25
DJ
8171@end table
8172
1b56eb55
JK
8173You can control how file names are displayed.
8174
8175@table @code
8176@item set filename-display
8177@itemx set filename-display relative
8178@cindex filename-display
8179Display file names relative to the compilation directory. This is the default.
8180
8181@item set filename-display basename
8182Display only basename of a filename.
8183
8184@item set filename-display absolute
8185Display an absolute filename.
8186
8187@item show filename-display
8188Show the current way to display filenames.
8189@end table
8190
6d2ebf8b 8191@node Selection
79a6e687 8192@section Selecting a Frame
c906108c
SS
8193
8194Most commands for examining the stack and other data in your program work on
8195whichever stack frame is selected at the moment. Here are the commands for
8196selecting a stack frame; all of them finish by printing a brief description
8197of the stack frame just selected.
8198
8199@table @code
d4f3574e 8200@kindex frame@r{, selecting}
41afff9a 8201@kindex f @r{(@code{frame})}
f67ffa6a
AB
8202@item frame @r{[} @var{frame-selection-spec} @r{]}
8203@item f @r{[} @var{frame-selection-spec} @r{]}
8204The @command{frame} command allows different stack frames to be
8205selected. The @var{frame-selection-spec} can be any of the following:
8206
8207@table @code
8208@kindex frame level
8209@item @var{num}
8210@item level @var{num}
8211Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8212(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8213innermost one, and so on. The highest level frame is usually the one
8214for @code{main}.
8215
8216As this is the most common method of navigating the frame stack, the
8217string @command{level} can be omitted. For example, the following two
8218commands are equivalent:
8219
8220@smallexample
8221(@value{GDBP}) frame 3
8222(@value{GDBP}) frame level 3
8223@end smallexample
8224
8225@kindex frame address
8226@item address @var{stack-address}
8227Select the frame with stack address @var{stack-address}. The
8228@var{stack-address} for a frame can be seen in the output of
8229@command{info frame}, for example:
8230
8231@smallexample
8232(gdb) info frame
8233Stack level 1, frame at 0x7fffffffda30:
8234 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8235 tail call frame, caller of frame at 0x7fffffffda30
8236 source language c++.
8237 Arglist at unknown address.
8238 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8239@end smallexample
8240
8241The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8242indicated by the line:
8243
8244@smallexample
8245Stack level 1, frame at 0x7fffffffda30:
8246@end smallexample
8247
8248@kindex frame function
8249@item function @var{function-name}
8250Select the stack frame for function @var{function-name}. If there are
8251multiple stack frames for function @var{function-name} then the inner
8252most stack frame is selected.
8253
8254@kindex frame view
8255@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8256View a frame that is not part of @value{GDBN}'s backtrace. The frame
8257viewed has stack address @var{stack-addr}, and optionally, a program
8258counter address of @var{pc-addr}.
8259
8260This is useful mainly if the chaining of stack frames has been
8261damaged by a bug, making it impossible for @value{GDBN} to assign
8262numbers properly to all frames. In addition, this can be useful
8263when your program has multiple stacks and switches between them.
8264
8265When viewing a frame outside the current backtrace using
8266@command{frame view} then you can always return to the original
8267stack using one of the previous stack frame selection instructions,
8268for example @command{frame level 0}.
8269
8270@end table
c906108c
SS
8271
8272@kindex up
8273@item up @var{n}
697aa1b7
EZ
8274Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8275numbers @var{n}, this advances toward the outermost frame, to higher
8276frame numbers, to frames that have existed longer.
c906108c
SS
8277
8278@kindex down
41afff9a 8279@kindex do @r{(@code{down})}
c906108c 8280@item down @var{n}
697aa1b7
EZ
8281Move @var{n} frames down the stack; @var{n} defaults to 1. For
8282positive numbers @var{n}, this advances toward the innermost frame, to
8283lower frame numbers, to frames that were created more recently.
8284You may abbreviate @code{down} as @code{do}.
c906108c
SS
8285@end table
8286
8287All of these commands end by printing two lines of output describing the
8288frame. The first line shows the frame number, the function name, the
8289arguments, and the source file and line number of execution in that
5d161b24 8290frame. The second line shows the text of that source line.
c906108c
SS
8291
8292@need 1000
8293For example:
8294
8295@smallexample
8296@group
8297(@value{GDBP}) up
8298#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8299 at env.c:10
830010 read_input_file (argv[i]);
8301@end group
8302@end smallexample
8303
8304After such a printout, the @code{list} command with no arguments
8305prints ten lines centered on the point of execution in the frame.
87885426
FN
8306You can also edit the program at the point of execution with your favorite
8307editing program by typing @code{edit}.
79a6e687 8308@xref{List, ,Printing Source Lines},
87885426 8309for details.
c906108c
SS
8310
8311@table @code
fc58fa65 8312@kindex select-frame
f67ffa6a 8313@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8314The @code{select-frame} command is a variant of @code{frame} that does
8315not display the new frame after selecting it. This command is
8316intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8317output might be unnecessary and distracting. The
8318@var{frame-selection-spec} is as for the @command{frame} command
8319described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8320
c906108c
SS
8321@kindex down-silently
8322@kindex up-silently
8323@item up-silently @var{n}
8324@itemx down-silently @var{n}
8325These two commands are variants of @code{up} and @code{down},
8326respectively; they differ in that they do their work silently, without
8327causing display of the new frame. They are intended primarily for use
8328in @value{GDBN} command scripts, where the output might be unnecessary and
8329distracting.
8330@end table
8331
6d2ebf8b 8332@node Frame Info
79a6e687 8333@section Information About a Frame
c906108c
SS
8334
8335There are several other commands to print information about the selected
8336stack frame.
8337
8338@table @code
8339@item frame
8340@itemx f
8341When used without any argument, this command does not change which
8342frame is selected, but prints a brief description of the currently
8343selected stack frame. It can be abbreviated @code{f}. With an
8344argument, this command is used to select a stack frame.
79a6e687 8345@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8346
8347@kindex info frame
41afff9a 8348@kindex info f @r{(@code{info frame})}
c906108c
SS
8349@item info frame
8350@itemx info f
8351This command prints a verbose description of the selected stack frame,
8352including:
8353
8354@itemize @bullet
5d161b24
DB
8355@item
8356the address of the frame
c906108c
SS
8357@item
8358the address of the next frame down (called by this frame)
8359@item
8360the address of the next frame up (caller of this frame)
8361@item
8362the language in which the source code corresponding to this frame is written
8363@item
8364the address of the frame's arguments
8365@item
d4f3574e
SS
8366the address of the frame's local variables
8367@item
c906108c
SS
8368the program counter saved in it (the address of execution in the caller frame)
8369@item
8370which registers were saved in the frame
8371@end itemize
8372
8373@noindent The verbose description is useful when
8374something has gone wrong that has made the stack format fail to fit
8375the usual conventions.
8376
f67ffa6a
AB
8377@item info frame @r{[} @var{frame-selection-spec} @r{]}
8378@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8379Print a verbose description of the frame selected by
8380@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8381same as for the @command{frame} command (@pxref{Selection, ,Selecting
8382a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8383
8384@kindex info args
d321477b 8385@item info args [-q]
c906108c
SS
8386Print the arguments of the selected frame, each on a separate line.
8387
d321477b
PW
8388The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8389printing header information and messages explaining why no argument
8390have been printed.
8391
8392@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8393Like @kbd{info args}, but only print the arguments selected
8394with the provided regexp(s).
8395
8396If @var{regexp} is provided, print only the arguments whose names
8397match the regular expression @var{regexp}.
8398
8399If @var{type_regexp} is provided, print only the arguments whose
8400types, as printed by the @code{whatis} command, match
8401the regular expression @var{type_regexp}.
8402If @var{type_regexp} contains space(s), it should be enclosed in
8403quote characters. If needed, use backslash to escape the meaning
8404of special characters or quotes.
8405
8406If both @var{regexp} and @var{type_regexp} are provided, an argument
8407is printed only if its name matches @var{regexp} and its type matches
8408@var{type_regexp}.
8409
8410@item info locals [-q]
c906108c
SS
8411@kindex info locals
8412Print the local variables of the selected frame, each on a separate
8413line. These are all variables (declared either static or automatic)
8414accessible at the point of execution of the selected frame.
8415
d321477b
PW
8416The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8417printing header information and messages explaining why no local variables
8418have been printed.
8419
8420@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8421Like @kbd{info locals}, but only print the local variables selected
8422with the provided regexp(s).
8423
8424If @var{regexp} is provided, print only the local variables whose names
8425match the regular expression @var{regexp}.
8426
8427If @var{type_regexp} is provided, print only the local variables whose
8428types, as printed by the @code{whatis} command, match
8429the regular expression @var{type_regexp}.
8430If @var{type_regexp} contains space(s), it should be enclosed in
8431quote characters. If needed, use backslash to escape the meaning
8432of special characters or quotes.
8433
8434If both @var{regexp} and @var{type_regexp} are provided, a local variable
8435is printed only if its name matches @var{regexp} and its type matches
8436@var{type_regexp}.
8437
8438The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8439combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8440For example, your program might use Resource Acquisition Is
8441Initialization types (RAII) such as @code{lock_something_t}: each
8442local variable of type @code{lock_something_t} automatically places a
8443lock that is destroyed when the variable goes out of scope. You can
8444then list all acquired locks in your program by doing
8445@smallexample
8446thread apply all -s frame apply all -s info locals -q -t lock_something_t
8447@end smallexample
8448@noindent
8449or the equivalent shorter form
8450@smallexample
8451tfaas i lo -q -t lock_something_t
8452@end smallexample
8453
c906108c
SS
8454@end table
8455
0a232300
PW
8456@node Frame Apply
8457@section Applying a Command to Several Frames.
8458@kindex frame apply
8459@cindex apply command to several frames
8460@table @code
3345721a 8461@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8462The @code{frame apply} command allows you to apply the named
8463@var{command} to one or more frames.
8464
8465@table @code
8466@item @code{all}
8467Specify @code{all} to apply @var{command} to all frames.
8468
8469@item @var{count}
8470Use @var{count} to apply @var{command} to the innermost @var{count}
8471frames, where @var{count} is a positive number.
8472
8473@item @var{-count}
8474Use @var{-count} to apply @var{command} to the outermost @var{count}
8475frames, where @var{count} is a positive number.
8476
8477@item @code{level}
8478Use @code{level} to apply @var{command} to the set of frames identified
8479by the @var{level} list. @var{level} is a frame level or a range of frame
8480levels as @var{level1}-@var{level2}. The frame level is the number shown
8481in the first field of the @samp{backtrace} command output.
8482E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8483at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8484
8485@end table
8486
0a232300
PW
8487Note that the frames on which @code{frame apply} applies a command are
8488also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8489backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8490@xref{Backtrace,,Backtraces}.
8491
3345721a
PA
8492The @code{frame apply} command also supports a number of options that
8493allow overriding relevant @code{set backtrace} settings:
8494
8495@table @code
8496@item -past-main [@code{on}|@code{off}]
8497Whether backtraces should continue past @code{main}.
8498Related setting: @ref{set backtrace past-main}.
8499
8500@item -past-entry [@code{on}|@code{off}]
8501Whether backtraces should continue past the entry point of a program.
8502Related setting: @ref{set backtrace past-entry}.
8503@end table
0a232300
PW
8504
8505By default, @value{GDBN} displays some frame information before the
8506output produced by @var{command}, and an error raised during the
8507execution of a @var{command} will abort @code{frame apply}. The
3345721a 8508following options can be used to fine-tune these behaviors:
0a232300
PW
8509
8510@table @code
8511@item -c
8512The flag @code{-c}, which stands for @samp{continue}, causes any
8513errors in @var{command} to be displayed, and the execution of
8514@code{frame apply} then continues.
8515@item -s
8516The flag @code{-s}, which stands for @samp{silent}, causes any errors
8517or empty output produced by a @var{command} to be silently ignored.
8518That is, the execution continues, but the frame information and errors
8519are not printed.
8520@item -q
8521The flag @code{-q} (@samp{quiet}) disables printing the frame
8522information.
8523@end table
8524
8525The following example shows how the flags @code{-c} and @code{-s} are
8526working when applying the command @code{p j} to all frames, where
8527variable @code{j} can only be successfully printed in the outermost
8528@code{#1 main} frame.
8529
8530@smallexample
8531@group
8532(gdb) frame apply all p j
8533#0 some_function (i=5) at fun.c:4
8534No symbol "j" in current context.
8535(gdb) frame apply all -c p j
8536#0 some_function (i=5) at fun.c:4
8537No symbol "j" in current context.
8538#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8539$1 = 5
8540(gdb) frame apply all -s p j
8541#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8542$2 = 5
8543(gdb)
8544@end group
8545@end smallexample
8546
8547By default, @samp{frame apply}, prints the frame location
8548information before the command output:
8549
8550@smallexample
8551@group
8552(gdb) frame apply all p $sp
8553#0 some_function (i=5) at fun.c:4
8554$4 = (void *) 0xffffd1e0
8555#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8556$5 = (void *) 0xffffd1f0
8557(gdb)
8558@end group
8559@end smallexample
8560
3345721a 8561If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8562@smallexample
8563@group
8564(gdb) frame apply all -q p $sp
8565$12 = (void *) 0xffffd1e0
8566$13 = (void *) 0xffffd1f0
8567(gdb)
8568@end group
8569@end smallexample
8570
3345721a
PA
8571@end table
8572
0a232300
PW
8573@table @code
8574
8575@kindex faas
8576@cindex apply a command to all frames (ignoring errors and empty output)
8577@item faas @var{command}
8578Shortcut for @code{frame apply all -s @var{command}}.
8579Applies @var{command} on all frames, ignoring errors and empty output.
8580
8581It can for example be used to print a local variable or a function
8582argument without knowing the frame where this variable or argument
8583is, using:
8584@smallexample
8585(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8586@end smallexample
8587
3345721a 8588The @code{faas} command accepts the same options as the @code{frame
ed788fee 8589apply} command. @xref{Frame Apply,,frame apply}.
3345721a 8590
0a232300
PW
8591Note that the command @code{tfaas @var{command}} applies @var{command}
8592on all frames of all threads. See @xref{Threads,,Threads}.
8593@end table
8594
8595
fc58fa65
AB
8596@node Frame Filter Management
8597@section Management of Frame Filters.
8598@cindex managing frame filters
8599
8600Frame filters are Python based utilities to manage and decorate the
8601output of frames. @xref{Frame Filter API}, for further information.
8602
8603Managing frame filters is performed by several commands available
8604within @value{GDBN}, detailed here.
8605
8606@table @code
8607@kindex info frame-filter
8608@item info frame-filter
8609Print a list of installed frame filters from all dictionaries, showing
8610their name, priority and enabled status.
8611
8612@kindex disable frame-filter
8613@anchor{disable frame-filter all}
8614@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8615Disable a frame filter in the dictionary matching
8616@var{filter-dictionary} and @var{filter-name}. The
8617@var{filter-dictionary} may be @code{all}, @code{global},
8618@code{progspace}, or the name of the object file where the frame filter
8619dictionary resides. When @code{all} is specified, all frame filters
8620across all dictionaries are disabled. The @var{filter-name} is the name
8621of the frame filter and is used when @code{all} is not the option for
8622@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8623may be enabled again later.
8624
8625@kindex enable frame-filter
8626@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8627Enable a frame filter in the dictionary matching
8628@var{filter-dictionary} and @var{filter-name}. The
8629@var{filter-dictionary} may be @code{all}, @code{global},
8630@code{progspace} or the name of the object file where the frame filter
8631dictionary resides. When @code{all} is specified, all frame filters across
8632all dictionaries are enabled. The @var{filter-name} is the name of the frame
8633filter and is used when @code{all} is not the option for
8634@var{filter-dictionary}.
8635
8636Example:
8637
8638@smallexample
8639(gdb) info frame-filter
8640
8641global frame-filters:
8642 Priority Enabled Name
8643 1000 No PrimaryFunctionFilter
8644 100 Yes Reverse
8645
8646progspace /build/test frame-filters:
8647 Priority Enabled Name
8648 100 Yes ProgspaceFilter
8649
8650objfile /build/test frame-filters:
8651 Priority Enabled Name
6b92c0d3 8652 999 Yes BuildProgramFilter
fc58fa65
AB
8653
8654(gdb) disable frame-filter /build/test BuildProgramFilter
8655(gdb) info frame-filter
8656
8657global frame-filters:
8658 Priority Enabled Name
8659 1000 No PrimaryFunctionFilter
8660 100 Yes Reverse
8661
8662progspace /build/test frame-filters:
8663 Priority Enabled Name
8664 100 Yes ProgspaceFilter
8665
8666objfile /build/test frame-filters:
8667 Priority Enabled Name
8668 999 No BuildProgramFilter
8669
8670(gdb) enable frame-filter global PrimaryFunctionFilter
8671(gdb) info frame-filter
8672
8673global frame-filters:
8674 Priority Enabled Name
8675 1000 Yes PrimaryFunctionFilter
8676 100 Yes Reverse
8677
8678progspace /build/test frame-filters:
8679 Priority Enabled Name
8680 100 Yes ProgspaceFilter
8681
8682objfile /build/test frame-filters:
8683 Priority Enabled Name
8684 999 No BuildProgramFilter
8685@end smallexample
8686
8687@kindex set frame-filter priority
8688@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8689Set the @var{priority} of a frame filter in the dictionary matching
8690@var{filter-dictionary}, and the frame filter name matching
8691@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8692@code{progspace} or the name of the object file where the frame filter
8693dictionary resides. The @var{priority} is an integer.
8694
8695@kindex show frame-filter priority
8696@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8697Show the @var{priority} of a frame filter in the dictionary matching
8698@var{filter-dictionary}, and the frame filter name matching
8699@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8700@code{progspace} or the name of the object file where the frame filter
8701dictionary resides.
8702
8703Example:
8704
8705@smallexample
8706(gdb) info frame-filter
8707
8708global frame-filters:
8709 Priority Enabled Name
8710 1000 Yes PrimaryFunctionFilter
8711 100 Yes Reverse
8712
8713progspace /build/test frame-filters:
8714 Priority Enabled Name
8715 100 Yes ProgspaceFilter
8716
8717objfile /build/test frame-filters:
8718 Priority Enabled Name
8719 999 No BuildProgramFilter
8720
8721(gdb) set frame-filter priority global Reverse 50
8722(gdb) info frame-filter
8723
8724global frame-filters:
8725 Priority Enabled Name
8726 1000 Yes PrimaryFunctionFilter
8727 50 Yes Reverse
8728
8729progspace /build/test frame-filters:
8730 Priority Enabled Name
8731 100 Yes ProgspaceFilter
8732
8733objfile /build/test frame-filters:
8734 Priority Enabled Name
8735 999 No BuildProgramFilter
8736@end smallexample
8737@end table
c906108c 8738
6d2ebf8b 8739@node Source
c906108c
SS
8740@chapter Examining Source Files
8741
8742@value{GDBN} can print parts of your program's source, since the debugging
8743information recorded in the program tells @value{GDBN} what source files were
8744used to build it. When your program stops, @value{GDBN} spontaneously prints
8745the line where it stopped. Likewise, when you select a stack frame
79a6e687 8746(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8747execution in that frame has stopped. You can print other portions of
8748source files by explicit command.
8749
7a292a7a 8750If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8751prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8752@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8753
8754@menu
8755* List:: Printing source lines
2a25a5ba 8756* Specify Location:: How to specify code locations
87885426 8757* Edit:: Editing source files
c906108c 8758* Search:: Searching source files
c906108c
SS
8759* Source Path:: Specifying source directories
8760* Machine Code:: Source and machine code
8761@end menu
8762
6d2ebf8b 8763@node List
79a6e687 8764@section Printing Source Lines
c906108c
SS
8765
8766@kindex list
41afff9a 8767@kindex l @r{(@code{list})}
c906108c 8768To print lines from a source file, use the @code{list} command
5d161b24 8769(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8770There are several ways to specify what part of the file you want to
8771print; see @ref{Specify Location}, for the full list.
c906108c
SS
8772
8773Here are the forms of the @code{list} command most commonly used:
8774
8775@table @code
8776@item list @var{linenum}
8777Print lines centered around line number @var{linenum} in the
8778current source file.
8779
8780@item list @var{function}
8781Print lines centered around the beginning of function
8782@var{function}.
8783
8784@item list
8785Print more lines. If the last lines printed were printed with a
8786@code{list} command, this prints lines following the last lines
8787printed; however, if the last line printed was a solitary line printed
8788as part of displaying a stack frame (@pxref{Stack, ,Examining the
8789Stack}), this prints lines centered around that line.
8790
8791@item list -
8792Print lines just before the lines last printed.
8793@end table
8794
9c16f35a 8795@cindex @code{list}, how many lines to display
c906108c
SS
8796By default, @value{GDBN} prints ten source lines with any of these forms of
8797the @code{list} command. You can change this using @code{set listsize}:
8798
8799@table @code
8800@kindex set listsize
8801@item set listsize @var{count}
f81d1120 8802@itemx set listsize unlimited
c906108c
SS
8803Make the @code{list} command display @var{count} source lines (unless
8804the @code{list} argument explicitly specifies some other number).
f81d1120 8805Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8806
8807@kindex show listsize
8808@item show listsize
8809Display the number of lines that @code{list} prints.
8810@end table
8811
8812Repeating a @code{list} command with @key{RET} discards the argument,
8813so it is equivalent to typing just @code{list}. This is more useful
8814than listing the same lines again. An exception is made for an
8815argument of @samp{-}; that argument is preserved in repetition so that
8816each repetition moves up in the source file.
8817
c906108c 8818In general, the @code{list} command expects you to supply zero, one or two
629500fa 8819@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8820of writing them (@pxref{Specify Location}), but the effect is always
8821to specify some source line.
8822
c906108c
SS
8823Here is a complete description of the possible arguments for @code{list}:
8824
8825@table @code
629500fa
KS
8826@item list @var{location}
8827Print lines centered around the line specified by @var{location}.
c906108c
SS
8828
8829@item list @var{first},@var{last}
8830Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8831locations. When a @code{list} command has two locations, and the
8832source file of the second location is omitted, this refers to
8833the same source file as the first location.
c906108c
SS
8834
8835@item list ,@var{last}
8836Print lines ending with @var{last}.
8837
8838@item list @var{first},
8839Print lines starting with @var{first}.
8840
8841@item list +
8842Print lines just after the lines last printed.
8843
8844@item list -
8845Print lines just before the lines last printed.
8846
8847@item list
8848As described in the preceding table.
8849@end table
8850
2a25a5ba
EZ
8851@node Specify Location
8852@section Specifying a Location
8853@cindex specifying location
629500fa
KS
8854@cindex location
8855@cindex source location
8856
8857@menu
8858* Linespec Locations:: Linespec locations
8859* Explicit Locations:: Explicit locations
8860* Address Locations:: Address locations
8861@end menu
c906108c 8862
2a25a5ba
EZ
8863Several @value{GDBN} commands accept arguments that specify a location
8864of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8865debugger, a location usually specifies some line in the source code.
8866Locations may be specified using three different formats:
8867linespec locations, explicit locations, or address locations.
c906108c 8868
629500fa
KS
8869@node Linespec Locations
8870@subsection Linespec Locations
8871@cindex linespec locations
8872
8873A @dfn{linespec} is a colon-separated list of source location parameters such
8874as file name, function name, etc. Here are all the different ways of
8875specifying a linespec:
c906108c 8876
2a25a5ba
EZ
8877@table @code
8878@item @var{linenum}
8879Specifies the line number @var{linenum} of the current source file.
c906108c 8880
2a25a5ba
EZ
8881@item -@var{offset}
8882@itemx +@var{offset}
8883Specifies the line @var{offset} lines before or after the @dfn{current
8884line}. For the @code{list} command, the current line is the last one
8885printed; for the breakpoint commands, this is the line at which
8886execution stopped in the currently selected @dfn{stack frame}
8887(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8888used as the second of the two linespecs in a @code{list} command,
8889this specifies the line @var{offset} lines up or down from the first
8890linespec.
8891
8892@item @var{filename}:@var{linenum}
8893Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8894If @var{filename} is a relative file name, then it will match any
8895source file name with the same trailing components. For example, if
8896@var{filename} is @samp{gcc/expr.c}, then it will match source file
8897name of @file{/build/trunk/gcc/expr.c}, but not
8898@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8899
8900@item @var{function}
8901Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8902For example, in C, this is the line with the open brace.
c906108c 8903
a20714ff
PA
8904By default, in C@t{++} and Ada, @var{function} is interpreted as
8905specifying all functions named @var{function} in all scopes. For
8906C@t{++}, this means in all namespaces and classes. For Ada, this
8907means in all packages.
8908
8909For example, assuming a program with C@t{++} symbols named
8910@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8911func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8912
8913Commands that accept a linespec let you override this with the
8914@code{-qualified} option. For example, @w{@kbd{break -qualified
8915func}} sets a breakpoint on a free-function named @code{func} ignoring
8916any C@t{++} class methods and namespace functions called @code{func}.
8917
8918@xref{Explicit Locations}.
8919
9ef07c8c
TT
8920@item @var{function}:@var{label}
8921Specifies the line where @var{label} appears in @var{function}.
8922
c906108c 8923@item @var{filename}:@var{function}
2a25a5ba
EZ
8924Specifies the line that begins the body of the function @var{function}
8925in the file @var{filename}. You only need the file name with a
8926function name to avoid ambiguity when there are identically named
8927functions in different source files.
c906108c 8928
0f5238ed 8929@item @var{label}
629500fa
KS
8930Specifies the line at which the label named @var{label} appears
8931in the function corresponding to the currently selected stack frame.
8932If there is no current selected stack frame (for instance, if the inferior
8933is not running), then @value{GDBN} will not search for a label.
8934
8935@cindex breakpoint at static probe point
8936@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8937The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8938applications to embed static probes. @xref{Static Probe Points}, for more
8939information on finding and using static probes. This form of linespec
8940specifies the location of such a static probe.
8941
8942If @var{objfile} is given, only probes coming from that shared library
8943or executable matching @var{objfile} as a regular expression are considered.
8944If @var{provider} is given, then only probes from that provider are considered.
8945If several probes match the spec, @value{GDBN} will insert a breakpoint at
8946each one of those probes.
8947@end table
8948
8949@node Explicit Locations
8950@subsection Explicit Locations
8951@cindex explicit locations
8952
8953@dfn{Explicit locations} allow the user to directly specify the source
8954location's parameters using option-value pairs.
8955
8956Explicit locations are useful when several functions, labels, or
8957file names have the same name (base name for files) in the program's
8958sources. In these cases, explicit locations point to the source
8959line you meant more accurately and unambiguously. Also, using
8960explicit locations might be faster in large programs.
8961
8962For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8963defined in the file named @file{foo} or the label @code{bar} in a function
8964named @code{foo}. @value{GDBN} must search either the file system or
8965the symbol table to know.
8966
8967The list of valid explicit location options is summarized in the
8968following table:
8969
8970@table @code
8971@item -source @var{filename}
8972The value specifies the source file name. To differentiate between
8973files with the same base name, prepend as many directories as is necessary
8974to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8975@value{GDBN} will use the first file it finds with the given base
8976name. This option requires the use of either @code{-function} or @code{-line}.
8977
8978@item -function @var{function}
8979The value specifies the name of a function. Operations
8980on function locations unmodified by other options (such as @code{-label}
8981or @code{-line}) refer to the line that begins the body of the function.
8982In C, for example, this is the line with the open brace.
8983
a20714ff
PA
8984By default, in C@t{++} and Ada, @var{function} is interpreted as
8985specifying all functions named @var{function} in all scopes. For
8986C@t{++}, this means in all namespaces and classes. For Ada, this
8987means in all packages.
8988
8989For example, assuming a program with C@t{++} symbols named
8990@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8991-function func}} and @w{@kbd{break -function B::func}} set a
8992breakpoint on both symbols.
8993
8994You can use the @kbd{-qualified} flag to override this (see below).
8995
8996@item -qualified
8997
8998This flag makes @value{GDBN} interpret a function name specified with
8999@kbd{-function} as a complete fully-qualified name.
9000
9001For example, assuming a C@t{++} program with symbols named
9002@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9003-function B::func}} command sets a breakpoint on @code{B::func}, only.
9004
9005(Note: the @kbd{-qualified} option can precede a linespec as well
9006(@pxref{Linespec Locations}), so the particular example above could be
9007simplified as @w{@kbd{break -qualified B::func}}.)
9008
629500fa
KS
9009@item -label @var{label}
9010The value specifies the name of a label. When the function
9011name is not specified, the label is searched in the function of the currently
9012selected stack frame.
9013
9014@item -line @var{number}
9015The value specifies a line offset for the location. The offset may either
9016be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9017the command. When specified without any other options, the line offset is
9018relative to the current line.
9019@end table
9020
9021Explicit location options may be abbreviated by omitting any non-unique
a20714ff 9022trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
9023
9024@node Address Locations
9025@subsection Address Locations
9026@cindex address locations
9027
9028@dfn{Address locations} indicate a specific program address. They have
9029the generalized form *@var{address}.
9030
9031For line-oriented commands, such as @code{list} and @code{edit}, this
9032specifies a source line that contains @var{address}. For @code{break} and
9033other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
9034parts of your program which do not have debugging information or
9035source files.
9036
9037Here @var{address} may be any expression valid in the current working
9038language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 9039address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
9040semantics of expressions used in locations to cover several situations
9041that frequently occur during debugging. Here are the various forms
5fa54e5d 9042of @var{address}:
2a25a5ba
EZ
9043
9044@table @code
9045@item @var{expression}
9046Any expression valid in the current working language.
9047
9048@item @var{funcaddr}
9049An address of a function or procedure derived from its name. In C,
9c37b5ae 9050C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
9051simply the function's name @var{function} (and actually a special case
9052of a valid expression). In Pascal and Modula-2, this is
9053@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9054(although the Pascal form also works).
9055
9056This form specifies the address of the function's first instruction,
9057before the stack frame and arguments have been set up.
9058
9a284c97 9059@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
9060Like @var{funcaddr} above, but also specifies the name of the source
9061file explicitly. This is useful if the name of the function does not
9062specify the function unambiguously, e.g., if there are several
9063functions with identical names in different source files.
c906108c
SS
9064@end table
9065
87885426 9066@node Edit
79a6e687 9067@section Editing Source Files
87885426
FN
9068@cindex editing source files
9069
9070@kindex edit
9071@kindex e @r{(@code{edit})}
9072To edit the lines in a source file, use the @code{edit} command.
9073The editing program of your choice
9074is invoked with the current line set to
9075the active line in the program.
9076Alternatively, there are several ways to specify what part of the file you
2a25a5ba 9077want to print if you want to see other parts of the program:
87885426
FN
9078
9079@table @code
2a25a5ba
EZ
9080@item edit @var{location}
9081Edit the source file specified by @code{location}. Editing starts at
9082that @var{location}, e.g., at the specified source line of the
9083specified file. @xref{Specify Location}, for all the possible forms
9084of the @var{location} argument; here are the forms of the @code{edit}
9085command most commonly used:
87885426 9086
2a25a5ba 9087@table @code
87885426
FN
9088@item edit @var{number}
9089Edit the current source file with @var{number} as the active line number.
9090
9091@item edit @var{function}
9092Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 9093@end table
87885426 9094
87885426
FN
9095@end table
9096
79a6e687 9097@subsection Choosing your Editor
87885426
FN
9098You can customize @value{GDBN} to use any editor you want
9099@footnote{
9100The only restriction is that your editor (say @code{ex}), recognizes the
9101following command-line syntax:
10998722 9102@smallexample
87885426 9103ex +@var{number} file
10998722 9104@end smallexample
15387254
EZ
9105The optional numeric value +@var{number} specifies the number of the line in
9106the file where to start editing.}.
9107By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
9108by setting the environment variable @code{EDITOR} before using
9109@value{GDBN}. For example, to configure @value{GDBN} to use the
9110@code{vi} editor, you could use these commands with the @code{sh} shell:
9111@smallexample
87885426
FN
9112EDITOR=/usr/bin/vi
9113export EDITOR
15387254 9114gdb @dots{}
10998722 9115@end smallexample
87885426 9116or in the @code{csh} shell,
10998722 9117@smallexample
87885426 9118setenv EDITOR /usr/bin/vi
15387254 9119gdb @dots{}
10998722 9120@end smallexample
87885426 9121
6d2ebf8b 9122@node Search
79a6e687 9123@section Searching Source Files
15387254 9124@cindex searching source files
c906108c
SS
9125
9126There are two commands for searching through the current source file for a
9127regular expression.
9128
9129@table @code
9130@kindex search
9131@kindex forward-search
1e96de83 9132@kindex fo @r{(@code{forward-search})}
c906108c
SS
9133@item forward-search @var{regexp}
9134@itemx search @var{regexp}
9135The command @samp{forward-search @var{regexp}} checks each line,
9136starting with the one following the last line listed, for a match for
5d161b24 9137@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9138synonym @samp{search @var{regexp}} or abbreviate the command name as
9139@code{fo}.
9140
09d4efe1 9141@kindex reverse-search
c906108c
SS
9142@item reverse-search @var{regexp}
9143The command @samp{reverse-search @var{regexp}} checks each line, starting
9144with the one before the last line listed and going backward, for a match
9145for @var{regexp}. It lists the line that is found. You can abbreviate
9146this command as @code{rev}.
9147@end table
c906108c 9148
6d2ebf8b 9149@node Source Path
79a6e687 9150@section Specifying Source Directories
c906108c
SS
9151
9152@cindex source path
9153@cindex directories for source files
9154Executable programs sometimes do not record the directories of the source
9155files from which they were compiled, just the names. Even when they do,
9156the directories could be moved between the compilation and your debugging
9157session. @value{GDBN} has a list of directories to search for source files;
9158this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9159it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9160in the list, until it finds a file with the desired name.
9161
9162For example, suppose an executable references the file
f1b620e9
MG
9163@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9164directory, and the @dfn{source path} is @file{/mnt/cross}.
9165@value{GDBN} would look for the source file in the following
9166locations:
9167
9168@enumerate
9169
9170@item @file{/usr/src/foo-1.0/lib/foo.c}
9171@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9172@item @file{/mnt/cross/foo.c}
9173
9174@end enumerate
9175
9176If the source file is not present at any of the above locations then
9177an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9178source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9179Likewise, the subdirectories of the source path are not searched: if
9180the source path is @file{/mnt/cross}, and the binary refers to
9181@file{foo.c}, @value{GDBN} would not find it under
9182@file{/mnt/cross/usr/src/foo-1.0/lib}.
9183
9184Plain file names, relative file names with leading directories, file
f1b620e9
MG
9185names containing dots, etc.@: are all treated as described above,
9186except that non-absolute file names are not looked up literally. If
9187the @dfn{source path} is @file{/mnt/cross}, the source file is
9188recorded as @file{../lib/foo.c}, and no compilation directory is
9189recorded, then @value{GDBN} will search in the following locations:
9190
9191@enumerate
9192
9193@item @file{/mnt/cross/../lib/foo.c}
9194@item @file{/mnt/cross/foo.c}
9195
9196@end enumerate
9197
9198@kindex cdir
9199@kindex cwd
9200@vindex $cdir@r{, convenience variable}
9201@vindex $cwd@r{, convenience variable}
9202@cindex compilation directory
9203@cindex current directory
9204@cindex working directory
9205@cindex directory, current
9206@cindex directory, compilation
9207The @dfn{source path} will always include two special entries
9208@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9209(if one is recorded) and the current working directory respectively.
9210
9211@samp{$cdir} causes @value{GDBN} to search within the compilation
9212directory, if one is recorded in the debug information. If no
9213compilation directory is recorded in the debug information then
9214@samp{$cdir} is ignored.
9215
9216@samp{$cwd} is not the same as @samp{.}---the former tracks the
9217current working directory as it changes during your @value{GDBN}
9218session, while the latter is immediately expanded to the current
9219directory at the time you add an entry to the source path.
9220
9221If a compilation directory is recorded in the debug information, and
9222@value{GDBN} has not found the source file after the first search
9223using @dfn{source path}, then @value{GDBN} will combine the
9224compilation directory and the filename, and then search for the source
9225file again using the @dfn{source path}.
9226
9227For example, if the executable records the source file as
9228@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9229recorded as @file{/project/build}, and the @dfn{source path} is
9230@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9231the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9232search for the source file in the following locations:
f1b620e9
MG
9233
9234@enumerate
9235
9236@item @file{/usr/src/foo-1.0/lib/foo.c}
9237@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9238@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9239@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9240@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9241@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9242@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9243@item @file{/mnt/cross/foo.c}
9244@item @file{/project/build/foo.c}
9245@item @file{/home/user/foo.c}
9246
9247@end enumerate
9248
9249If the file name in the previous example had been recorded in the
9250executable as a relative path rather than an absolute path, then the
9251first look up would not have occurred, but all of the remaining steps
9252would be similar.
9253
9254When searching for source files on MS-DOS and MS-Windows, where
9255absolute paths start with a drive letter (e.g.
9256@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9257from the file name before appending it to a search directory from
9258@dfn{source path}; for instance if the executable references the
9259source file @file{C:/project/foo.c} and @dfn{source path} is set to
9260@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9261locations for the source file:
9262
9263@enumerate
9264
9265@item @file{C:/project/foo.c}
9266@item @file{D:/mnt/cross/project/foo.c}
9267@item @file{D:/mnt/cross/foo.c}
9268
9269@end enumerate
0b66e38c
EZ
9270
9271Note that the executable search path is @emph{not} used to locate the
cd852561 9272source files.
c906108c
SS
9273
9274Whenever you reset or rearrange the source path, @value{GDBN} clears out
9275any information it has cached about where source files are found and where
9276each line is in the file.
9277
9278@kindex directory
9279@kindex dir
f1b620e9
MG
9280When you start @value{GDBN}, its source path includes only @samp{$cdir}
9281and @samp{$cwd}, in that order.
c906108c
SS
9282To add other directories, use the @code{directory} command.
9283
4b505b12
AS
9284The search path is used to find both program source files and @value{GDBN}
9285script files (read using the @samp{-command} option and @samp{source} command).
9286
30daae6c
JB
9287In addition to the source path, @value{GDBN} provides a set of commands
9288that manage a list of source path substitution rules. A @dfn{substitution
9289rule} specifies how to rewrite source directories stored in the program's
9290debug information in case the sources were moved to a different
9291directory between compilation and debugging. A rule is made of
9292two strings, the first specifying what needs to be rewritten in
9293the path, and the second specifying how it should be rewritten.
9294In @ref{set substitute-path}, we name these two parts @var{from} and
9295@var{to} respectively. @value{GDBN} does a simple string replacement
9296of @var{from} with @var{to} at the start of the directory part of the
9297source file name, and uses that result instead of the original file
9298name to look up the sources.
9299
9300Using the previous example, suppose the @file{foo-1.0} tree has been
9301moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9302@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9303@file{/mnt/cross}. The first lookup will then be
9304@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9305of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9306substitution rule, use the @code{set substitute-path} command
9307(@pxref{set substitute-path}).
9308
9309To avoid unexpected substitution results, a rule is applied only if the
9310@var{from} part of the directory name ends at a directory separator.
9311For instance, a rule substituting @file{/usr/source} into
9312@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9313not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9314is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9315not be applied to @file{/root/usr/source/baz.c} either.
9316
9317In many cases, you can achieve the same result using the @code{directory}
9318command. However, @code{set substitute-path} can be more efficient in
9319the case where the sources are organized in a complex tree with multiple
9320subdirectories. With the @code{directory} command, you need to add each
9321subdirectory of your project. If you moved the entire tree while
9322preserving its internal organization, then @code{set substitute-path}
9323allows you to direct the debugger to all the sources with one single
9324command.
9325
9326@code{set substitute-path} is also more than just a shortcut command.
9327The source path is only used if the file at the original location no
9328longer exists. On the other hand, @code{set substitute-path} modifies
9329the debugger behavior to look at the rewritten location instead. So, if
9330for any reason a source file that is not relevant to your executable is
9331located at the original location, a substitution rule is the only
3f94c067 9332method available to point @value{GDBN} at the new location.
30daae6c 9333
29b0e8a2
JM
9334@cindex @samp{--with-relocated-sources}
9335@cindex default source path substitution
9336You can configure a default source path substitution rule by
9337configuring @value{GDBN} with the
9338@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9339should be the name of a directory under @value{GDBN}'s configured
9340prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9341directory names in debug information under @var{dir} will be adjusted
9342automatically if the installed @value{GDBN} is moved to a new
9343location. This is useful if @value{GDBN}, libraries or executables
9344with debug information and corresponding source code are being moved
9345together.
9346
c906108c
SS
9347@table @code
9348@item directory @var{dirname} @dots{}
9349@item dir @var{dirname} @dots{}
9350Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9351directory names may be given to this command, separated by @samp{:}
9352(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9353part of absolute file names) or
c906108c
SS
9354whitespace. You may specify a directory that is already in the source
9355path; this moves it forward, so @value{GDBN} searches it sooner.
9356
f1b620e9
MG
9357The special strings @samp{$cdir} (to refer to the compilation
9358directory, if one is recorded), and @samp{$cwd} (to refer to the
9359current working directory) can also be included in the list of
9360directories @var{dirname}. Though these will already be in the source
9361path they will be moved forward in the list so @value{GDBN} searches
9362them sooner.
c906108c
SS
9363
9364@item directory
cd852561 9365Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9366
9367@c RET-repeat for @code{directory} is explicitly disabled, but since
9368@c repeating it would be a no-op we do not say that. (thanks to RMS)
9369
99e7ae30
DE
9370@item set directories @var{path-list}
9371@kindex set directories
9372Set the source path to @var{path-list}.
9373@samp{$cdir:$cwd} are added if missing.
9374
c906108c
SS
9375@item show directories
9376@kindex show directories
9377Print the source path: show which directories it contains.
30daae6c
JB
9378
9379@anchor{set substitute-path}
9380@item set substitute-path @var{from} @var{to}
9381@kindex set substitute-path
9382Define a source path substitution rule, and add it at the end of the
9383current list of existing substitution rules. If a rule with the same
9384@var{from} was already defined, then the old rule is also deleted.
9385
9386For example, if the file @file{/foo/bar/baz.c} was moved to
9387@file{/mnt/cross/baz.c}, then the command
9388
9389@smallexample
c58b006b 9390(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9391@end smallexample
9392
9393@noindent
c58b006b 9394will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9395@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9396@file{baz.c} even though it was moved.
9397
9398In the case when more than one substitution rule have been defined,
9399the rules are evaluated one by one in the order where they have been
9400defined. The first one matching, if any, is selected to perform
9401the substitution.
9402
9403For instance, if we had entered the following commands:
9404
9405@smallexample
9406(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9407(@value{GDBP}) set substitute-path /usr/src /mnt/src
9408@end smallexample
9409
9410@noindent
9411@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9412@file{/mnt/include/defs.h} by using the first rule. However, it would
9413use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9414@file{/mnt/src/lib/foo.c}.
9415
9416
9417@item unset substitute-path [path]
9418@kindex unset substitute-path
9419If a path is specified, search the current list of substitution rules
9420for a rule that would rewrite that path. Delete that rule if found.
9421A warning is emitted by the debugger if no rule could be found.
9422
9423If no path is specified, then all substitution rules are deleted.
9424
9425@item show substitute-path [path]
9426@kindex show substitute-path
9427If a path is specified, then print the source path substitution rule
9428which would rewrite that path, if any.
9429
9430If no path is specified, then print all existing source path substitution
9431rules.
9432
c906108c
SS
9433@end table
9434
9435If your source path is cluttered with directories that are no longer of
9436interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9437versions of source. You can correct the situation as follows:
9438
9439@enumerate
9440@item
cd852561 9441Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9442
9443@item
9444Use @code{directory} with suitable arguments to reinstall the
9445directories you want in the source path. You can add all the
9446directories in one command.
9447@end enumerate
9448
6d2ebf8b 9449@node Machine Code
79a6e687 9450@section Source and Machine Code
15387254 9451@cindex source line and its code address
c906108c
SS
9452
9453You can use the command @code{info line} to map source lines to program
9454addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9455a range of addresses as machine instructions. You can use the command
9456@code{set disassemble-next-line} to set whether to disassemble next
9457source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9458mode, the @code{info line} command causes the arrow to point to the
5d161b24 9459line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9460well as hex.
9461
9462@table @code
9463@kindex info line
db1ae9c5
AB
9464@item info line
9465@itemx info line @var{location}
c906108c 9466Print the starting and ending addresses of the compiled code for
629500fa 9467source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9468the ways documented in @ref{Specify Location}. With no @var{location}
9469information about the current source line is printed.
c906108c
SS
9470@end table
9471
9472For example, we can use @code{info line} to discover the location of
9473the object code for the first line of function
9474@code{m4_changequote}:
9475
9476@smallexample
96a2c332 9477(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9478Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9479 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9480@end smallexample
9481
9482@noindent
15387254 9483@cindex code address and its source line
c906108c 9484We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9485@var{location}) what source line covers a particular address:
c906108c
SS
9486@smallexample
9487(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9488Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9489 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9490@end smallexample
9491
9492@cindex @code{$_} and @code{info line}
15387254 9493@cindex @code{x} command, default address
41afff9a 9494@kindex x@r{(examine), and} info line
c906108c
SS
9495After @code{info line}, the default address for the @code{x} command
9496is changed to the starting address of the line, so that @samp{x/i} is
9497sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9498,Examining Memory}). Also, this address is saved as the value of the
c906108c 9499convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9500Variables}).
c906108c 9501
db1ae9c5
AB
9502@cindex info line, repeated calls
9503After @code{info line}, using @code{info line} again without
9504specifying a location will display information about the next source
9505line.
9506
c906108c
SS
9507@table @code
9508@kindex disassemble
9509@cindex assembly instructions
9510@cindex instructions, assembly
9511@cindex machine instructions
9512@cindex listing machine instructions
9513@item disassemble
d14508fe 9514@itemx disassemble /m
6ff0ba5f 9515@itemx disassemble /s
9b117ef3 9516@itemx disassemble /r
c906108c 9517This specialized command dumps a range of memory as machine
d14508fe 9518instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9519the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9520as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9521The default memory range is the function surrounding the
c906108c
SS
9522program counter of the selected frame. A single argument to this
9523command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9524surrounding this value. When two arguments are given, they should
9525be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9526arguments specify a range of addresses to dump, in one of two forms:
9527
9528@table @code
9529@item @var{start},@var{end}
9530the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9531@item @var{start},+@var{length}
9532the addresses from @var{start} (inclusive) to
9533@code{@var{start}+@var{length}} (exclusive).
9534@end table
9535
9536@noindent
9537When 2 arguments are specified, the name of the function is also
9538printed (since there could be several functions in the given range).
21a0512e
PP
9539
9540The argument(s) can be any expression yielding a numeric value, such as
9541@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9542
9543If the range of memory being disassembled contains current program counter,
9544the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9545@end table
9546
c906108c
SS
9547The following example shows the disassembly of a range of addresses of
9548HP PA-RISC 2.0 code:
9549
9550@smallexample
21a0512e 9551(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9552Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9553 0x32c4 <main+204>: addil 0,dp
9554 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9555 0x32cc <main+212>: ldil 0x3000,r31
9556 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9557 0x32d4 <main+220>: ldo 0(r31),rp
9558 0x32d8 <main+224>: addil -0x800,dp
9559 0x32dc <main+228>: ldo 0x588(r1),r26
9560 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9561End of assembler dump.
9562@end smallexample
c906108c 9563
6ff0ba5f
DE
9564Here is an example showing mixed source+assembly for Intel x86
9565with @code{/m} or @code{/s}, when the program is stopped just after
9566function prologue in a non-optimized function with no inline code.
d14508fe
DE
9567
9568@smallexample
9569(@value{GDBP}) disas /m main
9570Dump of assembler code for function main:
95715 @{
9c419145
PP
9572 0x08048330 <+0>: push %ebp
9573 0x08048331 <+1>: mov %esp,%ebp
9574 0x08048333 <+3>: sub $0x8,%esp
9575 0x08048336 <+6>: and $0xfffffff0,%esp
9576 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9577
95786 printf ("Hello.\n");
9c419145
PP
9579=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9580 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9581
95827 return 0;
95838 @}
9c419145
PP
9584 0x08048348 <+24>: mov $0x0,%eax
9585 0x0804834d <+29>: leave
9586 0x0804834e <+30>: ret
d14508fe
DE
9587
9588End of assembler dump.
9589@end smallexample
9590
6ff0ba5f
DE
9591The @code{/m} option is deprecated as its output is not useful when
9592there is either inlined code or re-ordered code.
9593The @code{/s} option is the preferred choice.
9594Here is an example for AMD x86-64 showing the difference between
9595@code{/m} output and @code{/s} output.
9596This example has one inline function defined in a header file,
9597and the code is compiled with @samp{-O2} optimization.
9598Note how the @code{/m} output is missing the disassembly of
9599several instructions that are present in the @code{/s} output.
9600
9601@file{foo.h}:
9602
9603@smallexample
9604int
9605foo (int a)
9606@{
9607 if (a < 0)
9608 return a * 2;
9609 if (a == 0)
9610 return 1;
9611 return a + 10;
9612@}
9613@end smallexample
9614
9615@file{foo.c}:
9616
9617@smallexample
9618#include "foo.h"
9619volatile int x, y;
9620int
9621main ()
9622@{
9623 x = foo (y);
9624 return 0;
9625@}
9626@end smallexample
9627
9628@smallexample
9629(@value{GDBP}) disas /m main
9630Dump of assembler code for function main:
96315 @{
9632
96336 x = foo (y);
9634 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9635 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9636
96377 return 0;
96388 @}
9639 0x000000000040041d <+29>: xor %eax,%eax
9640 0x000000000040041f <+31>: retq
9641 0x0000000000400420 <+32>: add %eax,%eax
9642 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9643
9644End of assembler dump.
9645(@value{GDBP}) disas /s main
9646Dump of assembler code for function main:
9647foo.c:
96485 @{
96496 x = foo (y);
9650 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9651
9652foo.h:
96534 if (a < 0)
9654 0x0000000000400406 <+6>: test %eax,%eax
9655 0x0000000000400408 <+8>: js 0x400420 <main+32>
9656
96576 if (a == 0)
96587 return 1;
96598 return a + 10;
9660 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9661 0x000000000040040d <+13>: test %eax,%eax
9662 0x000000000040040f <+15>: mov $0x1,%eax
9663 0x0000000000400414 <+20>: cmovne %edx,%eax
9664
9665foo.c:
96666 x = foo (y);
9667 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9668
96697 return 0;
96708 @}
9671 0x000000000040041d <+29>: xor %eax,%eax
9672 0x000000000040041f <+31>: retq
9673
9674foo.h:
96755 return a * 2;
9676 0x0000000000400420 <+32>: add %eax,%eax
9677 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9678End of assembler dump.
9679@end smallexample
9680
53a71c06
CR
9681Here is another example showing raw instructions in hex for AMD x86-64,
9682
9683@smallexample
9684(gdb) disas /r 0x400281,+10
9685Dump of assembler code from 0x400281 to 0x40028b:
9686 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9687 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9688 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9689 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9690End of assembler dump.
9691@end smallexample
9692
629500fa 9693Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9694So, for example, if you want to disassemble function @code{bar}
9695in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9696and not @samp{disassemble foo.c:bar}.
9697
c906108c
SS
9698Some architectures have more than one commonly-used set of instruction
9699mnemonics or other syntax.
9700
76d17f34
EZ
9701For programs that were dynamically linked and use shared libraries,
9702instructions that call functions or branch to locations in the shared
9703libraries might show a seemingly bogus location---it's actually a
9704location of the relocation table. On some architectures, @value{GDBN}
9705might be able to resolve these to actual function names.
9706
65b48a81
PB
9707@table @code
9708@kindex set disassembler-options
9709@cindex disassembler options
9710@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9711This command controls the passing of target specific information to
9712the disassembler. For a list of valid options, please refer to the
9713@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9714manual and/or the output of @kbd{objdump --help}
f5a476a7 9715(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9716The default value is the empty string.
9717
9718If it is necessary to specify more than one disassembler option, then
9719multiple options can be placed together into a comma separated list.
471b9d15 9720Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9721and S/390.
9722
9723@kindex show disassembler-options
9724@item show disassembler-options
9725Show the current setting of the disassembler options.
9726@end table
9727
c906108c 9728@table @code
d4f3574e 9729@kindex set disassembly-flavor
d4f3574e
SS
9730@cindex Intel disassembly flavor
9731@cindex AT&T disassembly flavor
9732@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9733Select the instruction set to use when disassembling the
9734program via the @code{disassemble} or @code{x/i} commands.
9735
9736Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9737can set @var{instruction-set} to either @code{intel} or @code{att}.
9738The default is @code{att}, the AT&T flavor used by default by Unix
9739assemblers for x86-based targets.
9c16f35a
EZ
9740
9741@kindex show disassembly-flavor
9742@item show disassembly-flavor
9743Show the current setting of the disassembly flavor.
c906108c
SS
9744@end table
9745
91440f57
HZ
9746@table @code
9747@kindex set disassemble-next-line
9748@kindex show disassemble-next-line
9749@item set disassemble-next-line
9750@itemx show disassemble-next-line
32ae1842
EZ
9751Control whether or not @value{GDBN} will disassemble the next source
9752line or instruction when execution stops. If ON, @value{GDBN} will
9753display disassembly of the next source line when execution of the
9754program being debugged stops. This is @emph{in addition} to
9755displaying the source line itself, which @value{GDBN} always does if
9756possible. If the next source line cannot be displayed for some reason
9757(e.g., if @value{GDBN} cannot find the source file, or there's no line
9758info in the debug info), @value{GDBN} will display disassembly of the
9759next @emph{instruction} instead of showing the next source line. If
9760AUTO, @value{GDBN} will display disassembly of next instruction only
9761if the source line cannot be displayed. This setting causes
9762@value{GDBN} to display some feedback when you step through a function
9763with no line info or whose source file is unavailable. The default is
9764OFF, which means never display the disassembly of the next line or
9765instruction.
91440f57
HZ
9766@end table
9767
c906108c 9768
6d2ebf8b 9769@node Data
c906108c
SS
9770@chapter Examining Data
9771
9772@cindex printing data
9773@cindex examining data
9774@kindex print
9775@kindex inspect
c906108c 9776The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9777command (abbreviated @code{p}), or its synonym @code{inspect}. It
9778evaluates and prints the value of an expression of the language your
9779program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9780Different Languages}). It may also print the expression using a
9781Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9782
9783@table @code
3345721a
PA
9784@item print [[@var{options}] --] @var{expr}
9785@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9786@var{expr} is an expression (in the source language). By default the
9787value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9788you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9789@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9790Formats}.
c906108c 9791
3345721a
PA
9792@anchor{print options}
9793The @code{print} command supports a number of options that allow
9794overriding relevant global print settings as set by @code{set print}
9795subcommands:
9796
9797@table @code
9798@item -address [@code{on}|@code{off}]
9799Set printing of addresses.
9800Related setting: @ref{set print address}.
9801
9802@item -array [@code{on}|@code{off}]
9803Pretty formatting of arrays.
9804Related setting: @ref{set print array}.
9805
9806@item -array-indexes [@code{on}|@code{off}]
9807Set printing of array indexes.
9808Related setting: @ref{set print array-indexes}.
9809
9810@item -elements @var{number-of-elements}|@code{unlimited}
9811Set limit on string chars or array elements to print. The value
9812@code{unlimited} causes there to be no limit. Related setting:
9813@ref{set print elements}.
9814
9815@item -max-depth @var{depth}|@code{unlimited}
9816Set the threshold after which nested structures are replaced with
9817ellipsis. Related setting: @ref{set print max-depth}.
9818
9819@item -null-stop [@code{on}|@code{off}]
9820Set printing of char arrays to stop at first null char. Related
9821setting: @ref{set print null-stop}.
9822
9823@item -object [@code{on}|@code{off}]
9824Set printing C@t{++} virtual function tables. Related setting:
9825@ref{set print object}.
9826
9827@item -pretty [@code{on}|@code{off}]
9828Set pretty formatting of structures. Related setting: @ref{set print
9829pretty}.
9830
d8edc8b7
PW
9831@item -raw-values [@code{on}|@code{off}]
9832Set whether to print values in raw form, bypassing any
9833pretty-printers for that value. Related setting: @ref{set print
9834raw-values}.
9835
3345721a
PA
9836@item -repeats @var{number-of-repeats}|@code{unlimited}
9837Set threshold for repeated print elements. @code{unlimited} causes
9838all elements to be individually printed. Related setting: @ref{set
9839print repeats}.
9840
9841@item -static-members [@code{on}|@code{off}]
9842Set printing C@t{++} static members. Related setting: @ref{set print
9843static-members}.
9844
9845@item -symbol [@code{on}|@code{off}]
9846Set printing of symbol names when printing pointers. Related setting:
9847@ref{set print symbol}.
9848
9849@item -union [@code{on}|@code{off}]
9850Set printing of unions interior to structures. Related setting:
9851@ref{set print union}.
9852
9853@item -vtbl [@code{on}|@code{off}]
9854Set printing of C++ virtual function tables. Related setting:
9855@ref{set print vtbl}.
9856@end table
9857
9858Because the @code{print} command accepts arbitrary expressions which
9859may look like options (including abbreviations), if you specify any
9860command option, then you must use a double dash (@code{--}) to mark
9861the end of option processing.
9862
d8edc8b7 9863For example, this prints the value of the @code{-p} expression:
3345721a
PA
9864
9865@smallexample
d8edc8b7 9866(@value{GDBP}) print -p
3345721a
PA
9867@end smallexample
9868
9869While this repeats the last value in the value history (see below)
d8edc8b7 9870with the @code{-pretty} option in effect:
3345721a
PA
9871
9872@smallexample
d8edc8b7 9873(@value{GDBP}) print -p --
3345721a
PA
9874@end smallexample
9875
9876Here is an example including both on option and an expression:
9877
9878@smallexample
9879@group
9880(@value{GDBP}) print -pretty -- *myptr
9881$1 = @{
9882 next = 0x0,
9883 flags = @{
9884 sweet = 1,
9885 sour = 1
9886 @},
9887 meat = 0x54 "Pork"
9888@}
9889@end group
9890@end smallexample
9891
9892@item print [@var{options}]
9893@itemx print [@var{options}] /@var{f}
15387254 9894@cindex reprint the last value
d4f3574e 9895If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9896@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9897conveniently inspect the same value in an alternative format.
9898@end table
9899
9900A more low-level way of examining data is with the @code{x} command.
9901It examines data in memory at a specified address and prints it in a
79a6e687 9902specified format. @xref{Memory, ,Examining Memory}.
c906108c 9903
7a292a7a 9904If you are interested in information about types, or about how the
d4f3574e
SS
9905fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9906command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9907Table}.
c906108c 9908
06fc020f
SCR
9909@cindex exploring hierarchical data structures
9910@kindex explore
9911Another way of examining values of expressions and type information is
9912through the Python extension command @code{explore} (available only if
9913the @value{GDBN} build is configured with @code{--with-python}). It
9914offers an interactive way to start at the highest level (or, the most
9915abstract level) of the data type of an expression (or, the data type
9916itself) and explore all the way down to leaf scalar values/fields
9917embedded in the higher level data types.
9918
9919@table @code
9920@item explore @var{arg}
9921@var{arg} is either an expression (in the source language), or a type
9922visible in the current context of the program being debugged.
9923@end table
9924
9925The working of the @code{explore} command can be illustrated with an
9926example. If a data type @code{struct ComplexStruct} is defined in your
9927C program as
9928
9929@smallexample
9930struct SimpleStruct
9931@{
9932 int i;
9933 double d;
9934@};
9935
9936struct ComplexStruct
9937@{
9938 struct SimpleStruct *ss_p;
9939 int arr[10];
9940@};
9941@end smallexample
9942
9943@noindent
9944followed by variable declarations as
9945
9946@smallexample
9947struct SimpleStruct ss = @{ 10, 1.11 @};
9948struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9949@end smallexample
9950
9951@noindent
9952then, the value of the variable @code{cs} can be explored using the
9953@code{explore} command as follows.
9954
9955@smallexample
9956(gdb) explore cs
9957The value of `cs' is a struct/class of type `struct ComplexStruct' with
9958the following fields:
9959
9960 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9961 arr = <Enter 1 to explore this field of type `int [10]'>
9962
9963Enter the field number of choice:
9964@end smallexample
9965
9966@noindent
9967Since the fields of @code{cs} are not scalar values, you are being
9968prompted to chose the field you want to explore. Let's say you choose
9969the field @code{ss_p} by entering @code{0}. Then, since this field is a
9970pointer, you will be asked if it is pointing to a single value. From
9971the declaration of @code{cs} above, it is indeed pointing to a single
9972value, hence you enter @code{y}. If you enter @code{n}, then you will
9973be asked if it were pointing to an array of values, in which case this
9974field will be explored as if it were an array.
9975
9976@smallexample
9977`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9978Continue exploring it as a pointer to a single value [y/n]: y
9979The value of `*(cs.ss_p)' is a struct/class of type `struct
9980SimpleStruct' with the following fields:
9981
9982 i = 10 .. (Value of type `int')
9983 d = 1.1100000000000001 .. (Value of type `double')
9984
9985Press enter to return to parent value:
9986@end smallexample
9987
9988@noindent
9989If the field @code{arr} of @code{cs} was chosen for exploration by
9990entering @code{1} earlier, then since it is as array, you will be
9991prompted to enter the index of the element in the array that you want
9992to explore.
9993
9994@smallexample
9995`cs.arr' is an array of `int'.
9996Enter the index of the element you want to explore in `cs.arr': 5
9997
9998`(cs.arr)[5]' is a scalar value of type `int'.
9999
10000(cs.arr)[5] = 4
10001
10002Press enter to return to parent value:
10003@end smallexample
10004
10005In general, at any stage of exploration, you can go deeper towards the
10006leaf values by responding to the prompts appropriately, or hit the
10007return key to return to the enclosing data structure (the @i{higher}
10008level data structure).
10009
10010Similar to exploring values, you can use the @code{explore} command to
10011explore types. Instead of specifying a value (which is typically a
10012variable name or an expression valid in the current context of the
10013program being debugged), you specify a type name. If you consider the
10014same example as above, your can explore the type
10015@code{struct ComplexStruct} by passing the argument
10016@code{struct ComplexStruct} to the @code{explore} command.
10017
10018@smallexample
10019(gdb) explore struct ComplexStruct
10020@end smallexample
10021
10022@noindent
10023By responding to the prompts appropriately in the subsequent interactive
10024session, you can explore the type @code{struct ComplexStruct} in a
10025manner similar to how the value @code{cs} was explored in the above
10026example.
10027
10028The @code{explore} command also has two sub-commands,
10029@code{explore value} and @code{explore type}. The former sub-command is
10030a way to explicitly specify that value exploration of the argument is
10031being invoked, while the latter is a way to explicitly specify that type
10032exploration of the argument is being invoked.
10033
10034@table @code
10035@item explore value @var{expr}
10036@cindex explore value
10037This sub-command of @code{explore} explores the value of the
10038expression @var{expr} (if @var{expr} is an expression valid in the
10039current context of the program being debugged). The behavior of this
10040command is identical to that of the behavior of the @code{explore}
10041command being passed the argument @var{expr}.
10042
10043@item explore type @var{arg}
10044@cindex explore type
10045This sub-command of @code{explore} explores the type of @var{arg} (if
10046@var{arg} is a type visible in the current context of program being
10047debugged), or the type of the value/expression @var{arg} (if @var{arg}
10048is an expression valid in the current context of the program being
10049debugged). If @var{arg} is a type, then the behavior of this command is
10050identical to that of the @code{explore} command being passed the
10051argument @var{arg}. If @var{arg} is an expression, then the behavior of
10052this command will be identical to that of the @code{explore} command
10053being passed the type of @var{arg} as the argument.
10054@end table
10055
c906108c
SS
10056@menu
10057* Expressions:: Expressions
6ba66d6a 10058* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
10059* Variables:: Program variables
10060* Arrays:: Artificial arrays
10061* Output Formats:: Output formats
10062* Memory:: Examining memory
10063* Auto Display:: Automatic display
10064* Print Settings:: Print settings
4c374409 10065* Pretty Printing:: Python pretty printing
c906108c
SS
10066* Value History:: Value history
10067* Convenience Vars:: Convenience variables
a72c3253 10068* Convenience Funs:: Convenience functions
c906108c 10069* Registers:: Registers
c906108c 10070* Floating Point Hardware:: Floating point hardware
53c69bd7 10071* Vector Unit:: Vector Unit
721c2651 10072* OS Information:: Auxiliary data provided by operating system
29e57380 10073* Memory Region Attributes:: Memory region attributes
16d9dec6 10074* Dump/Restore Files:: Copy between memory and a file
384ee23f 10075* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
10076* Character Sets:: Debugging programs that use a different
10077 character set than GDB does
b12039c6 10078* Caching Target Data:: Data caching for targets
08388c79 10079* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 10080* Value Sizes:: Managing memory allocated for values
c906108c
SS
10081@end menu
10082
6d2ebf8b 10083@node Expressions
c906108c
SS
10084@section Expressions
10085
10086@cindex expressions
10087@code{print} and many other @value{GDBN} commands accept an expression and
10088compute its value. Any kind of constant, variable or operator defined
10089by the programming language you are using is valid in an expression in
e2e0bcd1
JB
10090@value{GDBN}. This includes conditional expressions, function calls,
10091casts, and string constants. It also includes preprocessor macros, if
10092you compiled your program to include this information; see
10093@ref{Compilation}.
c906108c 10094
15387254 10095@cindex arrays in expressions
d4f3574e
SS
10096@value{GDBN} supports array constants in expressions input by
10097the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
10098you can use the command @code{print @{1, 2, 3@}} to create an array
10099of three integers. If you pass an array to a function or assign it
10100to a program variable, @value{GDBN} copies the array to memory that
10101is @code{malloc}ed in the target program.
c906108c 10102
c906108c
SS
10103Because C is so widespread, most of the expressions shown in examples in
10104this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10105Languages}, for information on how to use expressions in other
10106languages.
10107
10108In this section, we discuss operators that you can use in @value{GDBN}
10109expressions regardless of your programming language.
10110
15387254 10111@cindex casts, in expressions
c906108c
SS
10112Casts are supported in all languages, not just in C, because it is so
10113useful to cast a number into a pointer in order to examine a structure
10114at that address in memory.
10115@c FIXME: casts supported---Mod2 true?
c906108c
SS
10116
10117@value{GDBN} supports these operators, in addition to those common
10118to programming languages:
10119
10120@table @code
10121@item @@
10122@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10123@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10124
10125@item ::
10126@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10127function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10128
10129@cindex @{@var{type}@}
10130@cindex type casting memory
10131@cindex memory, viewing as typed object
10132@cindex casts, to view memory
10133@item @{@var{type}@} @var{addr}
10134Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10135memory. The address @var{addr} may be any expression whose value is
10136an integer or pointer (but parentheses are required around binary
10137operators, just as in a cast). This construct is allowed regardless
10138of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10139@end table
10140
6ba66d6a
JB
10141@node Ambiguous Expressions
10142@section Ambiguous Expressions
10143@cindex ambiguous expressions
10144
10145Expressions can sometimes contain some ambiguous elements. For instance,
10146some programming languages (notably Ada, C@t{++} and Objective-C) permit
10147a single function name to be defined several times, for application in
10148different contexts. This is called @dfn{overloading}. Another example
10149involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10150templates and is typically instantiated several times, resulting in
10151the same function name being defined in different contexts.
10152
10153In some cases and depending on the language, it is possible to adjust
10154the expression to remove the ambiguity. For instance in C@t{++}, you
10155can specify the signature of the function you want to break on, as in
10156@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10157qualified name of your function often makes the expression unambiguous
10158as well.
10159
10160When an ambiguity that needs to be resolved is detected, the debugger
10161has the capability to display a menu of numbered choices for each
10162possibility, and then waits for the selection with the prompt @samp{>}.
10163The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10164aborts the current command. If the command in which the expression was
10165used allows more than one choice to be selected, the next option in the
10166menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10167choices.
10168
10169For example, the following session excerpt shows an attempt to set a
10170breakpoint at the overloaded symbol @code{String::after}.
10171We choose three particular definitions of that function name:
10172
10173@c FIXME! This is likely to change to show arg type lists, at least
10174@smallexample
10175@group
10176(@value{GDBP}) b String::after
10177[0] cancel
10178[1] all
10179[2] file:String.cc; line number:867
10180[3] file:String.cc; line number:860
10181[4] file:String.cc; line number:875
10182[5] file:String.cc; line number:853
10183[6] file:String.cc; line number:846
10184[7] file:String.cc; line number:735
10185> 2 4 6
10186Breakpoint 1 at 0xb26c: file String.cc, line 867.
10187Breakpoint 2 at 0xb344: file String.cc, line 875.
10188Breakpoint 3 at 0xafcc: file String.cc, line 846.
10189Multiple breakpoints were set.
10190Use the "delete" command to delete unwanted
10191 breakpoints.
10192(@value{GDBP})
10193@end group
10194@end smallexample
10195
10196@table @code
10197@kindex set multiple-symbols
10198@item set multiple-symbols @var{mode}
10199@cindex multiple-symbols menu
10200
10201This option allows you to adjust the debugger behavior when an expression
10202is ambiguous.
10203
10204By default, @var{mode} is set to @code{all}. If the command with which
10205the expression is used allows more than one choice, then @value{GDBN}
10206automatically selects all possible choices. For instance, inserting
10207a breakpoint on a function using an ambiguous name results in a breakpoint
10208inserted on each possible match. However, if a unique choice must be made,
10209then @value{GDBN} uses the menu to help you disambiguate the expression.
10210For instance, printing the address of an overloaded function will result
10211in the use of the menu.
10212
10213When @var{mode} is set to @code{ask}, the debugger always uses the menu
10214when an ambiguity is detected.
10215
10216Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10217an error due to the ambiguity and the command is aborted.
10218
10219@kindex show multiple-symbols
10220@item show multiple-symbols
10221Show the current value of the @code{multiple-symbols} setting.
10222@end table
10223
6d2ebf8b 10224@node Variables
79a6e687 10225@section Program Variables
c906108c
SS
10226
10227The most common kind of expression to use is the name of a variable
10228in your program.
10229
10230Variables in expressions are understood in the selected stack frame
79a6e687 10231(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10232
10233@itemize @bullet
10234@item
10235global (or file-static)
10236@end itemize
10237
5d161b24 10238@noindent or
c906108c
SS
10239
10240@itemize @bullet
10241@item
10242visible according to the scope rules of the
10243programming language from the point of execution in that frame
5d161b24 10244@end itemize
c906108c
SS
10245
10246@noindent This means that in the function
10247
474c8240 10248@smallexample
c906108c
SS
10249foo (a)
10250 int a;
10251@{
10252 bar (a);
10253 @{
10254 int b = test ();
10255 bar (b);
10256 @}
10257@}
474c8240 10258@end smallexample
c906108c
SS
10259
10260@noindent
10261you can examine and use the variable @code{a} whenever your program is
10262executing within the function @code{foo}, but you can only use or
10263examine the variable @code{b} while your program is executing inside
10264the block where @code{b} is declared.
10265
10266@cindex variable name conflict
10267There is an exception: you can refer to a variable or function whose
10268scope is a single source file even if the current execution point is not
10269in this file. But it is possible to have more than one such variable or
10270function with the same name (in different source files). If that
10271happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10272you can specify a static variable in a particular function or file by
15387254 10273using the colon-colon (@code{::}) notation:
c906108c 10274
d4f3574e 10275@cindex colon-colon, context for variables/functions
12c27660 10276@ifnotinfo
c906108c 10277@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10278@cindex @code{::}, context for variables/functions
12c27660 10279@end ifnotinfo
474c8240 10280@smallexample
c906108c
SS
10281@var{file}::@var{variable}
10282@var{function}::@var{variable}
474c8240 10283@end smallexample
c906108c
SS
10284
10285@noindent
10286Here @var{file} or @var{function} is the name of the context for the
10287static @var{variable}. In the case of file names, you can use quotes to
10288make sure @value{GDBN} parses the file name as a single word---for example,
10289to print a global value of @code{x} defined in @file{f2.c}:
10290
474c8240 10291@smallexample
c906108c 10292(@value{GDBP}) p 'f2.c'::x
474c8240 10293@end smallexample
c906108c 10294
72384ba3
PH
10295The @code{::} notation is normally used for referring to
10296static variables, since you typically disambiguate uses of local variables
10297in functions by selecting the appropriate frame and using the
10298simple name of the variable. However, you may also use this notation
10299to refer to local variables in frames enclosing the selected frame:
10300
10301@smallexample
10302void
10303foo (int a)
10304@{
10305 if (a < 10)
10306 bar (a);
10307 else
10308 process (a); /* Stop here */
10309@}
10310
10311int
10312bar (int a)
10313@{
10314 foo (a + 5);
10315@}
10316@end smallexample
10317
10318@noindent
10319For example, if there is a breakpoint at the commented line,
10320here is what you might see
10321when the program stops after executing the call @code{bar(0)}:
10322
10323@smallexample
10324(@value{GDBP}) p a
10325$1 = 10
10326(@value{GDBP}) p bar::a
10327$2 = 5
10328(@value{GDBP}) up 2
10329#2 0x080483d0 in foo (a=5) at foobar.c:12
10330(@value{GDBP}) p a
10331$3 = 5
10332(@value{GDBP}) p bar::a
10333$4 = 0
10334@end smallexample
10335
b37052ae 10336@cindex C@t{++} scope resolution
805e1f19
TT
10337These uses of @samp{::} are very rarely in conflict with the very
10338similar use of the same notation in C@t{++}. When they are in
10339conflict, the C@t{++} meaning takes precedence; however, this can be
10340overridden by quoting the file or function name with single quotes.
10341
10342For example, suppose the program is stopped in a method of a class
10343that has a field named @code{includefile}, and there is also an
10344include file named @file{includefile} that defines a variable,
10345@code{some_global}.
10346
10347@smallexample
10348(@value{GDBP}) p includefile
10349$1 = 23
10350(@value{GDBP}) p includefile::some_global
10351A syntax error in expression, near `'.
10352(@value{GDBP}) p 'includefile'::some_global
10353$2 = 27
10354@end smallexample
c906108c
SS
10355
10356@cindex wrong values
10357@cindex variable values, wrong
15387254
EZ
10358@cindex function entry/exit, wrong values of variables
10359@cindex optimized code, wrong values of variables
c906108c
SS
10360@quotation
10361@emph{Warning:} Occasionally, a local variable may appear to have the
10362wrong value at certain points in a function---just after entry to a new
10363scope, and just before exit.
10364@end quotation
10365You may see this problem when you are stepping by machine instructions.
10366This is because, on most machines, it takes more than one instruction to
10367set up a stack frame (including local variable definitions); if you are
10368stepping by machine instructions, variables may appear to have the wrong
10369values until the stack frame is completely built. On exit, it usually
10370also takes more than one machine instruction to destroy a stack frame;
10371after you begin stepping through that group of instructions, local
10372variable definitions may be gone.
10373
10374This may also happen when the compiler does significant optimizations.
10375To be sure of always seeing accurate values, turn off all optimization
10376when compiling.
10377
d4f3574e
SS
10378@cindex ``No symbol "foo" in current context''
10379Another possible effect of compiler optimizations is to optimize
10380unused variables out of existence, or assign variables to registers (as
10381opposed to memory addresses). Depending on the support for such cases
10382offered by the debug info format used by the compiler, @value{GDBN}
10383might not be able to display values for such local variables. If that
10384happens, @value{GDBN} will print a message like this:
10385
474c8240 10386@smallexample
d4f3574e 10387No symbol "foo" in current context.
474c8240 10388@end smallexample
d4f3574e
SS
10389
10390To solve such problems, either recompile without optimizations, or use a
10391different debug info format, if the compiler supports several such
e0f8f636
TT
10392formats. @xref{Compilation}, for more information on choosing compiler
10393options. @xref{C, ,C and C@t{++}}, for more information about debug
10394info formats that are best suited to C@t{++} programs.
d4f3574e 10395
ab1adacd
EZ
10396If you ask to print an object whose contents are unknown to
10397@value{GDBN}, e.g., because its data type is not completely specified
10398by the debug information, @value{GDBN} will say @samp{<incomplete
10399type>}. @xref{Symbols, incomplete type}, for more about this.
10400
d69cf9b2
PA
10401@cindex no debug info variables
10402If you try to examine or use the value of a (global) variable for
10403which @value{GDBN} has no type information, e.g., because the program
10404includes no debug information, @value{GDBN} displays an error message.
10405@xref{Symbols, unknown type}, for more about unknown types. If you
10406cast the variable to its declared type, @value{GDBN} gets the
10407variable's value using the cast-to type as the variable's type. For
10408example, in a C program:
10409
10410@smallexample
10411 (@value{GDBP}) p var
10412 'var' has unknown type; cast it to its declared type
10413 (@value{GDBP}) p (float) var
10414 $1 = 3.14
10415@end smallexample
10416
36b11add
JK
10417If you append @kbd{@@entry} string to a function parameter name you get its
10418value at the time the function got called. If the value is not available an
10419error message is printed. Entry values are available only with some compilers.
10420Entry values are normally also printed at the function parameter list according
10421to @ref{set print entry-values}.
10422
10423@smallexample
10424Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1042529 i++;
10426(gdb) next
1042730 e (i);
10428(gdb) print i
10429$1 = 31
10430(gdb) print i@@entry
10431$2 = 30
10432@end smallexample
10433
3a60f64e
JK
10434Strings are identified as arrays of @code{char} values without specified
10435signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10436printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10437@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10438defines literal string type @code{"char"} as @code{char} without a sign.
10439For program code
10440
10441@smallexample
10442char var0[] = "A";
10443signed char var1[] = "A";
10444@end smallexample
10445
10446You get during debugging
10447@smallexample
10448(gdb) print var0
10449$1 = "A"
10450(gdb) print var1
10451$2 = @{65 'A', 0 '\0'@}
10452@end smallexample
10453
6d2ebf8b 10454@node Arrays
79a6e687 10455@section Artificial Arrays
c906108c
SS
10456
10457@cindex artificial array
15387254 10458@cindex arrays
41afff9a 10459@kindex @@@r{, referencing memory as an array}
c906108c
SS
10460It is often useful to print out several successive objects of the
10461same type in memory; a section of an array, or an array of
10462dynamically determined size for which only a pointer exists in the
10463program.
10464
10465You can do this by referring to a contiguous span of memory as an
10466@dfn{artificial array}, using the binary operator @samp{@@}. The left
10467operand of @samp{@@} should be the first element of the desired array
10468and be an individual object. The right operand should be the desired length
10469of the array. The result is an array value whose elements are all of
10470the type of the left argument. The first element is actually the left
10471argument; the second element comes from bytes of memory immediately
10472following those that hold the first element, and so on. Here is an
10473example. If a program says
10474
474c8240 10475@smallexample
c906108c 10476int *array = (int *) malloc (len * sizeof (int));
474c8240 10477@end smallexample
c906108c
SS
10478
10479@noindent
10480you can print the contents of @code{array} with
10481
474c8240 10482@smallexample
c906108c 10483p *array@@len
474c8240 10484@end smallexample
c906108c
SS
10485
10486The left operand of @samp{@@} must reside in memory. Array values made
10487with @samp{@@} in this way behave just like other arrays in terms of
10488subscripting, and are coerced to pointers when used in expressions.
10489Artificial arrays most often appear in expressions via the value history
79a6e687 10490(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10491
10492Another way to create an artificial array is to use a cast.
10493This re-interprets a value as if it were an array.
10494The value need not be in memory:
474c8240 10495@smallexample
c906108c
SS
10496(@value{GDBP}) p/x (short[2])0x12345678
10497$1 = @{0x1234, 0x5678@}
474c8240 10498@end smallexample
c906108c
SS
10499
10500As a convenience, if you leave the array length out (as in
c3f6f71d 10501@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10502the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10503@smallexample
c906108c
SS
10504(@value{GDBP}) p/x (short[])0x12345678
10505$2 = @{0x1234, 0x5678@}
474c8240 10506@end smallexample
c906108c
SS
10507
10508Sometimes the artificial array mechanism is not quite enough; in
10509moderately complex data structures, the elements of interest may not
10510actually be adjacent---for example, if you are interested in the values
10511of pointers in an array. One useful work-around in this situation is
10512to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10513Variables}) as a counter in an expression that prints the first
c906108c
SS
10514interesting value, and then repeat that expression via @key{RET}. For
10515instance, suppose you have an array @code{dtab} of pointers to
10516structures, and you are interested in the values of a field @code{fv}
10517in each structure. Here is an example of what you might type:
10518
474c8240 10519@smallexample
c906108c
SS
10520set $i = 0
10521p dtab[$i++]->fv
10522@key{RET}
10523@key{RET}
10524@dots{}
474c8240 10525@end smallexample
c906108c 10526
6d2ebf8b 10527@node Output Formats
79a6e687 10528@section Output Formats
c906108c
SS
10529
10530@cindex formatted output
10531@cindex output formats
10532By default, @value{GDBN} prints a value according to its data type. Sometimes
10533this is not what you want. For example, you might want to print a number
10534in hex, or a pointer in decimal. Or you might want to view data in memory
10535at a certain address as a character string or as an instruction. To do
10536these things, specify an @dfn{output format} when you print a value.
10537
10538The simplest use of output formats is to say how to print a value
10539already computed. This is done by starting the arguments of the
10540@code{print} command with a slash and a format letter. The format
10541letters supported are:
10542
10543@table @code
10544@item x
10545Regard the bits of the value as an integer, and print the integer in
10546hexadecimal.
10547
10548@item d
10549Print as integer in signed decimal.
10550
10551@item u
10552Print as integer in unsigned decimal.
10553
10554@item o
10555Print as integer in octal.
10556
10557@item t
10558Print as integer in binary. The letter @samp{t} stands for ``two''.
10559@footnote{@samp{b} cannot be used because these format letters are also
10560used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10561see @ref{Memory,,Examining Memory}.}
c906108c
SS
10562
10563@item a
10564@cindex unknown address, locating
3d67e040 10565@cindex locate address
c906108c
SS
10566Print as an address, both absolute in hexadecimal and as an offset from
10567the nearest preceding symbol. You can use this format used to discover
10568where (in what function) an unknown address is located:
10569
474c8240 10570@smallexample
c906108c
SS
10571(@value{GDBP}) p/a 0x54320
10572$3 = 0x54320 <_initialize_vx+396>
474c8240 10573@end smallexample
c906108c 10574
3d67e040
EZ
10575@noindent
10576The command @code{info symbol 0x54320} yields similar results.
10577@xref{Symbols, info symbol}.
10578
c906108c 10579@item c
51274035
EZ
10580Regard as an integer and print it as a character constant. This
10581prints both the numerical value and its character representation. The
10582character representation is replaced with the octal escape @samp{\nnn}
10583for characters outside the 7-bit @sc{ascii} range.
c906108c 10584
ea37ba09
DJ
10585Without this format, @value{GDBN} displays @code{char},
10586@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10587constants. Single-byte members of vectors are displayed as integer
10588data.
10589
c906108c
SS
10590@item f
10591Regard the bits of the value as a floating point number and print
10592using typical floating point syntax.
ea37ba09
DJ
10593
10594@item s
10595@cindex printing strings
10596@cindex printing byte arrays
10597Regard as a string, if possible. With this format, pointers to single-byte
10598data are displayed as null-terminated strings and arrays of single-byte data
10599are displayed as fixed-length strings. Other values are displayed in their
10600natural types.
10601
10602Without this format, @value{GDBN} displays pointers to and arrays of
10603@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10604strings. Single-byte members of a vector are displayed as an integer
10605array.
a6bac58e 10606
6fbe845e
AB
10607@item z
10608Like @samp{x} formatting, the value is treated as an integer and
10609printed as hexadecimal, but leading zeros are printed to pad the value
10610to the size of the integer type.
10611
a6bac58e
TT
10612@item r
10613@cindex raw printing
10614Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10615use a Python-based pretty-printer, if one is available (@pxref{Pretty
10616Printing}). This typically results in a higher-level display of the
10617value's contents. The @samp{r} format bypasses any Python
10618pretty-printer which might exist.
c906108c
SS
10619@end table
10620
10621For example, to print the program counter in hex (@pxref{Registers}), type
10622
474c8240 10623@smallexample
c906108c 10624p/x $pc
474c8240 10625@end smallexample
c906108c
SS
10626
10627@noindent
10628Note that no space is required before the slash; this is because command
10629names in @value{GDBN} cannot contain a slash.
10630
10631To reprint the last value in the value history with a different format,
10632you can use the @code{print} command with just a format and no
10633expression. For example, @samp{p/x} reprints the last value in hex.
10634
6d2ebf8b 10635@node Memory
79a6e687 10636@section Examining Memory
c906108c
SS
10637
10638You can use the command @code{x} (for ``examine'') to examine memory in
10639any of several formats, independently of your program's data types.
10640
10641@cindex examining memory
10642@table @code
41afff9a 10643@kindex x @r{(examine memory)}
c906108c
SS
10644@item x/@var{nfu} @var{addr}
10645@itemx x @var{addr}
10646@itemx x
10647Use the @code{x} command to examine memory.
10648@end table
10649
10650@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10651much memory to display and how to format it; @var{addr} is an
10652expression giving the address where you want to start displaying memory.
10653If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10654Several commands set convenient defaults for @var{addr}.
10655
10656@table @r
10657@item @var{n}, the repeat count
10658The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10659how much memory (counting by units @var{u}) to display. If a negative
10660number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10661@c This really is **decimal**; unaffected by 'set radix' as of GDB
10662@c 4.1.2.
10663
10664@item @var{f}, the display format
51274035
EZ
10665The display format is one of the formats used by @code{print}
10666(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10667@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10668The default is @samp{x} (hexadecimal) initially. The default changes
10669each time you use either @code{x} or @code{print}.
c906108c
SS
10670
10671@item @var{u}, the unit size
10672The unit size is any of
10673
10674@table @code
10675@item b
10676Bytes.
10677@item h
10678Halfwords (two bytes).
10679@item w
10680Words (four bytes). This is the initial default.
10681@item g
10682Giant words (eight bytes).
10683@end table
10684
10685Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10686default unit the next time you use @code{x}. For the @samp{i} format,
10687the unit size is ignored and is normally not written. For the @samp{s} format,
10688the unit size defaults to @samp{b}, unless it is explicitly given.
10689Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1069032-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10691Note that the results depend on the programming language of the
10692current compilation unit. If the language is C, the @samp{s}
10693modifier will use the UTF-16 encoding while @samp{w} will use
10694UTF-32. The encoding is set by the programming language and cannot
10695be altered.
c906108c
SS
10696
10697@item @var{addr}, starting display address
10698@var{addr} is the address where you want @value{GDBN} to begin displaying
10699memory. The expression need not have a pointer value (though it may);
10700it is always interpreted as an integer address of a byte of memory.
10701@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10702@var{addr} is usually just after the last address examined---but several
10703other commands also set the default address: @code{info breakpoints} (to
10704the address of the last breakpoint listed), @code{info line} (to the
10705starting address of a line), and @code{print} (if you use it to display
10706a value from memory).
10707@end table
10708
10709For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10710(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10711starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10712words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10713@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10714
bb556f1f
TK
10715You can also specify a negative repeat count to examine memory backward
10716from the given address. For example, @samp{x/-3uh 0x54320} prints three
10717halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10718
c906108c
SS
10719Since the letters indicating unit sizes are all distinct from the
10720letters specifying output formats, you do not have to remember whether
10721unit size or format comes first; either order works. The output
10722specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10723(However, the count @var{n} must come first; @samp{wx4} does not work.)
10724
10725Even though the unit size @var{u} is ignored for the formats @samp{s}
10726and @samp{i}, you might still want to use a count @var{n}; for example,
10727@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10728including any operands. For convenience, especially when used with
10729the @code{display} command, the @samp{i} format also prints branch delay
10730slot instructions, if any, beyond the count specified, which immediately
10731follow the last instruction that is within the count. The command
10732@code{disassemble} gives an alternative way of inspecting machine
10733instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10734
bb556f1f
TK
10735If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10736the command displays null-terminated strings or instructions before the given
10737address as many as the absolute value of the given number. For the @samp{i}
10738format, we use line number information in the debug info to accurately locate
10739instruction boundaries while disassembling backward. If line info is not
10740available, the command stops examining memory with an error message.
10741
c906108c
SS
10742All the defaults for the arguments to @code{x} are designed to make it
10743easy to continue scanning memory with minimal specifications each time
10744you use @code{x}. For example, after you have inspected three machine
10745instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10746with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10747the repeat count @var{n} is used again; the other arguments default as
10748for successive uses of @code{x}.
10749
2b28d209
PP
10750When examining machine instructions, the instruction at current program
10751counter is shown with a @code{=>} marker. For example:
10752
10753@smallexample
10754(@value{GDBP}) x/5i $pc-6
10755 0x804837f <main+11>: mov %esp,%ebp
10756 0x8048381 <main+13>: push %ecx
10757 0x8048382 <main+14>: sub $0x4,%esp
10758=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10759 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10760@end smallexample
10761
c906108c
SS
10762@cindex @code{$_}, @code{$__}, and value history
10763The addresses and contents printed by the @code{x} command are not saved
10764in the value history because there is often too much of them and they
10765would get in the way. Instead, @value{GDBN} makes these values available for
10766subsequent use in expressions as values of the convenience variables
10767@code{$_} and @code{$__}. After an @code{x} command, the last address
10768examined is available for use in expressions in the convenience variable
10769@code{$_}. The contents of that address, as examined, are available in
10770the convenience variable @code{$__}.
10771
10772If the @code{x} command has a repeat count, the address and contents saved
10773are from the last memory unit printed; this is not the same as the last
10774address printed if several units were printed on the last line of output.
10775
a86c90e6
SM
10776@anchor{addressable memory unit}
10777@cindex addressable memory unit
10778Most targets have an addressable memory unit size of 8 bits. This means
10779that to each memory address are associated 8 bits of data. Some
10780targets, however, have other addressable memory unit sizes.
10781Within @value{GDBN} and this document, the term
10782@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10783when explicitly referring to a chunk of data of that size. The word
10784@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10785the addressable memory unit size of the target. For most systems,
10786addressable memory unit is a synonym of byte.
10787
09d4efe1 10788@cindex remote memory comparison
936d2992 10789@cindex target memory comparison
09d4efe1 10790@cindex verify remote memory image
936d2992 10791@cindex verify target memory image
09d4efe1 10792When you are debugging a program running on a remote target machine
936d2992
PA
10793(@pxref{Remote Debugging}), you may wish to verify the program's image
10794in the remote machine's memory against the executable file you
10795downloaded to the target. Or, on any target, you may want to check
10796whether the program has corrupted its own read-only sections. The
10797@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10798
10799@table @code
10800@kindex compare-sections
95cf3b38 10801@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10802Compare the data of a loadable section @var{section-name} in the
10803executable file of the program being debugged with the same section in
936d2992 10804the target machine's memory, and report any mismatches. With no
95cf3b38 10805arguments, compares all loadable sections. With an argument of
936d2992
PA
10806@code{-r}, compares all loadable read-only sections.
10807
10808Note: for remote targets, this command can be accelerated if the
10809target supports computing the CRC checksum of a block of memory
10810(@pxref{qCRC packet}).
09d4efe1
EZ
10811@end table
10812
6d2ebf8b 10813@node Auto Display
79a6e687 10814@section Automatic Display
c906108c
SS
10815@cindex automatic display
10816@cindex display of expressions
10817
10818If you find that you want to print the value of an expression frequently
10819(to see how it changes), you might want to add it to the @dfn{automatic
10820display list} so that @value{GDBN} prints its value each time your program stops.
10821Each expression added to the list is given a number to identify it;
10822to remove an expression from the list, you specify that number.
10823The automatic display looks like this:
10824
474c8240 10825@smallexample
c906108c
SS
108262: foo = 38
108273: bar[5] = (struct hack *) 0x3804
474c8240 10828@end smallexample
c906108c
SS
10829
10830@noindent
10831This display shows item numbers, expressions and their current values. As with
10832displays you request manually using @code{x} or @code{print}, you can
10833specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10834whether to use @code{print} or @code{x} depending your format
10835specification---it uses @code{x} if you specify either the @samp{i}
10836or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10837
10838@table @code
10839@kindex display
d4f3574e
SS
10840@item display @var{expr}
10841Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10842each time your program stops. @xref{Expressions, ,Expressions}.
10843
10844@code{display} does not repeat if you press @key{RET} again after using it.
10845
d4f3574e 10846@item display/@var{fmt} @var{expr}
c906108c 10847For @var{fmt} specifying only a display format and not a size or
d4f3574e 10848count, add the expression @var{expr} to the auto-display list but
c906108c 10849arrange to display it each time in the specified format @var{fmt}.
79a6e687 10850@xref{Output Formats,,Output Formats}.
c906108c
SS
10851
10852@item display/@var{fmt} @var{addr}
10853For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10854number of units, add the expression @var{addr} as a memory address to
10855be examined each time your program stops. Examining means in effect
79a6e687 10856doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10857@end table
10858
10859For example, @samp{display/i $pc} can be helpful, to see the machine
10860instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10861is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10862
10863@table @code
10864@kindex delete display
10865@kindex undisplay
10866@item undisplay @var{dnums}@dots{}
10867@itemx delete display @var{dnums}@dots{}
c9174737
PA
10868Remove items from the list of expressions to display. Specify the
10869numbers of the displays that you want affected with the command
10870argument @var{dnums}. It can be a single display number, one of the
10871numbers shown in the first field of the @samp{info display} display;
10872or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10873
10874@code{undisplay} does not repeat if you press @key{RET} after using it.
10875(Otherwise you would just get the error @samp{No display number @dots{}}.)
10876
10877@kindex disable display
10878@item disable display @var{dnums}@dots{}
10879Disable the display of item numbers @var{dnums}. A disabled display
10880item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10881enabled again later. Specify the numbers of the displays that you
10882want affected with the command argument @var{dnums}. It can be a
10883single display number, one of the numbers shown in the first field of
10884the @samp{info display} display; or it could be a range of display
10885numbers, as in @code{2-4}.
c906108c
SS
10886
10887@kindex enable display
10888@item enable display @var{dnums}@dots{}
10889Enable display of item numbers @var{dnums}. It becomes effective once
10890again in auto display of its expression, until you specify otherwise.
c9174737
PA
10891Specify the numbers of the displays that you want affected with the
10892command argument @var{dnums}. It can be a single display number, one
10893of the numbers shown in the first field of the @samp{info display}
10894display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10895
10896@item display
10897Display the current values of the expressions on the list, just as is
10898done when your program stops.
10899
10900@kindex info display
10901@item info display
10902Print the list of expressions previously set up to display
10903automatically, each one with its item number, but without showing the
10904values. This includes disabled expressions, which are marked as such.
10905It also includes expressions which would not be displayed right now
10906because they refer to automatic variables not currently available.
10907@end table
10908
15387254 10909@cindex display disabled out of scope
c906108c
SS
10910If a display expression refers to local variables, then it does not make
10911sense outside the lexical context for which it was set up. Such an
10912expression is disabled when execution enters a context where one of its
10913variables is not defined. For example, if you give the command
10914@code{display last_char} while inside a function with an argument
10915@code{last_char}, @value{GDBN} displays this argument while your program
10916continues to stop inside that function. When it stops elsewhere---where
10917there is no variable @code{last_char}---the display is disabled
10918automatically. The next time your program stops where @code{last_char}
10919is meaningful, you can enable the display expression once again.
10920
6d2ebf8b 10921@node Print Settings
79a6e687 10922@section Print Settings
c906108c
SS
10923
10924@cindex format options
10925@cindex print settings
10926@value{GDBN} provides the following ways to control how arrays, structures,
10927and symbols are printed.
10928
10929@noindent
10930These settings are useful for debugging programs in any language:
10931
10932@table @code
4644b6e3 10933@kindex set print
3345721a 10934@anchor{set print address}
c906108c
SS
10935@item set print address
10936@itemx set print address on
4644b6e3 10937@cindex print/don't print memory addresses
c906108c
SS
10938@value{GDBN} prints memory addresses showing the location of stack
10939traces, structure values, pointer values, breakpoints, and so forth,
10940even when it also displays the contents of those addresses. The default
10941is @code{on}. For example, this is what a stack frame display looks like with
10942@code{set print address on}:
10943
10944@smallexample
10945@group
10946(@value{GDBP}) f
10947#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10948 at input.c:530
10949530 if (lquote != def_lquote)
10950@end group
10951@end smallexample
10952
10953@item set print address off
10954Do not print addresses when displaying their contents. For example,
10955this is the same stack frame displayed with @code{set print address off}:
10956
10957@smallexample
10958@group
10959(@value{GDBP}) set print addr off
10960(@value{GDBP}) f
10961#0 set_quotes (lq="<<", rq=">>") at input.c:530
10962530 if (lquote != def_lquote)
10963@end group
10964@end smallexample
10965
10966You can use @samp{set print address off} to eliminate all machine
10967dependent displays from the @value{GDBN} interface. For example, with
10968@code{print address off}, you should get the same text for backtraces on
10969all machines---whether or not they involve pointer arguments.
10970
4644b6e3 10971@kindex show print
c906108c
SS
10972@item show print address
10973Show whether or not addresses are to be printed.
10974@end table
10975
10976When @value{GDBN} prints a symbolic address, it normally prints the
10977closest earlier symbol plus an offset. If that symbol does not uniquely
10978identify the address (for example, it is a name whose scope is a single
10979source file), you may need to clarify. One way to do this is with
10980@code{info line}, for example @samp{info line *0x4537}. Alternately,
10981you can set @value{GDBN} to print the source file and line number when
10982it prints a symbolic address:
10983
10984@table @code
c906108c 10985@item set print symbol-filename on
9c16f35a
EZ
10986@cindex source file and line of a symbol
10987@cindex symbol, source file and line
c906108c
SS
10988Tell @value{GDBN} to print the source file name and line number of a
10989symbol in the symbolic form of an address.
10990
10991@item set print symbol-filename off
10992Do not print source file name and line number of a symbol. This is the
10993default.
10994
c906108c
SS
10995@item show print symbol-filename
10996Show whether or not @value{GDBN} will print the source file name and
10997line number of a symbol in the symbolic form of an address.
10998@end table
10999
11000Another situation where it is helpful to show symbol filenames and line
11001numbers is when disassembling code; @value{GDBN} shows you the line
11002number and source file that corresponds to each instruction.
11003
11004Also, you may wish to see the symbolic form only if the address being
11005printed is reasonably close to the closest earlier symbol:
11006
11007@table @code
c906108c 11008@item set print max-symbolic-offset @var{max-offset}
f81d1120 11009@itemx set print max-symbolic-offset unlimited
4644b6e3 11010@cindex maximum value for offset of closest symbol
c906108c
SS
11011Tell @value{GDBN} to only display the symbolic form of an address if the
11012offset between the closest earlier symbol and the address is less than
f81d1120
PA
11013@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11014to always print the symbolic form of an address if any symbol precedes
11015it. Zero is equivalent to @code{unlimited}.
c906108c 11016
c906108c
SS
11017@item show print max-symbolic-offset
11018Ask how large the maximum offset is that @value{GDBN} prints in a
11019symbolic address.
11020@end table
11021
11022@cindex wild pointer, interpreting
11023@cindex pointer, finding referent
11024If you have a pointer and you are not sure where it points, try
11025@samp{set print symbol-filename on}. Then you can determine the name
11026and source file location of the variable where it points, using
11027@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11028For example, here @value{GDBN} shows that a variable @code{ptt} points
11029at another variable @code{t}, defined in @file{hi2.c}:
11030
474c8240 11031@smallexample
c906108c
SS
11032(@value{GDBP}) set print symbol-filename on
11033(@value{GDBP}) p/a ptt
11034$4 = 0xe008 <t in hi2.c>
474c8240 11035@end smallexample
c906108c
SS
11036
11037@quotation
11038@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11039does not show the symbol name and filename of the referent, even with
11040the appropriate @code{set print} options turned on.
11041@end quotation
11042
9cb709b6
TT
11043You can also enable @samp{/a}-like formatting all the time using
11044@samp{set print symbol on}:
11045
3345721a 11046@anchor{set print symbol}
9cb709b6
TT
11047@table @code
11048@item set print symbol on
11049Tell @value{GDBN} to print the symbol corresponding to an address, if
11050one exists.
11051
11052@item set print symbol off
11053Tell @value{GDBN} not to print the symbol corresponding to an
11054address. In this mode, @value{GDBN} will still print the symbol
11055corresponding to pointers to functions. This is the default.
11056
11057@item show print symbol
11058Show whether @value{GDBN} will display the symbol corresponding to an
11059address.
11060@end table
11061
c906108c
SS
11062Other settings control how different kinds of objects are printed:
11063
11064@table @code
3345721a 11065@anchor{set print array}
c906108c
SS
11066@item set print array
11067@itemx set print array on
4644b6e3 11068@cindex pretty print arrays
c906108c
SS
11069Pretty print arrays. This format is more convenient to read,
11070but uses more space. The default is off.
11071
11072@item set print array off
11073Return to compressed format for arrays.
11074
c906108c
SS
11075@item show print array
11076Show whether compressed or pretty format is selected for displaying
11077arrays.
11078
3c9c013a 11079@cindex print array indexes
3345721a 11080@anchor{set print array-indexes}
3c9c013a
JB
11081@item set print array-indexes
11082@itemx set print array-indexes on
11083Print the index of each element when displaying arrays. May be more
11084convenient to locate a given element in the array or quickly find the
11085index of a given element in that printed array. The default is off.
11086
11087@item set print array-indexes off
11088Stop printing element indexes when displaying arrays.
11089
11090@item show print array-indexes
11091Show whether the index of each element is printed when displaying
11092arrays.
11093
3345721a 11094@anchor{set print elements}
c906108c 11095@item set print elements @var{number-of-elements}
f81d1120 11096@itemx set print elements unlimited
4644b6e3 11097@cindex number of array elements to print
9c16f35a 11098@cindex limit on number of printed array elements
c906108c
SS
11099Set a limit on how many elements of an array @value{GDBN} will print.
11100If @value{GDBN} is printing a large array, it stops printing after it has
11101printed the number of elements set by the @code{set print elements} command.
11102This limit also applies to the display of strings.
d4f3574e 11103When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
11104Setting @var{number-of-elements} to @code{unlimited} or zero means
11105that the number of elements to print is unlimited.
c906108c 11106
c906108c
SS
11107@item show print elements
11108Display the number of elements of a large array that @value{GDBN} will print.
11109If the number is 0, then the printing is unlimited.
11110
3345721a 11111@anchor{set print frame-arguments}
b4740add 11112@item set print frame-arguments @var{value}
a0381d3a 11113@kindex set print frame-arguments
b4740add
JB
11114@cindex printing frame argument values
11115@cindex print all frame argument values
11116@cindex print frame argument values for scalars only
bc4268a5 11117@cindex do not print frame arguments
b4740add
JB
11118This command allows to control how the values of arguments are printed
11119when the debugger prints a frame (@pxref{Frames}). The possible
11120values are:
11121
11122@table @code
11123@item all
4f5376b2 11124The values of all arguments are printed.
b4740add
JB
11125
11126@item scalars
11127Print the value of an argument only if it is a scalar. The value of more
11128complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11129by @code{@dots{}}. This is the default. Here is an example where
11130only scalar arguments are shown:
b4740add
JB
11131
11132@smallexample
11133#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11134 at frame-args.c:23
11135@end smallexample
11136
11137@item none
11138None of the argument values are printed. Instead, the value of each argument
11139is replaced by @code{@dots{}}. In this case, the example above now becomes:
11140
11141@smallexample
11142#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11143 at frame-args.c:23
11144@end smallexample
bc4268a5
PW
11145
11146@item presence
11147Only the presence of arguments is indicated by @code{@dots{}}.
11148The @code{@dots{}} are not printed for function without any arguments.
11149None of the argument names and values are printed.
11150In this case, the example above now becomes:
11151
11152@smallexample
11153#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11154@end smallexample
11155
b4740add
JB
11156@end table
11157
4f5376b2
JB
11158By default, only scalar arguments are printed. This command can be used
11159to configure the debugger to print the value of all arguments, regardless
11160of their type. However, it is often advantageous to not print the value
11161of more complex parameters. For instance, it reduces the amount of
11162information printed in each frame, making the backtrace more readable.
11163Also, it improves performance when displaying Ada frames, because
11164the computation of large arguments can sometimes be CPU-intensive,
11165especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11166to @code{scalars} (the default), @code{none} or @code{presence} avoids
11167this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11168
11169@item show print frame-arguments
11170Show how the value of arguments should be displayed when printing a frame.
11171
3345721a 11172@anchor{set print raw-frame-arguments}
2daf894e 11173@item set print raw-frame-arguments on
e7045703
DE
11174Print frame arguments in raw, non pretty-printed, form.
11175
2daf894e 11176@item set print raw-frame-arguments off
e7045703
DE
11177Print frame arguments in pretty-printed form, if there is a pretty-printer
11178for the value (@pxref{Pretty Printing}),
11179otherwise print the value in raw form.
11180This is the default.
11181
2daf894e 11182@item show print raw-frame-arguments
e7045703
DE
11183Show whether to print frame arguments in raw form.
11184
36b11add 11185@anchor{set print entry-values}
e18b2753
JK
11186@item set print entry-values @var{value}
11187@kindex set print entry-values
11188Set printing of frame argument values at function entry. In some cases
11189@value{GDBN} can determine the value of function argument which was passed by
11190the function caller, even if the value was modified inside the called function
11191and therefore is different. With optimized code, the current value could be
11192unavailable, but the entry value may still be known.
11193
11194The default value is @code{default} (see below for its description). Older
11195@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11196this feature will behave in the @code{default} setting the same way as with the
11197@code{no} setting.
11198
11199This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11200the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11201@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11202this information.
11203
11204The @var{value} parameter can be one of the following:
11205
11206@table @code
11207@item no
11208Print only actual parameter values, never print values from function entry
11209point.
11210@smallexample
11211#0 equal (val=5)
11212#0 different (val=6)
11213#0 lost (val=<optimized out>)
11214#0 born (val=10)
11215#0 invalid (val=<optimized out>)
11216@end smallexample
11217
11218@item only
11219Print only parameter values from function entry point. The actual parameter
11220values are never printed.
11221@smallexample
11222#0 equal (val@@entry=5)
11223#0 different (val@@entry=5)
11224#0 lost (val@@entry=5)
11225#0 born (val@@entry=<optimized out>)
11226#0 invalid (val@@entry=<optimized out>)
11227@end smallexample
11228
11229@item preferred
11230Print only parameter values from function entry point. If value from function
11231entry point is not known while the actual value is known, print the actual
11232value for such parameter.
11233@smallexample
11234#0 equal (val@@entry=5)
11235#0 different (val@@entry=5)
11236#0 lost (val@@entry=5)
11237#0 born (val=10)
11238#0 invalid (val@@entry=<optimized out>)
11239@end smallexample
11240
11241@item if-needed
11242Print actual parameter values. If actual parameter value is not known while
11243value from function entry point is known, print the entry point value for such
11244parameter.
11245@smallexample
11246#0 equal (val=5)
11247#0 different (val=6)
11248#0 lost (val@@entry=5)
11249#0 born (val=10)
11250#0 invalid (val=<optimized out>)
11251@end smallexample
11252
11253@item both
11254Always print both the actual parameter value and its value from function entry
11255point, even if values of one or both are not available due to compiler
11256optimizations.
11257@smallexample
11258#0 equal (val=5, val@@entry=5)
11259#0 different (val=6, val@@entry=5)
11260#0 lost (val=<optimized out>, val@@entry=5)
11261#0 born (val=10, val@@entry=<optimized out>)
11262#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11263@end smallexample
11264
11265@item compact
11266Print the actual parameter value if it is known and also its value from
11267function entry point if it is known. If neither is known, print for the actual
11268value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11269values are known and identical, print the shortened
11270@code{param=param@@entry=VALUE} notation.
11271@smallexample
11272#0 equal (val=val@@entry=5)
11273#0 different (val=6, val@@entry=5)
11274#0 lost (val@@entry=5)
11275#0 born (val=10)
11276#0 invalid (val=<optimized out>)
11277@end smallexample
11278
11279@item default
11280Always print the actual parameter value. Print also its value from function
11281entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11282if both values are known and identical, print the shortened
11283@code{param=param@@entry=VALUE} notation.
11284@smallexample
11285#0 equal (val=val@@entry=5)
11286#0 different (val=6, val@@entry=5)
11287#0 lost (val=<optimized out>, val@@entry=5)
11288#0 born (val=10)
11289#0 invalid (val=<optimized out>)
11290@end smallexample
11291@end table
11292
11293For analysis messages on possible failures of frame argument values at function
11294entry resolution see @ref{set debug entry-values}.
11295
11296@item show print entry-values
11297Show the method being used for printing of frame argument values at function
11298entry.
11299
bc4268a5
PW
11300@anchor{set print frame-info}
11301@item set print frame-info @var{value}
11302@kindex set print frame-info
11303@cindex printing frame information
11304@cindex frame information, printing
11305This command allows to control the information printed when
11306the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11307for a general explanation about frames and frame information.
11308Note that some other settings (such as @code{set print frame-arguments}
11309and @code{set print address}) are also influencing if and how some frame
11310information is displayed. In particular, the frame program counter is never
11311printed if @code{set print address} is off.
11312
11313The possible values for @code{set print frame-info} are:
11314@table @code
11315@item short-location
11316Print the frame level, the program counter (if not at the
11317beginning of the location source line), the function, the function
11318arguments.
11319@item location
11320Same as @code{short-location} but also print the source file and source line
11321number.
11322@item location-and-address
11323Same as @code{location} but print the program counter even if located at the
11324beginning of the location source line.
11325@item source-line
11326Print the program counter (if not at the beginning of the location
11327source line), the line number and the source line.
11328@item source-and-location
11329Print what @code{location} and @code{source-line} are printing.
11330@item auto
11331The information printed for a frame is decided automatically
11332by the @value{GDBN} command that prints a frame.
11333For example, @code{frame} prints the information printed by
11334@code{source-and-location} while @code{stepi} will switch between
11335@code{source-line} and @code{source-and-location} depending on the program
11336counter.
11337The default value is @code{auto}.
11338@end table
11339
3345721a 11340@anchor{set print repeats}
f81d1120
PA
11341@item set print repeats @var{number-of-repeats}
11342@itemx set print repeats unlimited
9c16f35a
EZ
11343@cindex repeated array elements
11344Set the threshold for suppressing display of repeated array
d3e8051b 11345elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11346array exceeds the threshold, @value{GDBN} prints the string
11347@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11348identical repetitions, instead of displaying the identical elements
f81d1120
PA
11349themselves. Setting the threshold to @code{unlimited} or zero will
11350cause all elements to be individually printed. The default threshold
11351is 10.
9c16f35a
EZ
11352
11353@item show print repeats
11354Display the current threshold for printing repeated identical
11355elements.
11356
3345721a 11357@anchor{set print max-depth}
2e62ab40
AB
11358@item set print max-depth @var{depth}
11359@item set print max-depth unlimited
11360@cindex printing nested structures
11361Set the threshold after which nested structures are replaced with
11362ellipsis, this can make visualising deeply nested structures easier.
11363
11364For example, given this C code
11365
11366@smallexample
11367typedef struct s1 @{ int a; @} s1;
11368typedef struct s2 @{ s1 b; @} s2;
11369typedef struct s3 @{ s2 c; @} s3;
11370typedef struct s4 @{ s3 d; @} s4;
11371
11372s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11373@end smallexample
11374
11375The following table shows how different values of @var{depth} will
11376effect how @code{var} is printed by @value{GDBN}:
11377
11378@multitable @columnfractions .3 .7
11379@headitem @var{depth} setting @tab Result of @samp{p var}
11380@item unlimited
11381@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11382@item @code{0}
11383@tab @code{$1 = @{...@}}
11384@item @code{1}
11385@tab @code{$1 = @{d = @{...@}@}}
11386@item @code{2}
11387@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11388@item @code{3}
11389@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11390@item @code{4}
11391@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11392@end multitable
11393
11394To see the contents of structures that have been hidden the user can
11395either increase the print max-depth, or they can print the elements of
11396the structure that are visible, for example
11397
11398@smallexample
11399(gdb) set print max-depth 2
11400(gdb) p var
11401$1 = @{d = @{c = @{...@}@}@}
11402(gdb) p var.d
11403$2 = @{c = @{b = @{...@}@}@}
11404(gdb) p var.d.c
11405$3 = @{b = @{a = 3@}@}
11406@end smallexample
11407
11408The pattern used to replace nested structures varies based on
11409language, for most languages @code{@{...@}} is used, but Fortran uses
11410@code{(...)}.
11411
11412@item show print max-depth
11413Display the current threshold after which nested structures are
11414replaces with ellipsis.
11415
3345721a 11416@anchor{set print null-stop}
c906108c 11417@item set print null-stop
4644b6e3 11418@cindex @sc{null} elements in arrays
c906108c 11419Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11420@sc{null} is encountered. This is useful when large arrays actually
c906108c 11421contain only short strings.
d4f3574e 11422The default is off.
c906108c 11423
9c16f35a
EZ
11424@item show print null-stop
11425Show whether @value{GDBN} stops printing an array on the first
11426@sc{null} character.
11427
3345721a 11428@anchor{set print pretty}
c906108c 11429@item set print pretty on
9c16f35a
EZ
11430@cindex print structures in indented form
11431@cindex indentation in structure display
5d161b24 11432Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11433per line, like this:
11434
11435@smallexample
11436@group
11437$1 = @{
11438 next = 0x0,
11439 flags = @{
11440 sweet = 1,
11441 sour = 1
11442 @},
11443 meat = 0x54 "Pork"
11444@}
11445@end group
11446@end smallexample
11447
11448@item set print pretty off
11449Cause @value{GDBN} to print structures in a compact format, like this:
11450
11451@smallexample
11452@group
11453$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11454meat = 0x54 "Pork"@}
11455@end group
11456@end smallexample
11457
11458@noindent
11459This is the default format.
11460
c906108c
SS
11461@item show print pretty
11462Show which format @value{GDBN} is using to print structures.
11463
d8edc8b7
PW
11464@anchor{set print raw-values}
11465@item set print raw-values on
11466Print values in raw form, without applying the pretty
11467printers for the value.
11468
11469@item set print raw-values off
11470Print values in pretty-printed form, if there is a pretty-printer
11471for the value (@pxref{Pretty Printing}),
11472otherwise print the value in raw form.
11473
11474The default setting is ``off''.
11475
11476@item show print raw-values
11477Show whether to print values in raw form.
11478
c906108c 11479@item set print sevenbit-strings on
4644b6e3
EZ
11480@cindex eight-bit characters in strings
11481@cindex octal escapes in strings
c906108c
SS
11482Print using only seven-bit characters; if this option is set,
11483@value{GDBN} displays any eight-bit characters (in strings or
11484character values) using the notation @code{\}@var{nnn}. This setting is
11485best if you are working in English (@sc{ascii}) and you use the
11486high-order bit of characters as a marker or ``meta'' bit.
11487
11488@item set print sevenbit-strings off
11489Print full eight-bit characters. This allows the use of more
11490international character sets, and is the default.
11491
c906108c
SS
11492@item show print sevenbit-strings
11493Show whether or not @value{GDBN} is printing only seven-bit characters.
11494
3345721a 11495@anchor{set print union}
c906108c 11496@item set print union on
4644b6e3 11497@cindex unions in structures, printing
9c16f35a
EZ
11498Tell @value{GDBN} to print unions which are contained in structures
11499and other unions. This is the default setting.
c906108c
SS
11500
11501@item set print union off
9c16f35a
EZ
11502Tell @value{GDBN} not to print unions which are contained in
11503structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11504instead.
c906108c 11505
c906108c
SS
11506@item show print union
11507Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11508structures and other unions.
c906108c
SS
11509
11510For example, given the declarations
11511
11512@smallexample
11513typedef enum @{Tree, Bug@} Species;
11514typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11515typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11516 Bug_forms;
11517
11518struct thing @{
11519 Species it;
11520 union @{
11521 Tree_forms tree;
11522 Bug_forms bug;
11523 @} form;
11524@};
11525
11526struct thing foo = @{Tree, @{Acorn@}@};
11527@end smallexample
11528
11529@noindent
11530with @code{set print union on} in effect @samp{p foo} would print
11531
11532@smallexample
11533$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11534@end smallexample
11535
11536@noindent
11537and with @code{set print union off} in effect it would print
11538
11539@smallexample
11540$1 = @{it = Tree, form = @{...@}@}
11541@end smallexample
9c16f35a
EZ
11542
11543@noindent
11544@code{set print union} affects programs written in C-like languages
11545and in Pascal.
c906108c
SS
11546@end table
11547
c906108c
SS
11548@need 1000
11549@noindent
b37052ae 11550These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11551
11552@table @code
4644b6e3 11553@cindex demangling C@t{++} names
c906108c
SS
11554@item set print demangle
11555@itemx set print demangle on
b37052ae 11556Print C@t{++} names in their source form rather than in the encoded
c906108c 11557(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11558linkage. The default is on.
c906108c 11559
c906108c 11560@item show print demangle
b37052ae 11561Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11562
c906108c
SS
11563@item set print asm-demangle
11564@itemx set print asm-demangle on
b37052ae 11565Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11566in assembler code printouts such as instruction disassemblies.
11567The default is off.
11568
c906108c 11569@item show print asm-demangle
b37052ae 11570Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11571or demangled form.
11572
b37052ae
EZ
11573@cindex C@t{++} symbol decoding style
11574@cindex symbol decoding style, C@t{++}
a8f24a35 11575@kindex set demangle-style
c906108c 11576@item set demangle-style @var{style}
041be526
SM
11577Choose among several encoding schemes used by different compilers to represent
11578C@t{++} names. If you omit @var{style}, you will see a list of possible
11579formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11580decoding style by inspecting your program.
c906108c 11581
c906108c 11582@item show demangle-style
b37052ae 11583Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11584
3345721a 11585@anchor{set print object}
c906108c
SS
11586@item set print object
11587@itemx set print object on
4644b6e3 11588@cindex derived type of an object, printing
9c16f35a 11589@cindex display derived types
c906108c
SS
11590When displaying a pointer to an object, identify the @emph{actual}
11591(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11592the virtual function table. Note that the virtual function table is
11593required---this feature can only work for objects that have run-time
11594type identification; a single virtual method in the object's declared
8264ba82
AG
11595type is sufficient. Note that this setting is also taken into account when
11596working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11597
11598@item set print object off
11599Display only the declared type of objects, without reference to the
11600virtual function table. This is the default setting.
11601
c906108c
SS
11602@item show print object
11603Show whether actual, or declared, object types are displayed.
11604
3345721a 11605@anchor{set print static-members}
c906108c
SS
11606@item set print static-members
11607@itemx set print static-members on
4644b6e3 11608@cindex static members of C@t{++} objects
b37052ae 11609Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11610
11611@item set print static-members off
b37052ae 11612Do not print static members when displaying a C@t{++} object.
c906108c 11613
c906108c 11614@item show print static-members
9c16f35a
EZ
11615Show whether C@t{++} static members are printed or not.
11616
11617@item set print pascal_static-members
11618@itemx set print pascal_static-members on
d3e8051b
EZ
11619@cindex static members of Pascal objects
11620@cindex Pascal objects, static members display
9c16f35a
EZ
11621Print static members when displaying a Pascal object. The default is on.
11622
11623@item set print pascal_static-members off
11624Do not print static members when displaying a Pascal object.
11625
11626@item show print pascal_static-members
11627Show whether Pascal static members are printed or not.
c906108c
SS
11628
11629@c These don't work with HP ANSI C++ yet.
3345721a 11630@anchor{set print vtbl}
c906108c
SS
11631@item set print vtbl
11632@itemx set print vtbl on
4644b6e3 11633@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11634@cindex virtual functions (C@t{++}) display
11635@cindex VTBL display
b37052ae 11636Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11637(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11638ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11639
11640@item set print vtbl off
b37052ae 11641Do not pretty print C@t{++} virtual function tables.
c906108c 11642
c906108c 11643@item show print vtbl
b37052ae 11644Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11645@end table
c906108c 11646
4c374409
JK
11647@node Pretty Printing
11648@section Pretty Printing
11649
11650@value{GDBN} provides a mechanism to allow pretty-printing of values using
11651Python code. It greatly simplifies the display of complex objects. This
11652mechanism works for both MI and the CLI.
11653
7b51bc51
DE
11654@menu
11655* Pretty-Printer Introduction:: Introduction to pretty-printers
11656* Pretty-Printer Example:: An example pretty-printer
11657* Pretty-Printer Commands:: Pretty-printer commands
11658@end menu
11659
11660@node Pretty-Printer Introduction
11661@subsection Pretty-Printer Introduction
11662
11663When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11664registered for the value. If there is then @value{GDBN} invokes the
11665pretty-printer to print the value. Otherwise the value is printed normally.
11666
11667Pretty-printers are normally named. This makes them easy to manage.
11668The @samp{info pretty-printer} command will list all the installed
11669pretty-printers with their names.
11670If a pretty-printer can handle multiple data types, then its
11671@dfn{subprinters} are the printers for the individual data types.
11672Each such subprinter has its own name.
4e04c971 11673The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11674
11675Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11676Typically they are automatically loaded and registered when the corresponding
11677debug information is loaded, thus making them available without having to
11678do anything special.
11679
11680There are three places where a pretty-printer can be registered.
11681
11682@itemize @bullet
11683@item
11684Pretty-printers registered globally are available when debugging
11685all inferiors.
11686
11687@item
11688Pretty-printers registered with a program space are available only
11689when debugging that program.
11690@xref{Progspaces In Python}, for more details on program spaces in Python.
11691
11692@item
11693Pretty-printers registered with an objfile are loaded and unloaded
11694with the corresponding objfile (e.g., shared library).
11695@xref{Objfiles In Python}, for more details on objfiles in Python.
11696@end itemize
11697
11698@xref{Selecting Pretty-Printers}, for further information on how
11699pretty-printers are selected,
11700
11701@xref{Writing a Pretty-Printer}, for implementing pretty printers
11702for new types.
11703
11704@node Pretty-Printer Example
11705@subsection Pretty-Printer Example
11706
11707Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11708
11709@smallexample
11710(@value{GDBP}) print s
11711$1 = @{
11712 static npos = 4294967295,
11713 _M_dataplus = @{
11714 <std::allocator<char>> = @{
11715 <__gnu_cxx::new_allocator<char>> = @{
11716 <No data fields>@}, <No data fields>
11717 @},
11718 members of std::basic_string<char, std::char_traits<char>,
11719 std::allocator<char> >::_Alloc_hider:
11720 _M_p = 0x804a014 "abcd"
11721 @}
11722@}
11723@end smallexample
11724
11725With a pretty-printer for @code{std::string} only the contents are printed:
11726
11727@smallexample
11728(@value{GDBP}) print s
11729$2 = "abcd"
11730@end smallexample
11731
7b51bc51
DE
11732@node Pretty-Printer Commands
11733@subsection Pretty-Printer Commands
11734@cindex pretty-printer commands
11735
11736@table @code
11737@kindex info pretty-printer
11738@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11739Print the list of installed pretty-printers.
11740This includes disabled pretty-printers, which are marked as such.
11741
11742@var{object-regexp} is a regular expression matching the objects
11743whose pretty-printers to list.
11744Objects can be @code{global}, the program space's file
11745(@pxref{Progspaces In Python}),
11746and the object files within that program space (@pxref{Objfiles In Python}).
11747@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11748looks up a printer from these three objects.
11749
11750@var{name-regexp} is a regular expression matching the name of the printers
11751to list.
11752
11753@kindex disable pretty-printer
11754@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11755Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11756A disabled pretty-printer is not forgotten, it may be enabled again later.
11757
11758@kindex enable pretty-printer
11759@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11760Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11761@end table
11762
11763Example:
11764
11765Suppose we have three pretty-printers installed: one from library1.so
11766named @code{foo} that prints objects of type @code{foo}, and
11767another from library2.so named @code{bar} that prints two types of objects,
11768@code{bar1} and @code{bar2}.
11769
11770@smallexample
11771(gdb) info pretty-printer
11772library1.so:
11773 foo
11774library2.so:
11775 bar
11776 bar1
11777 bar2
11778(gdb) info pretty-printer library2
11779library2.so:
11780 bar
11781 bar1
11782 bar2
11783(gdb) disable pretty-printer library1
117841 printer disabled
117852 of 3 printers enabled
11786(gdb) info pretty-printer
11787library1.so:
11788 foo [disabled]
11789library2.so:
11790 bar
11791 bar1
11792 bar2
088a96da 11793(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
117941 printer disabled
117951 of 3 printers enabled
11796(gdb) info pretty-printer library2
11797library1.so:
11798 foo [disabled]
11799library2.so:
11800 bar
11801 bar1 [disabled]
11802 bar2
11803(gdb) disable pretty-printer library2 bar
118041 printer disabled
118050 of 3 printers enabled
11806(gdb) info pretty-printer library2
11807library1.so:
11808 foo [disabled]
11809library2.so:
11810 bar [disabled]
11811 bar1 [disabled]
11812 bar2
11813@end smallexample
11814
11815Note that for @code{bar} the entire printer can be disabled,
11816as can each individual subprinter.
4c374409 11817
d8edc8b7
PW
11818Printing values and frame arguments is done by default using
11819the enabled pretty printers.
11820
11821The print option @code{-raw-values} and @value{GDBN} setting
11822@code{set print raw-values} (@pxref{set print raw-values}) can be
11823used to print values without applying the enabled pretty printers.
11824
11825Similarly, the backtrace option @code{-raw-frame-arguments} and
11826@value{GDBN} setting @code{set print raw-frame-arguments}
11827(@pxref{set print raw-frame-arguments}) can be used to ignore the
11828enabled pretty printers when printing frame argument values.
11829
6d2ebf8b 11830@node Value History
79a6e687 11831@section Value History
c906108c
SS
11832
11833@cindex value history
9c16f35a 11834@cindex history of values printed by @value{GDBN}
5d161b24
DB
11835Values printed by the @code{print} command are saved in the @value{GDBN}
11836@dfn{value history}. This allows you to refer to them in other expressions.
11837Values are kept until the symbol table is re-read or discarded
11838(for example with the @code{file} or @code{symbol-file} commands).
11839When the symbol table changes, the value history is discarded,
11840since the values may contain pointers back to the types defined in the
c906108c
SS
11841symbol table.
11842
11843@cindex @code{$}
11844@cindex @code{$$}
11845@cindex history number
11846The values printed are given @dfn{history numbers} by which you can
11847refer to them. These are successive integers starting with one.
11848@code{print} shows you the history number assigned to a value by
11849printing @samp{$@var{num} = } before the value; here @var{num} is the
11850history number.
11851
11852To refer to any previous value, use @samp{$} followed by the value's
11853history number. The way @code{print} labels its output is designed to
11854remind you of this. Just @code{$} refers to the most recent value in
11855the history, and @code{$$} refers to the value before that.
11856@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11857is the value just prior to @code{$$}, @code{$$1} is equivalent to
11858@code{$$}, and @code{$$0} is equivalent to @code{$}.
11859
11860For example, suppose you have just printed a pointer to a structure and
11861want to see the contents of the structure. It suffices to type
11862
474c8240 11863@smallexample
c906108c 11864p *$
474c8240 11865@end smallexample
c906108c
SS
11866
11867If you have a chain of structures where the component @code{next} points
11868to the next one, you can print the contents of the next one with this:
11869
474c8240 11870@smallexample
c906108c 11871p *$.next
474c8240 11872@end smallexample
c906108c
SS
11873
11874@noindent
11875You can print successive links in the chain by repeating this
11876command---which you can do by just typing @key{RET}.
11877
11878Note that the history records values, not expressions. If the value of
11879@code{x} is 4 and you type these commands:
11880
474c8240 11881@smallexample
c906108c
SS
11882print x
11883set x=5
474c8240 11884@end smallexample
c906108c
SS
11885
11886@noindent
11887then the value recorded in the value history by the @code{print} command
11888remains 4 even though the value of @code{x} has changed.
11889
11890@table @code
11891@kindex show values
11892@item show values
11893Print the last ten values in the value history, with their item numbers.
11894This is like @samp{p@ $$9} repeated ten times, except that @code{show
11895values} does not change the history.
11896
11897@item show values @var{n}
11898Print ten history values centered on history item number @var{n}.
11899
11900@item show values +
11901Print ten history values just after the values last printed. If no more
11902values are available, @code{show values +} produces no display.
11903@end table
11904
11905Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11906same effect as @samp{show values +}.
11907
6d2ebf8b 11908@node Convenience Vars
79a6e687 11909@section Convenience Variables
c906108c
SS
11910
11911@cindex convenience variables
9c16f35a 11912@cindex user-defined variables
c906108c
SS
11913@value{GDBN} provides @dfn{convenience variables} that you can use within
11914@value{GDBN} to hold on to a value and refer to it later. These variables
11915exist entirely within @value{GDBN}; they are not part of your program, and
11916setting a convenience variable has no direct effect on further execution
11917of your program. That is why you can use them freely.
11918
11919Convenience variables are prefixed with @samp{$}. Any name preceded by
11920@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11921the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11922(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11923by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11924
11925You can save a value in a convenience variable with an assignment
11926expression, just as you would set a variable in your program.
11927For example:
11928
474c8240 11929@smallexample
c906108c 11930set $foo = *object_ptr
474c8240 11931@end smallexample
c906108c
SS
11932
11933@noindent
11934would save in @code{$foo} the value contained in the object pointed to by
11935@code{object_ptr}.
11936
11937Using a convenience variable for the first time creates it, but its
11938value is @code{void} until you assign a new value. You can alter the
11939value with another assignment at any time.
11940
11941Convenience variables have no fixed types. You can assign a convenience
11942variable any type of value, including structures and arrays, even if
11943that variable already has a value of a different type. The convenience
11944variable, when used as an expression, has the type of its current value.
11945
11946@table @code
11947@kindex show convenience
f47f77df 11948@cindex show all user variables and functions
c906108c 11949@item show convenience
f47f77df
DE
11950Print a list of convenience variables used so far, and their values,
11951as well as a list of the convenience functions.
d4f3574e 11952Abbreviated @code{show conv}.
53e5f3cf
AS
11953
11954@kindex init-if-undefined
11955@cindex convenience variables, initializing
11956@item init-if-undefined $@var{variable} = @var{expression}
11957Set a convenience variable if it has not already been set. This is useful
11958for user-defined commands that keep some state. It is similar, in concept,
11959to using local static variables with initializers in C (except that
11960convenience variables are global). It can also be used to allow users to
11961override default values used in a command script.
11962
11963If the variable is already defined then the expression is not evaluated so
11964any side-effects do not occur.
c906108c
SS
11965@end table
11966
11967One of the ways to use a convenience variable is as a counter to be
11968incremented or a pointer to be advanced. For example, to print
11969a field from successive elements of an array of structures:
11970
474c8240 11971@smallexample
c906108c
SS
11972set $i = 0
11973print bar[$i++]->contents
474c8240 11974@end smallexample
c906108c 11975
d4f3574e
SS
11976@noindent
11977Repeat that command by typing @key{RET}.
c906108c
SS
11978
11979Some convenience variables are created automatically by @value{GDBN} and given
11980values likely to be useful.
11981
11982@table @code
41afff9a 11983@vindex $_@r{, convenience variable}
c906108c
SS
11984@item $_
11985The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 11986the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
11987commands which provide a default address for @code{x} to examine also
11988set @code{$_} to that address; these commands include @code{info line}
11989and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11990except when set by the @code{x} command, in which case it is a pointer
11991to the type of @code{$__}.
11992
41afff9a 11993@vindex $__@r{, convenience variable}
c906108c
SS
11994@item $__
11995The variable @code{$__} is automatically set by the @code{x} command
11996to the value found in the last address examined. Its type is chosen
11997to match the format in which the data was printed.
11998
11999@item $_exitcode
41afff9a 12000@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
12001When the program being debugged terminates normally, @value{GDBN}
12002automatically sets this variable to the exit code of the program, and
12003resets @code{$_exitsignal} to @code{void}.
12004
12005@item $_exitsignal
12006@vindex $_exitsignal@r{, convenience variable}
12007When the program being debugged dies due to an uncaught signal,
12008@value{GDBN} automatically sets this variable to that signal's number,
12009and resets @code{$_exitcode} to @code{void}.
12010
12011To distinguish between whether the program being debugged has exited
12012(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12013@code{$_exitsignal} is not @code{void}), the convenience function
12014@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12015Functions}). For example, considering the following source code:
12016
12017@smallexample
12018#include <signal.h>
12019
12020int
12021main (int argc, char *argv[])
12022@{
12023 raise (SIGALRM);
12024 return 0;
12025@}
12026@end smallexample
12027
12028A valid way of telling whether the program being debugged has exited
12029or signalled would be:
12030
12031@smallexample
12032(@value{GDBP}) define has_exited_or_signalled
12033Type commands for definition of ``has_exited_or_signalled''.
12034End with a line saying just ``end''.
12035>if $_isvoid ($_exitsignal)
12036 >echo The program has exited\n
12037 >else
12038 >echo The program has signalled\n
12039 >end
12040>end
12041(@value{GDBP}) run
12042Starting program:
12043
12044Program terminated with signal SIGALRM, Alarm clock.
12045The program no longer exists.
12046(@value{GDBP}) has_exited_or_signalled
12047The program has signalled
12048@end smallexample
12049
12050As can be seen, @value{GDBN} correctly informs that the program being
12051debugged has signalled, since it calls @code{raise} and raises a
12052@code{SIGALRM} signal. If the program being debugged had not called
12053@code{raise}, then @value{GDBN} would report a normal exit:
12054
12055@smallexample
12056(@value{GDBP}) has_exited_or_signalled
12057The program has exited
12058@end smallexample
4aa995e1 12059
72f1fe8a
TT
12060@item $_exception
12061The variable @code{$_exception} is set to the exception object being
12062thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12063
37f6a7f4
TT
12064@item $_ada_exception
12065The variable @code{$_ada_exception} is set to the address of the
12066exception being caught or thrown at an Ada exception-related
12067catchpoint. @xref{Set Catchpoints}.
12068
62e5f89c
SDJ
12069@item $_probe_argc
12070@itemx $_probe_arg0@dots{}$_probe_arg11
12071Arguments to a static probe. @xref{Static Probe Points}.
12072
0fb4aa4b
PA
12073@item $_sdata
12074@vindex $_sdata@r{, inspect, convenience variable}
12075The variable @code{$_sdata} contains extra collected static tracepoint
12076data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12077@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12078if extra static tracepoint data has not been collected.
12079
4aa995e1
PA
12080@item $_siginfo
12081@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
12082The variable @code{$_siginfo} contains extra signal information
12083(@pxref{extra signal information}). Note that @code{$_siginfo}
12084could be empty, if the application has not yet received any signals.
12085For example, it will be empty before you execute the @code{run} command.
711e434b
PM
12086
12087@item $_tlb
12088@vindex $_tlb@r{, convenience variable}
12089The variable @code{$_tlb} is automatically set when debugging
12090applications running on MS-Windows in native mode or connected to
7734102d 12091gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
12092@xref{General Query Packets}.
12093This variable contains the address of the thread information block.
12094
e3940304 12095@item $_inferior
65c574f6
PA
12096The number of the current inferior. @xref{Inferiors Connections and
12097Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 12098
5d5658a1
PA
12099@item $_thread
12100The thread number of the current thread. @xref{thread numbers}.
12101
663f6d42
PA
12102@item $_gthread
12103The global number of the current thread. @xref{global thread numbers}.
12104
7734102d
EZ
12105@item $_gdb_major
12106@itemx $_gdb_minor
12107@vindex $_gdb_major@r{, convenience variable}
12108@vindex $_gdb_minor@r{, convenience variable}
12109The major and minor version numbers of the running @value{GDBN}.
12110Development snapshots and pretest versions have their minor version
12111incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12112the value 12 for @code{$_gdb_minor}. These variables allow you to
12113write scripts that work with different versions of @value{GDBN}
12114without errors caused by features unavailable in some of those
12115versions.
e2c52041
PW
12116
12117@item $_shell_exitcode
12118@itemx $_shell_exitsignal
12119@vindex $_shell_exitcode@r{, convenience variable}
12120@vindex $_shell_exitsignal@r{, convenience variable}
12121@cindex shell command, exit code
12122@cindex shell command, exit signal
12123@cindex exit status of shell commands
12124@value{GDBN} commands such as @code{shell} and @code{|} are launching
12125shell commands. When a launched command terminates, @value{GDBN}
12126automatically maintains the variables @code{$_shell_exitcode}
12127and @code{$_shell_exitsignal} according to the exit status of the last
12128launched command. These variables are set and used similarly to
12129the variables @code{$_exitcode} and @code{$_exitsignal}.
12130
c906108c
SS
12131@end table
12132
a72c3253
DE
12133@node Convenience Funs
12134@section Convenience Functions
12135
bc3b79fd
TJB
12136@cindex convenience functions
12137@value{GDBN} also supplies some @dfn{convenience functions}. These
12138have a syntax similar to convenience variables. A convenience
12139function can be used in an expression just like an ordinary function;
12140however, a convenience function is implemented internally to
12141@value{GDBN}.
12142
a280dbd1
SDJ
12143These functions do not require @value{GDBN} to be configured with
12144@code{Python} support, which means that they are always available.
12145
12146@table @code
12147
12148@item $_isvoid (@var{expr})
12149@findex $_isvoid@r{, convenience function}
12150Return one if the expression @var{expr} is @code{void}. Otherwise it
12151returns zero.
12152
12153A @code{void} expression is an expression where the type of the result
12154is @code{void}. For example, you can examine a convenience variable
12155(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12156it is @code{void}:
12157
12158@smallexample
12159(@value{GDBP}) print $_exitcode
12160$1 = void
12161(@value{GDBP}) print $_isvoid ($_exitcode)
12162$2 = 1
12163(@value{GDBP}) run
12164Starting program: ./a.out
12165[Inferior 1 (process 29572) exited normally]
12166(@value{GDBP}) print $_exitcode
12167$3 = 0
12168(@value{GDBP}) print $_isvoid ($_exitcode)
12169$4 = 0
12170@end smallexample
12171
12172In the example above, we used @code{$_isvoid} to check whether
12173@code{$_exitcode} is @code{void} before and after the execution of the
12174program being debugged. Before the execution there is no exit code to
12175be examined, therefore @code{$_exitcode} is @code{void}. After the
12176execution the program being debugged returned zero, therefore
12177@code{$_exitcode} is zero, which means that it is not @code{void}
12178anymore.
12179
12180The @code{void} expression can also be a call of a function from the
12181program being debugged. For example, given the following function:
12182
12183@smallexample
12184void
12185foo (void)
12186@{
12187@}
12188@end smallexample
12189
12190The result of calling it inside @value{GDBN} is @code{void}:
12191
12192@smallexample
12193(@value{GDBP}) print foo ()
12194$1 = void
12195(@value{GDBP}) print $_isvoid (foo ())
12196$2 = 1
12197(@value{GDBP}) set $v = foo ()
12198(@value{GDBP}) print $v
12199$3 = void
12200(@value{GDBP}) print $_isvoid ($v)
12201$4 = 1
12202@end smallexample
12203
aed61d02
PW
12204@item $_gdb_setting_str (@var{setting})
12205@findex $_gdb_setting_str@r{, convenience function}
12206Return the value of the @value{GDBN} @var{setting} as a string.
12207@var{setting} is any setting that can be used in a @code{set} or
12208@code{show} command (@pxref{Controlling GDB}).
12209
12210@smallexample
12211(@value{GDBP}) show print frame-arguments
12212Printing of non-scalar frame arguments is "scalars".
12213(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12214$1 = "scalars"
12215(@value{GDBP}) p $_gdb_setting_str("height")
12216$2 = "30"
12217(@value{GDBP})
12218@end smallexample
12219
12220@item $_gdb_setting (@var{setting})
12221@findex $_gdb_setting@r{, convenience function}
12222Return the value of the @value{GDBN} @var{setting}.
12223The type of the returned value depends on the setting.
12224
12225The value type for boolean and auto boolean settings is @code{int}.
12226The boolean values @code{off} and @code{on} are converted to
12227the integer values @code{0} and @code{1}. The value @code{auto} is
12228converted to the value @code{-1}.
12229
12230The value type for integer settings is either @code{unsigned int}
12231or @code{int}, depending on the setting.
12232
12233Some integer settings accept an @code{unlimited} value.
12234Depending on the setting, the @code{set} command also accepts
12235the value @code{0} or the value @code{@minus{}1} as a synonym for
12236@code{unlimited}.
12237For example, @code{set height unlimited} is equivalent to
12238@code{set height 0}.
12239
12240Some other settings that accept the @code{unlimited} value
12241use the value @code{0} to literally mean zero.
12242For example, @code{set history size 0} indicates to not
12243record any @value{GDBN} commands in the command history.
12244For such settings, @code{@minus{}1} is the synonym
12245for @code{unlimited}.
12246
12247See the documentation of the corresponding @code{set} command for
12248the numerical value equivalent to @code{unlimited}.
12249
12250The @code{$_gdb_setting} function converts the unlimited value
12251to a @code{0} or a @code{@minus{}1} value according to what the
12252@code{set} command uses.
12253
12254@smallexample
12255@group
12256(@value{GDBP}) p $_gdb_setting_str("height")
12257$1 = "30"
12258(@value{GDBP}) p $_gdb_setting("height")
12259$2 = 30
12260(@value{GDBP}) set height unlimited
12261(@value{GDBP}) p $_gdb_setting_str("height")
12262$3 = "unlimited"
12263(@value{GDBP}) p $_gdb_setting("height")
12264$4 = 0
12265@end group
12266@group
12267(@value{GDBP}) p $_gdb_setting_str("history size")
12268$5 = "unlimited"
12269(@value{GDBP}) p $_gdb_setting("history size")
12270$6 = -1
12271(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12272$7 = "auto"
12273(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12274$8 = -1
12275(@value{GDBP})
12276@end group
12277@end smallexample
12278
12279Other setting types (enum, filename, optional filename, string, string noescape)
12280are returned as string values.
12281
12282
12283@item $_gdb_maint_setting_str (@var{setting})
12284@findex $_gdb_maint_setting_str@r{, convenience function}
12285Like the @code{$_gdb_setting_str} function, but works with
12286@code{maintenance set} variables.
12287
12288@item $_gdb_maint_setting (@var{setting})
12289@findex $_gdb_maint_setting@r{, convenience function}
12290Like the @code{$_gdb_setting} function, but works with
12291@code{maintenance set} variables.
12292
a280dbd1
SDJ
12293@end table
12294
aed61d02 12295The following functions require @value{GDBN} to be configured with
a72c3253
DE
12296@code{Python} support.
12297
12298@table @code
12299
12300@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12301@findex $_memeq@r{, convenience function}
12302Returns one if the @var{length} bytes at the addresses given by
12303@var{buf1} and @var{buf2} are equal.
12304Otherwise it returns zero.
12305
12306@item $_regex(@var{str}, @var{regex})
12307@findex $_regex@r{, convenience function}
12308Returns one if the string @var{str} matches the regular expression
12309@var{regex}. Otherwise it returns zero.
12310The syntax of the regular expression is that specified by @code{Python}'s
12311regular expression support.
12312
12313@item $_streq(@var{str1}, @var{str2})
12314@findex $_streq@r{, convenience function}
12315Returns one if the strings @var{str1} and @var{str2} are equal.
12316Otherwise it returns zero.
12317
12318@item $_strlen(@var{str})
12319@findex $_strlen@r{, convenience function}
12320Returns the length of string @var{str}.
12321
faa42425
DE
12322@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12323@findex $_caller_is@r{, convenience function}
12324Returns one if the calling function's name is equal to @var{name}.
12325Otherwise it returns zero.
12326
12327If the optional argument @var{number_of_frames} is provided,
12328it is the number of frames up in the stack to look.
12329The default is 1.
12330
12331Example:
12332
12333@smallexample
12334(gdb) backtrace
12335#0 bottom_func ()
12336 at testsuite/gdb.python/py-caller-is.c:21
12337#1 0x00000000004005a0 in middle_func ()
12338 at testsuite/gdb.python/py-caller-is.c:27
12339#2 0x00000000004005ab in top_func ()
12340 at testsuite/gdb.python/py-caller-is.c:33
12341#3 0x00000000004005b6 in main ()
12342 at testsuite/gdb.python/py-caller-is.c:39
12343(gdb) print $_caller_is ("middle_func")
12344$1 = 1
12345(gdb) print $_caller_is ("top_func", 2)
12346$1 = 1
12347@end smallexample
12348
12349@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12350@findex $_caller_matches@r{, convenience function}
12351Returns one if the calling function's name matches the regular expression
12352@var{regexp}. Otherwise it returns zero.
12353
12354If the optional argument @var{number_of_frames} is provided,
12355it is the number of frames up in the stack to look.
12356The default is 1.
12357
12358@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12359@findex $_any_caller_is@r{, convenience function}
12360Returns one if any calling function's name is equal to @var{name}.
12361Otherwise it returns zero.
12362
12363If the optional argument @var{number_of_frames} is provided,
12364it is the number of frames up in the stack to look.
12365The default is 1.
12366
12367This function differs from @code{$_caller_is} in that this function
12368checks all stack frames from the immediate caller to the frame specified
12369by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12370frame specified by @var{number_of_frames}.
12371
12372@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12373@findex $_any_caller_matches@r{, convenience function}
12374Returns one if any calling function's name matches the regular expression
12375@var{regexp}. Otherwise it returns zero.
12376
12377If the optional argument @var{number_of_frames} is provided,
12378it is the number of frames up in the stack to look.
12379The default is 1.
12380
12381This function differs from @code{$_caller_matches} in that this function
12382checks all stack frames from the immediate caller to the frame specified
12383by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12384frame specified by @var{number_of_frames}.
12385
f2f3ccb9
SM
12386@item $_as_string(@var{value})
12387@findex $_as_string@r{, convenience function}
12388Return the string representation of @var{value}.
12389
12390This function is useful to obtain the textual label (enumerator) of an
12391enumeration value. For example, assuming the variable @var{node} is of
12392an enumerated type:
12393
12394@smallexample
12395(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12396Visiting node of type NODE_INTEGER
12397@end smallexample
12398
8bdc1658
AB
12399@item $_cimag(@var{value})
12400@itemx $_creal(@var{value})
12401@findex $_cimag@r{, convenience function}
12402@findex $_creal@r{, convenience function}
12403Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12404the complex number @var{value}.
12405
12406The type of the imaginary or real part depends on the type of the
12407complex number, e.g., using @code{$_cimag} on a @code{float complex}
12408will return an imaginary part of type @code{float}.
12409
a72c3253
DE
12410@end table
12411
12412@value{GDBN} provides the ability to list and get help on
12413convenience functions.
12414
bc3b79fd
TJB
12415@table @code
12416@item help function
12417@kindex help function
12418@cindex show all convenience functions
12419Print a list of all convenience functions.
12420@end table
12421
6d2ebf8b 12422@node Registers
c906108c
SS
12423@section Registers
12424
12425@cindex registers
12426You can refer to machine register contents, in expressions, as variables
12427with names starting with @samp{$}. The names of registers are different
12428for each machine; use @code{info registers} to see the names used on
12429your machine.
12430
12431@table @code
12432@kindex info registers
12433@item info registers
12434Print the names and values of all registers except floating-point
c85508ee 12435and vector registers (in the selected stack frame).
c906108c
SS
12436
12437@kindex info all-registers
12438@cindex floating point registers
12439@item info all-registers
12440Print the names and values of all registers, including floating-point
c85508ee 12441and vector registers (in the selected stack frame).
c906108c 12442
64cb3757 12443@anchor{info_registers_reggroup}
b67d92b0
SH
12444@item info registers @var{reggroup} @dots{}
12445Print the name and value of the registers in each of the specified
6b92c0d3 12446@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12447@code{maint print reggroups} (@pxref{Maintenance Commands}).
12448
c906108c
SS
12449@item info registers @var{regname} @dots{}
12450Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12451As discussed in detail below, register values are normally relative to
697aa1b7 12452the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12453the machine you are using, with or without the initial @samp{$}.
12454@end table
12455
f5b95c01 12456@anchor{standard registers}
e09f16f9
EZ
12457@cindex stack pointer register
12458@cindex program counter register
12459@cindex process status register
12460@cindex frame pointer register
12461@cindex standard registers
c906108c
SS
12462@value{GDBN} has four ``standard'' register names that are available (in
12463expressions) on most machines---whenever they do not conflict with an
12464architecture's canonical mnemonics for registers. The register names
12465@code{$pc} and @code{$sp} are used for the program counter register and
12466the stack pointer. @code{$fp} is used for a register that contains a
12467pointer to the current stack frame, and @code{$ps} is used for a
12468register that contains the processor status. For example,
12469you could print the program counter in hex with
12470
474c8240 12471@smallexample
c906108c 12472p/x $pc
474c8240 12473@end smallexample
c906108c
SS
12474
12475@noindent
12476or print the instruction to be executed next with
12477
474c8240 12478@smallexample
c906108c 12479x/i $pc
474c8240 12480@end smallexample
c906108c
SS
12481
12482@noindent
12483or add four to the stack pointer@footnote{This is a way of removing
12484one word from the stack, on machines where stacks grow downward in
12485memory (most machines, nowadays). This assumes that the innermost
12486stack frame is selected; setting @code{$sp} is not allowed when other
12487stack frames are selected. To pop entire frames off the stack,
12488regardless of machine architecture, use @code{return};
79a6e687 12489see @ref{Returning, ,Returning from a Function}.} with
c906108c 12490
474c8240 12491@smallexample
c906108c 12492set $sp += 4
474c8240 12493@end smallexample
c906108c
SS
12494
12495Whenever possible, these four standard register names are available on
12496your machine even though the machine has different canonical mnemonics,
12497so long as there is no conflict. The @code{info registers} command
12498shows the canonical names. For example, on the SPARC, @code{info
12499registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12500can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12501is an alias for the @sc{eflags} register.
c906108c
SS
12502
12503@value{GDBN} always considers the contents of an ordinary register as an
12504integer when the register is examined in this way. Some machines have
12505special registers which can hold nothing but floating point; these
12506registers are considered to have floating point values. There is no way
12507to refer to the contents of an ordinary register as floating point value
12508(although you can @emph{print} it as a floating point value with
12509@samp{print/f $@var{regname}}).
12510
12511Some registers have distinct ``raw'' and ``virtual'' data formats. This
12512means that the data format in which the register contents are saved by
12513the operating system is not the same one that your program normally
12514sees. For example, the registers of the 68881 floating point
12515coprocessor are always saved in ``extended'' (raw) format, but all C
12516programs expect to work with ``double'' (virtual) format. In such
5d161b24 12517cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12518that makes sense for your program), but the @code{info registers} command
12519prints the data in both formats.
12520
36b80e65
EZ
12521@cindex SSE registers (x86)
12522@cindex MMX registers (x86)
12523Some machines have special registers whose contents can be interpreted
12524in several different ways. For example, modern x86-based machines
12525have SSE and MMX registers that can hold several values packed
12526together in several different formats. @value{GDBN} refers to such
12527registers in @code{struct} notation:
12528
12529@smallexample
12530(@value{GDBP}) print $xmm1
12531$1 = @{
12532 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12533 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12534 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12535 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12536 v4_int32 = @{0, 20657912, 11, 13@},
12537 v2_int64 = @{88725056443645952, 55834574859@},
12538 uint128 = 0x0000000d0000000b013b36f800000000
12539@}
12540@end smallexample
12541
12542@noindent
12543To set values of such registers, you need to tell @value{GDBN} which
12544view of the register you wish to change, as if you were assigning
12545value to a @code{struct} member:
12546
12547@smallexample
12548 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12549@end smallexample
12550
c906108c 12551Normally, register values are relative to the selected stack frame
79a6e687 12552(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12553value that the register would contain if all stack frames farther in
12554were exited and their saved registers restored. In order to see the
12555true contents of hardware registers, you must select the innermost
12556frame (with @samp{frame 0}).
12557
901461f8
PA
12558@cindex caller-saved registers
12559@cindex call-clobbered registers
12560@cindex volatile registers
12561@cindex <not saved> values
12562Usually ABIs reserve some registers as not needed to be saved by the
12563callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12564registers). It may therefore not be possible for @value{GDBN} to know
12565the value a register had before the call (in other words, in the outer
12566frame), if the register value has since been changed by the callee.
12567@value{GDBN} tries to deduce where the inner frame saved
12568(``callee-saved'') registers, from the debug info, unwind info, or the
12569machine code generated by your compiler. If some register is not
12570saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12571its own knowledge of the ABI, or because the debug/unwind info
12572explicitly says the register's value is undefined), @value{GDBN}
12573displays @w{@samp{<not saved>}} as the register's value. With targets
12574that @value{GDBN} has no knowledge of the register saving convention,
12575if a register was not saved by the callee, then its value and location
12576in the outer frame are assumed to be the same of the inner frame.
12577This is usually harmless, because if the register is call-clobbered,
12578the caller either does not care what is in the register after the
12579call, or has code to restore the value that it does care about. Note,
12580however, that if you change such a register in the outer frame, you
12581may also be affecting the inner frame. Also, the more ``outer'' the
12582frame is you're looking at, the more likely a call-clobbered
12583register's value is to be wrong, in the sense that it doesn't actually
12584represent the value the register had just before the call.
c906108c 12585
6d2ebf8b 12586@node Floating Point Hardware
79a6e687 12587@section Floating Point Hardware
c906108c
SS
12588@cindex floating point
12589
12590Depending on the configuration, @value{GDBN} may be able to give
12591you more information about the status of the floating point hardware.
12592
12593@table @code
12594@kindex info float
12595@item info float
12596Display hardware-dependent information about the floating
12597point unit. The exact contents and layout vary depending on the
12598floating point chip. Currently, @samp{info float} is supported on
12599the ARM and x86 machines.
12600@end table
c906108c 12601
e76f1f2e
AC
12602@node Vector Unit
12603@section Vector Unit
12604@cindex vector unit
12605
12606Depending on the configuration, @value{GDBN} may be able to give you
12607more information about the status of the vector unit.
12608
12609@table @code
12610@kindex info vector
12611@item info vector
12612Display information about the vector unit. The exact contents and
12613layout vary depending on the hardware.
12614@end table
12615
721c2651 12616@node OS Information
79a6e687 12617@section Operating System Auxiliary Information
721c2651
EZ
12618@cindex OS information
12619
12620@value{GDBN} provides interfaces to useful OS facilities that can help
12621you debug your program.
12622
b383017d
RM
12623@cindex auxiliary vector
12624@cindex vector, auxiliary
b383017d
RM
12625Some operating systems supply an @dfn{auxiliary vector} to programs at
12626startup. This is akin to the arguments and environment that you
12627specify for a program, but contains a system-dependent variety of
12628binary values that tell system libraries important details about the
12629hardware, operating system, and process. Each value's purpose is
12630identified by an integer tag; the meanings are well-known but system-specific.
12631Depending on the configuration and operating system facilities,
9c16f35a
EZ
12632@value{GDBN} may be able to show you this information. For remote
12633targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12634support of the @samp{qXfer:auxv:read} packet, see
12635@ref{qXfer auxiliary vector read}.
b383017d
RM
12636
12637@table @code
12638@kindex info auxv
12639@item info auxv
12640Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12641live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12642numerically, and also shows names and text descriptions for recognized
12643tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12644pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12645most appropriate form for a recognized tag, and in hexadecimal for
12646an unrecognized tag.
12647@end table
12648
85d4a676
SS
12649On some targets, @value{GDBN} can access operating system-specific
12650information and show it to you. The types of information available
12651will differ depending on the type of operating system running on the
12652target. The mechanism used to fetch the data is described in
12653@ref{Operating System Information}. For remote targets, this
12654functionality depends on the remote stub's support of the
07e059b5
VP
12655@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12656
12657@table @code
a61408f8 12658@kindex info os
85d4a676
SS
12659@item info os @var{infotype}
12660
12661Display OS information of the requested type.
a61408f8 12662
85d4a676
SS
12663On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12664
12665@anchor{linux info os infotypes}
12666@table @code
d33279b3
AT
12667@kindex info os cpus
12668@item cpus
12669Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12670the available fields from /proc/cpuinfo. For each supported architecture
12671different fields are available. Two common entries are processor which gives
12672CPU number and bogomips; a system constant that is calculated during
12673kernel initialization.
12674
12675@kindex info os files
12676@item files
12677Display the list of open file descriptors on the target. For each
12678file descriptor, @value{GDBN} prints the identifier of the process
12679owning the descriptor, the command of the owning process, the value
12680of the descriptor, and the target of the descriptor.
12681
12682@kindex info os modules
12683@item modules
12684Display the list of all loaded kernel modules on the target. For each
12685module, @value{GDBN} prints the module name, the size of the module in
12686bytes, the number of times the module is used, the dependencies of the
12687module, the status of the module, and the address of the loaded module
12688in memory.
12689
12690@kindex info os msg
12691@item msg
12692Display the list of all System V message queues on the target. For each
12693message queue, @value{GDBN} prints the message queue key, the message
12694queue identifier, the access permissions, the current number of bytes
12695on the queue, the current number of messages on the queue, the processes
12696that last sent and received a message on the queue, the user and group
12697of the owner and creator of the message queue, the times at which a
12698message was last sent and received on the queue, and the time at which
12699the message queue was last changed.
12700
07e059b5 12701@kindex info os processes
85d4a676 12702@item processes
07e059b5 12703Display the list of processes on the target. For each process,
85d4a676
SS
12704@value{GDBN} prints the process identifier, the name of the user, the
12705command corresponding to the process, and the list of processor cores
12706that the process is currently running on. (To understand what these
12707properties mean, for this and the following info types, please consult
12708the general @sc{gnu}/Linux documentation.)
12709
12710@kindex info os procgroups
12711@item procgroups
12712Display the list of process groups on the target. For each process,
12713@value{GDBN} prints the identifier of the process group that it belongs
12714to, the command corresponding to the process group leader, the process
12715identifier, and the command line of the process. The list is sorted
12716first by the process group identifier, then by the process identifier,
12717so that processes belonging to the same process group are grouped together
12718and the process group leader is listed first.
12719
d33279b3
AT
12720@kindex info os semaphores
12721@item semaphores
12722Display the list of all System V semaphore sets on the target. For each
12723semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12724set identifier, the access permissions, the number of semaphores in the
12725set, the user and group of the owner and creator of the semaphore set,
12726and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12727
12728@kindex info os shm
12729@item shm
12730Display the list of all System V shared-memory regions on the target.
12731For each shared-memory region, @value{GDBN} prints the region key,
12732the shared-memory identifier, the access permissions, the size of the
12733region, the process that created the region, the process that last
12734attached to or detached from the region, the current number of live
12735attaches to the region, and the times at which the region was last
12736attached to, detach from, and changed.
12737
d33279b3
AT
12738@kindex info os sockets
12739@item sockets
12740Display the list of Internet-domain sockets on the target. For each
12741socket, @value{GDBN} prints the address and port of the local and
12742remote endpoints, the current state of the connection, the creator of
12743the socket, the IP address family of the socket, and the type of the
12744connection.
85d4a676 12745
d33279b3
AT
12746@kindex info os threads
12747@item threads
12748Display the list of threads running on the target. For each thread,
12749@value{GDBN} prints the identifier of the process that the thread
12750belongs to, the command of the process, the thread identifier, and the
12751processor core that it is currently running on. The main thread of a
12752process is not listed.
85d4a676
SS
12753@end table
12754
12755@item info os
12756If @var{infotype} is omitted, then list the possible values for
12757@var{infotype} and the kind of OS information available for each
12758@var{infotype}. If the target does not return a list of possible
12759types, this command will report an error.
07e059b5 12760@end table
721c2651 12761
29e57380 12762@node Memory Region Attributes
79a6e687 12763@section Memory Region Attributes
29e57380
C
12764@cindex memory region attributes
12765
b383017d 12766@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12767required by regions of your target's memory. @value{GDBN} uses
12768attributes to determine whether to allow certain types of memory
12769accesses; whether to use specific width accesses; and whether to cache
12770target memory. By default the description of memory regions is
12771fetched from the target (if the current target supports this), but the
12772user can override the fetched regions.
29e57380
C
12773
12774Defined memory regions can be individually enabled and disabled. When a
12775memory region is disabled, @value{GDBN} uses the default attributes when
12776accessing memory in that region. Similarly, if no memory regions have
12777been defined, @value{GDBN} uses the default attributes when accessing
12778all memory.
12779
b383017d 12780When a memory region is defined, it is given a number to identify it;
29e57380
C
12781to enable, disable, or remove a memory region, you specify that number.
12782
12783@table @code
12784@kindex mem
bfac230e 12785@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12786Define a memory region bounded by @var{lower} and @var{upper} with
12787attributes @var{attributes}@dots{}, and add it to the list of regions
12788monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12789case: it is treated as the target's maximum memory address.
bfac230e 12790(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12791
fd79ecee
DJ
12792@item mem auto
12793Discard any user changes to the memory regions and use target-supplied
12794regions, if available, or no regions if the target does not support.
12795
29e57380
C
12796@kindex delete mem
12797@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12798Remove memory regions @var{nums}@dots{} from the list of regions
12799monitored by @value{GDBN}.
29e57380
C
12800
12801@kindex disable mem
12802@item disable mem @var{nums}@dots{}
09d4efe1 12803Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12804A disabled memory region is not forgotten.
29e57380
C
12805It may be enabled again later.
12806
12807@kindex enable mem
12808@item enable mem @var{nums}@dots{}
09d4efe1 12809Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12810
12811@kindex info mem
12812@item info mem
12813Print a table of all defined memory regions, with the following columns
09d4efe1 12814for each region:
29e57380
C
12815
12816@table @emph
12817@item Memory Region Number
12818@item Enabled or Disabled.
b383017d 12819Enabled memory regions are marked with @samp{y}.
29e57380
C
12820Disabled memory regions are marked with @samp{n}.
12821
12822@item Lo Address
12823The address defining the inclusive lower bound of the memory region.
12824
12825@item Hi Address
12826The address defining the exclusive upper bound of the memory region.
12827
12828@item Attributes
12829The list of attributes set for this memory region.
12830@end table
12831@end table
12832
12833
12834@subsection Attributes
12835
b383017d 12836@subsubsection Memory Access Mode
29e57380
C
12837The access mode attributes set whether @value{GDBN} may make read or
12838write accesses to a memory region.
12839
12840While these attributes prevent @value{GDBN} from performing invalid
12841memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12842etc.@: from accessing memory.
29e57380
C
12843
12844@table @code
12845@item ro
12846Memory is read only.
12847@item wo
12848Memory is write only.
12849@item rw
6ca652b0 12850Memory is read/write. This is the default.
29e57380
C
12851@end table
12852
12853@subsubsection Memory Access Size
d3e8051b 12854The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12855accesses in the memory region. Often memory mapped device registers
12856require specific sized accesses. If no access size attribute is
12857specified, @value{GDBN} may use accesses of any size.
12858
12859@table @code
12860@item 8
12861Use 8 bit memory accesses.
12862@item 16
12863Use 16 bit memory accesses.
12864@item 32
12865Use 32 bit memory accesses.
12866@item 64
12867Use 64 bit memory accesses.
12868@end table
12869
12870@c @subsubsection Hardware/Software Breakpoints
12871@c The hardware/software breakpoint attributes set whether @value{GDBN}
12872@c will use hardware or software breakpoints for the internal breakpoints
12873@c used by the step, next, finish, until, etc. commands.
12874@c
12875@c @table @code
12876@c @item hwbreak
b383017d 12877@c Always use hardware breakpoints
29e57380
C
12878@c @item swbreak (default)
12879@c @end table
12880
12881@subsubsection Data Cache
12882The data cache attributes set whether @value{GDBN} will cache target
12883memory. While this generally improves performance by reducing debug
12884protocol overhead, it can lead to incorrect results because @value{GDBN}
12885does not know about volatile variables or memory mapped device
12886registers.
12887
12888@table @code
12889@item cache
b383017d 12890Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12891@item nocache
12892Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12893@end table
12894
4b5752d0
VP
12895@subsection Memory Access Checking
12896@value{GDBN} can be instructed to refuse accesses to memory that is
12897not explicitly described. This can be useful if accessing such
12898regions has undesired effects for a specific target, or to provide
12899better error checking. The following commands control this behaviour.
12900
12901@table @code
12902@kindex set mem inaccessible-by-default
12903@item set mem inaccessible-by-default [on|off]
12904If @code{on} is specified, make @value{GDBN} treat memory not
12905explicitly described by the memory ranges as non-existent and refuse accesses
12906to such memory. The checks are only performed if there's at least one
12907memory range defined. If @code{off} is specified, make @value{GDBN}
12908treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12909The default value is @code{on}.
4b5752d0
VP
12910@kindex show mem inaccessible-by-default
12911@item show mem inaccessible-by-default
12912Show the current handling of accesses to unknown memory.
12913@end table
12914
12915
29e57380 12916@c @subsubsection Memory Write Verification
b383017d 12917@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12918@c will re-reads data after each write to verify the write was successful.
12919@c
12920@c @table @code
12921@c @item verify
12922@c @item noverify (default)
12923@c @end table
12924
16d9dec6 12925@node Dump/Restore Files
79a6e687 12926@section Copy Between Memory and a File
16d9dec6
MS
12927@cindex dump/restore files
12928@cindex append data to a file
12929@cindex dump data to a file
12930@cindex restore data from a file
16d9dec6 12931
df5215a6
JB
12932You can use the commands @code{dump}, @code{append}, and
12933@code{restore} to copy data between target memory and a file. The
12934@code{dump} and @code{append} commands write data to a file, and the
12935@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12936memory. Files may be in binary, Motorola S-record, Intel hex,
12937Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12938append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12939
12940@table @code
12941
12942@kindex dump
12943@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12944@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12945Dump the contents of memory from @var{start_addr} to @var{end_addr},
12946or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 12947
df5215a6 12948The @var{format} parameter may be any one of:
16d9dec6 12949@table @code
df5215a6
JB
12950@item binary
12951Raw binary form.
12952@item ihex
12953Intel hex format.
12954@item srec
12955Motorola S-record format.
12956@item tekhex
12957Tektronix Hex format.
cf75d6c3
AB
12958@item verilog
12959Verilog Hex format.
df5215a6
JB
12960@end table
12961
12962@value{GDBN} uses the same definitions of these formats as the
12963@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12964@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12965form.
12966
12967@kindex append
12968@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12969@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12970Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 12971or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
12972(@value{GDBN} can only append data to files in raw binary form.)
12973
12974@kindex restore
12975@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12976Restore the contents of file @var{filename} into memory. The
12977@code{restore} command can automatically recognize any known @sc{bfd}
12978file format, except for raw binary. To restore a raw binary file you
12979must specify the optional keyword @code{binary} after the filename.
16d9dec6 12980
b383017d 12981If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
12982contained in the file. Binary files always start at address zero, so
12983they will be restored at address @var{bias}. Other bfd files have
12984a built-in location; they will be restored at offset @var{bias}
12985from that location.
12986
12987If @var{start} and/or @var{end} are non-zero, then only data between
12988file offset @var{start} and file offset @var{end} will be restored.
b383017d 12989These offsets are relative to the addresses in the file, before
16d9dec6
MS
12990the @var{bias} argument is applied.
12991
12992@end table
12993
384ee23f
EZ
12994@node Core File Generation
12995@section How to Produce a Core File from Your Program
12996@cindex dump core from inferior
12997
12998A @dfn{core file} or @dfn{core dump} is a file that records the memory
12999image of a running process and its process status (register values
13000etc.). Its primary use is post-mortem debugging of a program that
13001crashed while it ran outside a debugger. A program that crashes
13002automatically produces a core file, unless this feature is disabled by
13003the user. @xref{Files}, for information on invoking @value{GDBN} in
13004the post-mortem debugging mode.
13005
13006Occasionally, you may wish to produce a core file of the program you
13007are debugging in order to preserve a snapshot of its state.
13008@value{GDBN} has a special command for that.
13009
13010@table @code
13011@kindex gcore
13012@kindex generate-core-file
13013@item generate-core-file [@var{file}]
13014@itemx gcore [@var{file}]
13015Produce a core dump of the inferior process. The optional argument
13016@var{file} specifies the file name where to put the core dump. If not
13017specified, the file name defaults to @file{core.@var{pid}}, where
13018@var{pid} is the inferior process ID.
13019
13020Note that this command is implemented only for some systems (as of
05b4bd79 13021this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
13022
13023On @sc{gnu}/Linux, this command can take into account the value of the
13024file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
13025dump (@pxref{set use-coredump-filter}), and by default honors the
13026@code{VM_DONTDUMP} flag for mappings where it is present in the file
13027@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
13028
13029@kindex set use-coredump-filter
13030@anchor{set use-coredump-filter}
13031@item set use-coredump-filter on
13032@itemx set use-coredump-filter off
13033Enable or disable the use of the file
13034@file{/proc/@var{pid}/coredump_filter} when generating core dump
13035files. This file is used by the Linux kernel to decide what types of
13036memory mappings will be dumped or ignored when generating a core dump
13037file. @var{pid} is the process ID of a currently running process.
13038
13039To make use of this feature, you have to write in the
13040@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13041which is a bit mask representing the memory mapping types. If a bit
13042is set in the bit mask, then the memory mappings of the corresponding
13043types will be dumped; otherwise, they will be ignored. This
13044configuration is inherited by child processes. For more information
13045about the bits that can be set in the
13046@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13047manpage of @code{core(5)}.
13048
13049By default, this option is @code{on}. If this option is turned
13050@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13051and instead uses the same default value as the Linux kernel in order
13052to decide which pages will be dumped in the core dump file. This
13053value is currently @code{0x33}, which means that bits @code{0}
13054(anonymous private mappings), @code{1} (anonymous shared mappings),
13055@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13056This will cause these memory mappings to be dumped automatically.
1e52e849
SL
13057
13058@kindex set dump-excluded-mappings
13059@anchor{set dump-excluded-mappings}
13060@item set dump-excluded-mappings on
13061@itemx set dump-excluded-mappings off
13062If @code{on} is specified, @value{GDBN} will dump memory mappings
13063marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13064the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13065
13066The default value is @code{off}.
384ee23f
EZ
13067@end table
13068
a0eb71c5
KB
13069@node Character Sets
13070@section Character Sets
13071@cindex character sets
13072@cindex charset
13073@cindex translating between character sets
13074@cindex host character set
13075@cindex target character set
13076
13077If the program you are debugging uses a different character set to
13078represent characters and strings than the one @value{GDBN} uses itself,
13079@value{GDBN} can automatically translate between the character sets for
13080you. The character set @value{GDBN} uses we call the @dfn{host
13081character set}; the one the inferior program uses we call the
13082@dfn{target character set}.
13083
13084For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13085uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 13086remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
13087running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13088then the host character set is Latin-1, and the target character set is
13089@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 13090target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
13091@sc{ebcdic} and Latin 1 as you print character or string values, or use
13092character and string literals in expressions.
13093
13094@value{GDBN} has no way to automatically recognize which character set
13095the inferior program uses; you must tell it, using the @code{set
13096target-charset} command, described below.
13097
13098Here are the commands for controlling @value{GDBN}'s character set
13099support:
13100
13101@table @code
13102@item set target-charset @var{charset}
13103@kindex set target-charset
10af6951
EZ
13104Set the current target character set to @var{charset}. To display the
13105list of supported target character sets, type
13106@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 13107
a0eb71c5
KB
13108@item set host-charset @var{charset}
13109@kindex set host-charset
13110Set the current host character set to @var{charset}.
13111
13112By default, @value{GDBN} uses a host character set appropriate to the
13113system it is running on; you can override that default using the
732f6a93
TT
13114@code{set host-charset} command. On some systems, @value{GDBN} cannot
13115automatically determine the appropriate host character set. In this
13116case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
13117
13118@value{GDBN} can only use certain character sets as its host character
c1b6b909 13119set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 13120@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
13121
13122@item set charset @var{charset}
13123@kindex set charset
e33d66ec 13124Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13125above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13126@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13127for both host and target.
13128
a0eb71c5 13129@item show charset
a0eb71c5 13130@kindex show charset
10af6951 13131Show the names of the current host and target character sets.
e33d66ec 13132
10af6951 13133@item show host-charset
a0eb71c5 13134@kindex show host-charset
10af6951 13135Show the name of the current host character set.
e33d66ec 13136
10af6951 13137@item show target-charset
a0eb71c5 13138@kindex show target-charset
10af6951 13139Show the name of the current target character set.
a0eb71c5 13140
10af6951
EZ
13141@item set target-wide-charset @var{charset}
13142@kindex set target-wide-charset
13143Set the current target's wide character set to @var{charset}. This is
13144the character set used by the target's @code{wchar_t} type. To
13145display the list of supported wide character sets, type
13146@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13147
13148@item show target-wide-charset
13149@kindex show target-wide-charset
13150Show the name of the current target's wide character set.
a0eb71c5
KB
13151@end table
13152
a0eb71c5
KB
13153Here is an example of @value{GDBN}'s character set support in action.
13154Assume that the following source code has been placed in the file
13155@file{charset-test.c}:
13156
13157@smallexample
13158#include <stdio.h>
13159
13160char ascii_hello[]
13161 = @{72, 101, 108, 108, 111, 44, 32, 119,
13162 111, 114, 108, 100, 33, 10, 0@};
13163char ibm1047_hello[]
13164 = @{200, 133, 147, 147, 150, 107, 64, 166,
13165 150, 153, 147, 132, 90, 37, 0@};
13166
13167main ()
13168@{
13169 printf ("Hello, world!\n");
13170@}
10998722 13171@end smallexample
a0eb71c5
KB
13172
13173In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13174containing the string @samp{Hello, world!} followed by a newline,
13175encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13176
13177We compile the program, and invoke the debugger on it:
13178
13179@smallexample
13180$ gcc -g charset-test.c -o charset-test
13181$ gdb -nw charset-test
13182GNU gdb 2001-12-19-cvs
13183Copyright 2001 Free Software Foundation, Inc.
13184@dots{}
f7dc1244 13185(@value{GDBP})
10998722 13186@end smallexample
a0eb71c5
KB
13187
13188We can use the @code{show charset} command to see what character sets
13189@value{GDBN} is currently using to interpret and display characters and
13190strings:
13191
13192@smallexample
f7dc1244 13193(@value{GDBP}) show charset
e33d66ec 13194The current host and target character set is `ISO-8859-1'.
f7dc1244 13195(@value{GDBP})
10998722 13196@end smallexample
a0eb71c5
KB
13197
13198For the sake of printing this manual, let's use @sc{ascii} as our
13199initial character set:
13200@smallexample
f7dc1244
EZ
13201(@value{GDBP}) set charset ASCII
13202(@value{GDBP}) show charset
e33d66ec 13203The current host and target character set is `ASCII'.
f7dc1244 13204(@value{GDBP})
10998722 13205@end smallexample
a0eb71c5
KB
13206
13207Let's assume that @sc{ascii} is indeed the correct character set for our
13208host system --- in other words, let's assume that if @value{GDBN} prints
13209characters using the @sc{ascii} character set, our terminal will display
13210them properly. Since our current target character set is also
13211@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13212
13213@smallexample
f7dc1244 13214(@value{GDBP}) print ascii_hello
a0eb71c5 13215$1 = 0x401698 "Hello, world!\n"
f7dc1244 13216(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13217$2 = 72 'H'
f7dc1244 13218(@value{GDBP})
10998722 13219@end smallexample
a0eb71c5
KB
13220
13221@value{GDBN} uses the target character set for character and string
13222literals you use in expressions:
13223
13224@smallexample
f7dc1244 13225(@value{GDBP}) print '+'
a0eb71c5 13226$3 = 43 '+'
f7dc1244 13227(@value{GDBP})
10998722 13228@end smallexample
a0eb71c5
KB
13229
13230The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13231character.
13232
13233@value{GDBN} relies on the user to tell it which character set the
13234target program uses. If we print @code{ibm1047_hello} while our target
13235character set is still @sc{ascii}, we get jibberish:
13236
13237@smallexample
f7dc1244 13238(@value{GDBP}) print ibm1047_hello
a0eb71c5 13239$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13240(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13241$5 = 200 '\310'
f7dc1244 13242(@value{GDBP})
10998722 13243@end smallexample
a0eb71c5 13244
e33d66ec 13245If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13246@value{GDBN} tells us the character sets it supports:
13247
13248@smallexample
f7dc1244 13249(@value{GDBP}) set target-charset
b383017d 13250ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13251(@value{GDBP}) set target-charset
10998722 13252@end smallexample
a0eb71c5
KB
13253
13254We can select @sc{ibm1047} as our target character set, and examine the
13255program's strings again. Now the @sc{ascii} string is wrong, but
13256@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13257target character set, @sc{ibm1047}, to the host character set,
13258@sc{ascii}, and they display correctly:
13259
13260@smallexample
f7dc1244
EZ
13261(@value{GDBP}) set target-charset IBM1047
13262(@value{GDBP}) show charset
e33d66ec
EZ
13263The current host character set is `ASCII'.
13264The current target character set is `IBM1047'.
f7dc1244 13265(@value{GDBP}) print ascii_hello
a0eb71c5 13266$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13267(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13268$7 = 72 '\110'
f7dc1244 13269(@value{GDBP}) print ibm1047_hello
a0eb71c5 13270$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13271(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13272$9 = 200 'H'
f7dc1244 13273(@value{GDBP})
10998722 13274@end smallexample
a0eb71c5
KB
13275
13276As above, @value{GDBN} uses the target character set for character and
13277string literals you use in expressions:
13278
13279@smallexample
f7dc1244 13280(@value{GDBP}) print '+'
a0eb71c5 13281$10 = 78 '+'
f7dc1244 13282(@value{GDBP})
10998722 13283@end smallexample
a0eb71c5 13284
e33d66ec 13285The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13286character.
13287
b12039c6
YQ
13288@node Caching Target Data
13289@section Caching Data of Targets
13290@cindex caching data of targets
13291
13292@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13293Each cache is associated with the address space of the inferior.
65c574f6 13294@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13295Such caching generally improves performance in remote debugging
13296(@pxref{Remote Debugging}), because it reduces the overhead of the
13297remote protocol by bundling memory reads and writes into large chunks.
13298Unfortunately, simply caching everything would lead to incorrect results,
13299since @value{GDBN} does not necessarily know anything about volatile
13300values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13301(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13302is executing.
29b090c0
DE
13303Therefore, by default, @value{GDBN} only caches data
13304known to be on the stack@footnote{In non-stop mode, it is moderately
13305rare for a running thread to modify the stack of a stopped thread
13306in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13307stack reads provides a significant speed up of remote backtraces.} or
13308in the code segment.
29b090c0 13309Other regions of memory can be explicitly marked as
27b81af3 13310cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13311
13312@table @code
13313@kindex set remotecache
13314@item set remotecache on
13315@itemx set remotecache off
4e5d721f
DE
13316This option no longer does anything; it exists for compatibility
13317with old scripts.
09d4efe1
EZ
13318
13319@kindex show remotecache
13320@item show remotecache
4e5d721f
DE
13321Show the current state of the obsolete remotecache flag.
13322
13323@kindex set stack-cache
13324@item set stack-cache on
13325@itemx set stack-cache off
6dd315ba
YQ
13326Enable or disable caching of stack accesses. When @code{on}, use
13327caching. By default, this option is @code{on}.
4e5d721f
DE
13328
13329@kindex show stack-cache
13330@item show stack-cache
13331Show the current state of data caching for memory accesses.
09d4efe1 13332
29453a14
YQ
13333@kindex set code-cache
13334@item set code-cache on
13335@itemx set code-cache off
13336Enable or disable caching of code segment accesses. When @code{on},
13337use caching. By default, this option is @code{on}. This improves
13338performance of disassembly in remote debugging.
13339
13340@kindex show code-cache
13341@item show code-cache
13342Show the current state of target memory cache for code segment
13343accesses.
13344
09d4efe1 13345@kindex info dcache
4e5d721f 13346@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13347Print the information about the performance of data cache of the
13348current inferior's address space. The information displayed
13349includes the dcache width and depth, and for each cache line, its
13350number, address, and how many times it was referenced. This
13351command is useful for debugging the data cache operation.
4e5d721f
DE
13352
13353If a line number is specified, the contents of that line will be
13354printed in hex.
1a532630
PP
13355
13356@item set dcache size @var{size}
13357@cindex dcache size
13358@kindex set dcache size
13359Set maximum number of entries in dcache (dcache depth above).
13360
13361@item set dcache line-size @var{line-size}
13362@cindex dcache line-size
13363@kindex set dcache line-size
13364Set number of bytes each dcache entry caches (dcache width above).
13365Must be a power of 2.
13366
13367@item show dcache size
13368@kindex show dcache size
b12039c6 13369Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13370
13371@item show dcache line-size
13372@kindex show dcache line-size
b12039c6 13373Show default size of dcache lines.
1a532630 13374
09d4efe1
EZ
13375@end table
13376
08388c79
DE
13377@node Searching Memory
13378@section Search Memory
13379@cindex searching memory
13380
13381Memory can be searched for a particular sequence of bytes with the
13382@code{find} command.
13383
13384@table @code
13385@kindex find
13386@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13387@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13388Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13389etc. The search begins at address @var{start_addr} and continues for either
13390@var{len} bytes or through to @var{end_addr} inclusive.
13391@end table
13392
13393@var{s} and @var{n} are optional parameters.
13394They may be specified in either order, apart or together.
13395
13396@table @r
13397@item @var{s}, search query size
13398The size of each search query value.
13399
13400@table @code
13401@item b
13402bytes
13403@item h
13404halfwords (two bytes)
13405@item w
13406words (four bytes)
13407@item g
13408giant words (eight bytes)
13409@end table
13410
13411All values are interpreted in the current language.
13412This means, for example, that if the current source language is C/C@t{++}
13413then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13414The null terminator can be removed from searching by using casts,
13415e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13416
13417If the value size is not specified, it is taken from the
13418value's type in the current language.
13419This is useful when one wants to specify the search
13420pattern as a mixture of types.
13421Note that this means, for example, that in the case of C-like languages
13422a search for an untyped 0x42 will search for @samp{(int) 0x42}
13423which is typically four bytes.
13424
13425@item @var{n}, maximum number of finds
13426The maximum number of matches to print. The default is to print all finds.
13427@end table
13428
13429You can use strings as search values. Quote them with double-quotes
13430 (@code{"}).
13431The string value is copied into the search pattern byte by byte,
13432regardless of the endianness of the target and the size specification.
13433
13434The address of each match found is printed as well as a count of the
13435number of matches found.
13436
13437The address of the last value found is stored in convenience variable
13438@samp{$_}.
13439A count of the number of matches is stored in @samp{$numfound}.
13440
13441For example, if stopped at the @code{printf} in this function:
13442
13443@smallexample
13444void
13445hello ()
13446@{
13447 static char hello[] = "hello-hello";
13448 static struct @{ char c; short s; int i; @}
13449 __attribute__ ((packed)) mixed
13450 = @{ 'c', 0x1234, 0x87654321 @};
13451 printf ("%s\n", hello);
13452@}
13453@end smallexample
13454
13455@noindent
13456you get during debugging:
13457
13458@smallexample
13459(gdb) find &hello[0], +sizeof(hello), "hello"
134600x804956d <hello.1620+6>
134611 pattern found
13462(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
134630x8049567 <hello.1620>
134640x804956d <hello.1620+6>
ee9a09e9
DC
134652 patterns found.
13466(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
134670x8049567 <hello.1620>
134680x804956d <hello.1620+6>
134692 patterns found.
08388c79
DE
13470(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
134710x8049567 <hello.1620>
134721 pattern found
13473(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
134740x8049560 <mixed.1625>
134751 pattern found
13476(gdb) print $numfound
13477$1 = 1
13478(gdb) print $_
13479$2 = (void *) 0x8049560
13480@end smallexample
a0eb71c5 13481
5fdf6324
AB
13482@node Value Sizes
13483@section Value Sizes
13484
13485Whenever @value{GDBN} prints a value memory will be allocated within
13486@value{GDBN} to hold the contents of the value. It is possible in
13487some languages with dynamic typing systems, that an invalid program
13488may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13489@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13490
13491@table @code
13492@kindex set max-value-size
713cdcbf 13493@item set max-value-size @var{bytes}
5fdf6324
AB
13494@itemx set max-value-size unlimited
13495Set the maximum size of memory that @value{GDBN} will allocate for the
13496contents of a value to @var{bytes}, trying to display a value that
13497requires more memory than that will result in an error.
13498
13499Setting this variable does not effect values that have already been
13500allocated within @value{GDBN}, only future allocations.
13501
13502There's a minimum size that @code{max-value-size} can be set to in
13503order that @value{GDBN} can still operate correctly, this minimum is
13504currently 16 bytes.
13505
13506The limit applies to the results of some subexpressions as well as to
13507complete expressions. For example, an expression denoting a simple
13508integer component, such as @code{x.y.z}, may fail if the size of
13509@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13510@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13511@var{A} is an array variable with non-constant size, will generally
13512succeed regardless of the bounds on @var{A}, as long as the component
13513size is less than @var{bytes}.
13514
13515The default value of @code{max-value-size} is currently 64k.
13516
13517@kindex show max-value-size
13518@item show max-value-size
13519Show the maximum size of memory, in bytes, that @value{GDBN} will
13520allocate for the contents of a value.
13521@end table
13522
edb3359d
DJ
13523@node Optimized Code
13524@chapter Debugging Optimized Code
13525@cindex optimized code, debugging
13526@cindex debugging optimized code
13527
13528Almost all compilers support optimization. With optimization
13529disabled, the compiler generates assembly code that corresponds
13530directly to your source code, in a simplistic way. As the compiler
13531applies more powerful optimizations, the generated assembly code
13532diverges from your original source code. With help from debugging
13533information generated by the compiler, @value{GDBN} can map from
13534the running program back to constructs from your original source.
13535
13536@value{GDBN} is more accurate with optimization disabled. If you
13537can recompile without optimization, it is easier to follow the
13538progress of your program during debugging. But, there are many cases
13539where you may need to debug an optimized version.
13540
13541When you debug a program compiled with @samp{-g -O}, remember that the
13542optimizer has rearranged your code; the debugger shows you what is
13543really there. Do not be too surprised when the execution path does not
13544exactly match your source file! An extreme example: if you define a
13545variable, but never use it, @value{GDBN} never sees that
13546variable---because the compiler optimizes it out of existence.
13547
13548Some things do not work as well with @samp{-g -O} as with just
13549@samp{-g}, particularly on machines with instruction scheduling. If in
13550doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13551please report it to us as a bug (including a test case!).
13552@xref{Variables}, for more information about debugging optimized code.
13553
13554@menu
13555* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13556* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13557@end menu
13558
13559@node Inline Functions
13560@section Inline Functions
13561@cindex inline functions, debugging
13562
13563@dfn{Inlining} is an optimization that inserts a copy of the function
13564body directly at each call site, instead of jumping to a shared
13565routine. @value{GDBN} displays inlined functions just like
13566non-inlined functions. They appear in backtraces. You can view their
13567arguments and local variables, step into them with @code{step}, skip
13568them with @code{next}, and escape from them with @code{finish}.
13569You can check whether a function was inlined by using the
13570@code{info frame} command.
13571
13572For @value{GDBN} to support inlined functions, the compiler must
13573record information about inlining in the debug information ---
13574@value{NGCC} using the @sc{dwarf 2} format does this, and several
13575other compilers do also. @value{GDBN} only supports inlined functions
13576when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13577do not emit two required attributes (@samp{DW_AT_call_file} and
13578@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13579function calls with earlier versions of @value{NGCC}. It instead
13580displays the arguments and local variables of inlined functions as
13581local variables in the caller.
13582
13583The body of an inlined function is directly included at its call site;
13584unlike a non-inlined function, there are no instructions devoted to
13585the call. @value{GDBN} still pretends that the call site and the
13586start of the inlined function are different instructions. Stepping to
13587the call site shows the call site, and then stepping again shows
13588the first line of the inlined function, even though no additional
13589instructions are executed.
13590
13591This makes source-level debugging much clearer; you can see both the
13592context of the call and then the effect of the call. Only stepping by
13593a single instruction using @code{stepi} or @code{nexti} does not do
13594this; single instruction steps always show the inlined body.
13595
13596There are some ways that @value{GDBN} does not pretend that inlined
13597function calls are the same as normal calls:
13598
13599@itemize @bullet
edb3359d
DJ
13600@item
13601Setting breakpoints at the call site of an inlined function may not
13602work, because the call site does not contain any code. @value{GDBN}
13603may incorrectly move the breakpoint to the next line of the enclosing
13604function, after the call. This limitation will be removed in a future
13605version of @value{GDBN}; until then, set a breakpoint on an earlier line
13606or inside the inlined function instead.
13607
13608@item
13609@value{GDBN} cannot locate the return value of inlined calls after
13610using the @code{finish} command. This is a limitation of compiler-generated
13611debugging information; after @code{finish}, you can step to the next line
13612and print a variable where your program stored the return value.
13613
13614@end itemize
13615
111c6489
JK
13616@node Tail Call Frames
13617@section Tail Call Frames
13618@cindex tail call frames, debugging
13619
13620Function @code{B} can call function @code{C} in its very last statement. In
13621unoptimized compilation the call of @code{C} is immediately followed by return
13622instruction at the end of @code{B} code. Optimizing compiler may replace the
13623call and return in function @code{B} into one jump to function @code{C}
13624instead. Such use of a jump instruction is called @dfn{tail call}.
13625
13626During execution of function @code{C}, there will be no indication in the
13627function call stack frames that it was tail-called from @code{B}. If function
13628@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13629then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13630some cases @value{GDBN} can determine that @code{C} was tail-called from
13631@code{B}, and it will then create fictitious call frame for that, with the
13632return address set up as if @code{B} called @code{C} normally.
13633
13634This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13635the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13636@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13637this information.
13638
13639@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13640kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13641
13642@smallexample
13643(gdb) x/i $pc - 2
13644 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13645(gdb) info frame
13646Stack level 1, frame at 0x7fffffffda30:
13647 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13648 tail call frame, caller of frame at 0x7fffffffda30
13649 source language c++.
13650 Arglist at unknown address.
13651 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13652@end smallexample
13653
13654The detection of all the possible code path executions can find them ambiguous.
13655There is no execution history stored (possible @ref{Reverse Execution} is never
13656used for this purpose) and the last known caller could have reached the known
13657callee by multiple different jump sequences. In such case @value{GDBN} still
13658tries to show at least all the unambiguous top tail callers and all the
13659unambiguous bottom tail calees, if any.
13660
13661@table @code
e18b2753 13662@anchor{set debug entry-values}
111c6489
JK
13663@item set debug entry-values
13664@kindex set debug entry-values
13665When set to on, enables printing of analysis messages for both frame argument
13666values at function entry and tail calls. It will show all the possible valid
13667tail calls code paths it has considered. It will also print the intersection
13668of them with the final unambiguous (possibly partial or even empty) code path
13669result.
13670
13671@item show debug entry-values
13672@kindex show debug entry-values
13673Show the current state of analysis messages printing for both frame argument
13674values at function entry and tail calls.
13675@end table
13676
13677The analysis messages for tail calls can for example show why the virtual tail
13678call frame for function @code{c} has not been recognized (due to the indirect
13679reference by variable @code{x}):
13680
13681@smallexample
13682static void __attribute__((noinline, noclone)) c (void);
13683void (*x) (void) = c;
13684static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13685static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13686int main (void) @{ x (); return 0; @}
13687
216f72a1
JK
13688Breakpoint 1, DW_OP_entry_value resolving cannot find
13689DW_TAG_call_site 0x40039a in main
111c6489
JK
13690a () at t.c:3
136913 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13692(gdb) bt
13693#0 a () at t.c:3
13694#1 0x000000000040039a in main () at t.c:5
13695@end smallexample
13696
13697Another possibility is an ambiguous virtual tail call frames resolution:
13698
13699@smallexample
13700int i;
13701static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13702static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13703static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13704static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13705static void __attribute__((noinline, noclone)) b (void)
13706@{ if (i) c (); else e (); @}
13707static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13708int main (void) @{ a (); return 0; @}
13709
13710tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13711tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13712tailcall: reduced: 0x4004d2(a) |
13713(gdb) bt
13714#0 f () at t.c:2
13715#1 0x00000000004004d2 in a () at t.c:8
13716#2 0x0000000000400395 in main () at t.c:9
13717@end smallexample
13718
5048e516
JK
13719@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13720@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13721
13722@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13723@ifset HAVE_MAKEINFO_CLICK
13724@set ARROW @click{}
13725@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13726@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13727@end ifset
13728@ifclear HAVE_MAKEINFO_CLICK
13729@set ARROW ->
13730@set CALLSEQ1B @value{CALLSEQ1A}
13731@set CALLSEQ2B @value{CALLSEQ2A}
13732@end ifclear
13733
13734Frames #0 and #2 are real, #1 is a virtual tail call frame.
13735The code can have possible execution paths @value{CALLSEQ1B} or
13736@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13737
13738@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13739has found. It then finds another possible calling sequence - that one is
111c6489
JK
13740prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13741printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13742further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13743any non-ambiguous sequence entries.
13744
13745For the frame of function @code{b} in both cases there are different possible
13746@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13747also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13748therefore this one is displayed to the user while the ambiguous frames are
13749omitted.
edb3359d 13750
e18b2753
JK
13751There can be also reasons why printing of frame argument values at function
13752entry may fail:
13753
13754@smallexample
13755int v;
13756static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13757static void __attribute__((noinline, noclone)) a (int i);
13758static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13759static void __attribute__((noinline, noclone)) a (int i)
13760@{ if (i) b (i - 1); else c (0); @}
13761int main (void) @{ a (5); return 0; @}
13762
13763(gdb) bt
13764#0 c (i=i@@entry=0) at t.c:2
216f72a1 13765#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13766function "a" at 0x400420 can call itself via tail calls
13767i=<optimized out>) at t.c:6
13768#2 0x000000000040036e in main () at t.c:7
13769@end smallexample
13770
13771@value{GDBN} cannot find out from the inferior state if and how many times did
13772function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13773tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13774@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13775prints @code{<optimized out>} instead.
13776
e2e0bcd1
JB
13777@node Macros
13778@chapter C Preprocessor Macros
13779
49efadf5 13780Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13781``preprocessor macros'' which expand into strings of tokens.
13782@value{GDBN} can evaluate expressions containing macro invocations, show
13783the result of macro expansion, and show a macro's definition, including
13784where it was defined.
13785
13786You may need to compile your program specially to provide @value{GDBN}
13787with information about preprocessor macros. Most compilers do not
13788include macros in their debugging information, even when you compile
13789with the @option{-g} flag. @xref{Compilation}.
13790
13791A program may define a macro at one point, remove that definition later,
13792and then provide a different definition after that. Thus, at different
13793points in the program, a macro may have different definitions, or have
13794no definition at all. If there is a current stack frame, @value{GDBN}
13795uses the macros in scope at that frame's source code line. Otherwise,
13796@value{GDBN} uses the macros in scope at the current listing location;
13797see @ref{List}.
13798
e2e0bcd1
JB
13799Whenever @value{GDBN} evaluates an expression, it always expands any
13800macro invocations present in the expression. @value{GDBN} also provides
13801the following commands for working with macros explicitly.
13802
13803@table @code
13804
13805@kindex macro expand
13806@cindex macro expansion, showing the results of preprocessor
13807@cindex preprocessor macro expansion, showing the results of
13808@cindex expanding preprocessor macros
13809@item macro expand @var{expression}
13810@itemx macro exp @var{expression}
13811Show the results of expanding all preprocessor macro invocations in
13812@var{expression}. Since @value{GDBN} simply expands macros, but does
13813not parse the result, @var{expression} need not be a valid expression;
13814it can be any string of tokens.
13815
09d4efe1 13816@kindex macro exp1
e2e0bcd1
JB
13817@item macro expand-once @var{expression}
13818@itemx macro exp1 @var{expression}
4644b6e3 13819@cindex expand macro once
e2e0bcd1
JB
13820@i{(This command is not yet implemented.)} Show the results of
13821expanding those preprocessor macro invocations that appear explicitly in
13822@var{expression}. Macro invocations appearing in that expansion are
13823left unchanged. This command allows you to see the effect of a
13824particular macro more clearly, without being confused by further
13825expansions. Since @value{GDBN} simply expands macros, but does not
13826parse the result, @var{expression} need not be a valid expression; it
13827can be any string of tokens.
13828
475b0867 13829@kindex info macro
e2e0bcd1 13830@cindex macro definition, showing
9b158ba0 13831@cindex definition of a macro, showing
13832@cindex macros, from debug info
71eba9c2 13833@item info macro [-a|-all] [--] @var{macro}
13834Show the current definition or all definitions of the named @var{macro},
13835and describe the source location or compiler command-line where that
13836definition was established. The optional double dash is to signify the end of
13837argument processing and the beginning of @var{macro} for non C-like macros where
13838the macro may begin with a hyphen.
e2e0bcd1 13839
9b158ba0 13840@kindex info macros
629500fa 13841@item info macros @var{location}
9b158ba0 13842Show all macro definitions that are in effect at the location specified
629500fa 13843by @var{location}, and describe the source location or compiler
9b158ba0 13844command-line where those definitions were established.
13845
e2e0bcd1
JB
13846@kindex macro define
13847@cindex user-defined macros
13848@cindex defining macros interactively
13849@cindex macros, user-defined
13850@item macro define @var{macro} @var{replacement-list}
13851@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13852Introduce a definition for a preprocessor macro named @var{macro},
13853invocations of which are replaced by the tokens given in
13854@var{replacement-list}. The first form of this command defines an
13855``object-like'' macro, which takes no arguments; the second form
13856defines a ``function-like'' macro, which takes the arguments given in
13857@var{arglist}.
13858
13859A definition introduced by this command is in scope in every
13860expression evaluated in @value{GDBN}, until it is removed with the
13861@code{macro undef} command, described below. The definition overrides
13862all definitions for @var{macro} present in the program being debugged,
13863as well as any previous user-supplied definition.
e2e0bcd1
JB
13864
13865@kindex macro undef
13866@item macro undef @var{macro}
d7d9f01e
TT
13867Remove any user-supplied definition for the macro named @var{macro}.
13868This command only affects definitions provided with the @code{macro
13869define} command, described above; it cannot remove definitions present
13870in the program being debugged.
e2e0bcd1 13871
09d4efe1
EZ
13872@kindex macro list
13873@item macro list
d7d9f01e 13874List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13875@end table
13876
13877@cindex macros, example of debugging with
13878Here is a transcript showing the above commands in action. First, we
13879show our source files:
13880
13881@smallexample
13882$ cat sample.c
13883#include <stdio.h>
13884#include "sample.h"
13885
13886#define M 42
13887#define ADD(x) (M + x)
13888
13889main ()
13890@{
13891#define N 28
13892 printf ("Hello, world!\n");
13893#undef N
13894 printf ("We're so creative.\n");
13895#define N 1729
13896 printf ("Goodbye, world!\n");
13897@}
13898$ cat sample.h
13899#define Q <
13900$
13901@end smallexample
13902
e0f8f636
TT
13903Now, we compile the program using the @sc{gnu} C compiler,
13904@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13905minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13906and @option{-gdwarf-4}; we recommend always choosing the most recent
13907version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13908includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13909information.
13910
13911@smallexample
13912$ gcc -gdwarf-2 -g3 sample.c -o sample
13913$
13914@end smallexample
13915
13916Now, we start @value{GDBN} on our sample program:
13917
13918@smallexample
13919$ gdb -nw sample
13920GNU gdb 2002-05-06-cvs
13921Copyright 2002 Free Software Foundation, Inc.
13922GDB is free software, @dots{}
f7dc1244 13923(@value{GDBP})
e2e0bcd1
JB
13924@end smallexample
13925
13926We can expand macros and examine their definitions, even when the
13927program is not running. @value{GDBN} uses the current listing position
13928to decide which macro definitions are in scope:
13929
13930@smallexample
f7dc1244 13931(@value{GDBP}) list main
e2e0bcd1
JB
139323
139334 #define M 42
139345 #define ADD(x) (M + x)
139356
139367 main ()
139378 @{
139389 #define N 28
1393910 printf ("Hello, world!\n");
1394011 #undef N
1394112 printf ("We're so creative.\n");
f7dc1244 13942(@value{GDBP}) info macro ADD
e2e0bcd1
JB
13943Defined at /home/jimb/gdb/macros/play/sample.c:5
13944#define ADD(x) (M + x)
f7dc1244 13945(@value{GDBP}) info macro Q
e2e0bcd1
JB
13946Defined at /home/jimb/gdb/macros/play/sample.h:1
13947 included at /home/jimb/gdb/macros/play/sample.c:2
13948#define Q <
f7dc1244 13949(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 13950expands to: (42 + 1)
f7dc1244 13951(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 13952expands to: once (M + 1)
f7dc1244 13953(@value{GDBP})
e2e0bcd1
JB
13954@end smallexample
13955
d7d9f01e 13956In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
13957the macro invocation explicit in the original text --- the invocation of
13958@code{ADD} --- but does not expand the invocation of the macro @code{M},
13959which was introduced by @code{ADD}.
13960
3f94c067
BW
13961Once the program is running, @value{GDBN} uses the macro definitions in
13962force at the source line of the current stack frame:
e2e0bcd1
JB
13963
13964@smallexample
f7dc1244 13965(@value{GDBP}) break main
e2e0bcd1 13966Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 13967(@value{GDBP}) run
b383017d 13968Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
13969
13970Breakpoint 1, main () at sample.c:10
1397110 printf ("Hello, world!\n");
f7dc1244 13972(@value{GDBP})
e2e0bcd1
JB
13973@end smallexample
13974
13975At line 10, the definition of the macro @code{N} at line 9 is in force:
13976
13977@smallexample
f7dc1244 13978(@value{GDBP}) info macro N
e2e0bcd1
JB
13979Defined at /home/jimb/gdb/macros/play/sample.c:9
13980#define N 28
f7dc1244 13981(@value{GDBP}) macro expand N Q M
e2e0bcd1 13982expands to: 28 < 42
f7dc1244 13983(@value{GDBP}) print N Q M
e2e0bcd1 13984$1 = 1
f7dc1244 13985(@value{GDBP})
e2e0bcd1
JB
13986@end smallexample
13987
13988As we step over directives that remove @code{N}'s definition, and then
13989give it a new definition, @value{GDBN} finds the definition (or lack
13990thereof) in force at each point:
13991
13992@smallexample
f7dc1244 13993(@value{GDBP}) next
e2e0bcd1
JB
13994Hello, world!
1399512 printf ("We're so creative.\n");
f7dc1244 13996(@value{GDBP}) info macro N
e2e0bcd1
JB
13997The symbol `N' has no definition as a C/C++ preprocessor macro
13998at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 13999(@value{GDBP}) next
e2e0bcd1
JB
14000We're so creative.
1400114 printf ("Goodbye, world!\n");
f7dc1244 14002(@value{GDBP}) info macro N
e2e0bcd1
JB
14003Defined at /home/jimb/gdb/macros/play/sample.c:13
14004#define N 1729
f7dc1244 14005(@value{GDBP}) macro expand N Q M
e2e0bcd1 14006expands to: 1729 < 42
f7dc1244 14007(@value{GDBP}) print N Q M
e2e0bcd1 14008$2 = 0
f7dc1244 14009(@value{GDBP})
e2e0bcd1
JB
14010@end smallexample
14011
484086b7
JK
14012In addition to source files, macros can be defined on the compilation command
14013line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14014such a way, @value{GDBN} displays the location of their definition as line zero
14015of the source file submitted to the compiler.
14016
14017@smallexample
14018(@value{GDBP}) info macro __STDC__
14019Defined at /home/jimb/gdb/macros/play/sample.c:0
14020-D__STDC__=1
14021(@value{GDBP})
14022@end smallexample
14023
e2e0bcd1 14024
b37052ae
EZ
14025@node Tracepoints
14026@chapter Tracepoints
14027@c This chapter is based on the documentation written by Michael
14028@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14029
14030@cindex tracepoints
14031In some applications, it is not feasible for the debugger to interrupt
14032the program's execution long enough for the developer to learn
14033anything helpful about its behavior. If the program's correctness
14034depends on its real-time behavior, delays introduced by a debugger
14035might cause the program to change its behavior drastically, or perhaps
14036fail, even when the code itself is correct. It is useful to be able
14037to observe the program's behavior without interrupting it.
14038
14039Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14040specify locations in the program, called @dfn{tracepoints}, and
14041arbitrary expressions to evaluate when those tracepoints are reached.
14042Later, using the @code{tfind} command, you can examine the values
14043those expressions had when the program hit the tracepoints. The
14044expressions may also denote objects in memory---structures or arrays,
14045for example---whose values @value{GDBN} should record; while visiting
14046a particular tracepoint, you may inspect those objects as if they were
14047in memory at that moment. However, because @value{GDBN} records these
14048values without interacting with you, it can do so quickly and
14049unobtrusively, hopefully not disturbing the program's behavior.
14050
14051The tracepoint facility is currently available only for remote
9d29849a
JB
14052targets. @xref{Targets}. In addition, your remote target must know
14053how to collect trace data. This functionality is implemented in the
14054remote stub; however, none of the stubs distributed with @value{GDBN}
14055support tracepoints as of this writing. The format of the remote
14056packets used to implement tracepoints are described in @ref{Tracepoint
14057Packets}.
b37052ae 14058
00bf0b85
SS
14059It is also possible to get trace data from a file, in a manner reminiscent
14060of corefiles; you specify the filename, and use @code{tfind} to search
14061through the file. @xref{Trace Files}, for more details.
14062
b37052ae
EZ
14063This chapter describes the tracepoint commands and features.
14064
14065@menu
b383017d
RM
14066* Set Tracepoints::
14067* Analyze Collected Data::
14068* Tracepoint Variables::
00bf0b85 14069* Trace Files::
b37052ae
EZ
14070@end menu
14071
14072@node Set Tracepoints
14073@section Commands to Set Tracepoints
14074
14075Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
14076tracepoints can be set. A tracepoint is actually a special type of
14077breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14078standard breakpoint commands. For instance, as with breakpoints,
14079tracepoint numbers are successive integers starting from one, and many
14080of the commands associated with tracepoints take the tracepoint number
14081as their argument, to identify which tracepoint to work on.
b37052ae
EZ
14082
14083For each tracepoint, you can specify, in advance, some arbitrary set
14084of data that you want the target to collect in the trace buffer when
14085it hits that tracepoint. The collected data can include registers,
14086local variables, or global data. Later, you can use @value{GDBN}
14087commands to examine the values these data had at the time the
14088tracepoint was hit.
14089
7d13fe92
SS
14090Tracepoints do not support every breakpoint feature. Ignore counts on
14091tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14092commands when they are hit. Tracepoints may not be thread-specific
14093either.
1042e4c0 14094
7a697b8d
SS
14095@cindex fast tracepoints
14096Some targets may support @dfn{fast tracepoints}, which are inserted in
14097a different way (such as with a jump instead of a trap), that is
14098faster but possibly restricted in where they may be installed.
14099
0fb4aa4b
PA
14100@cindex static tracepoints
14101@cindex markers, static tracepoints
14102@cindex probing markers, static tracepoints
14103Regular and fast tracepoints are dynamic tracing facilities, meaning
14104that they can be used to insert tracepoints at (almost) any location
14105in the target. Some targets may also support controlling @dfn{static
14106tracepoints} from @value{GDBN}. With static tracing, a set of
14107instrumentation points, also known as @dfn{markers}, are embedded in
14108the target program, and can be activated or deactivated by name or
14109address. These are usually placed at locations which facilitate
14110investigating what the target is actually doing. @value{GDBN}'s
14111support for static tracing includes being able to list instrumentation
14112points, and attach them with @value{GDBN} defined high level
14113tracepoints that expose the whole range of convenience of
8786b2bd 14114@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
14115registers values and values of global or local (to the instrumentation
14116point) variables; tracepoint conditions and trace state variables.
14117The act of installing a @value{GDBN} static tracepoint on an
14118instrumentation point, or marker, is referred to as @dfn{probing} a
14119static tracepoint marker.
14120
fa593d66
PA
14121@code{gdbserver} supports tracepoints on some target systems.
14122@xref{Server,,Tracepoints support in @code{gdbserver}}.
14123
b37052ae
EZ
14124This section describes commands to set tracepoints and associated
14125conditions and actions.
14126
14127@menu
b383017d
RM
14128* Create and Delete Tracepoints::
14129* Enable and Disable Tracepoints::
14130* Tracepoint Passcounts::
782b2b07 14131* Tracepoint Conditions::
f61e138d 14132* Trace State Variables::
b383017d
RM
14133* Tracepoint Actions::
14134* Listing Tracepoints::
0fb4aa4b 14135* Listing Static Tracepoint Markers::
79a6e687 14136* Starting and Stopping Trace Experiments::
c9429232 14137* Tracepoint Restrictions::
b37052ae
EZ
14138@end menu
14139
14140@node Create and Delete Tracepoints
14141@subsection Create and Delete Tracepoints
14142
14143@table @code
14144@cindex set tracepoint
14145@kindex trace
1042e4c0 14146@item trace @var{location}
b37052ae 14147The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14148Its argument @var{location} can be any valid location.
14149@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14150which is a point in the target program where the debugger will briefly stop,
14151collect some data, and then allow the program to continue. Setting a tracepoint
14152or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14153supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14154in tracing}).
14155If remote stub doesn't support the @samp{InstallInTrace} feature, all
14156these changes don't take effect until the next @code{tstart}
1042e4c0 14157command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14158not have any effect until the next trace experiment starts. In addition,
14159@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14160address is not yet resolved. (This is similar to pending breakpoints.)
14161Pending tracepoints are not downloaded to the target and not installed
14162until they are resolved. The resolution of pending tracepoints requires
14163@value{GDBN} support---when debugging with the remote target, and
14164@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14165tracing}), pending tracepoints can not be resolved (and downloaded to
14166the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14167
14168Here are some examples of using the @code{trace} command:
14169
14170@smallexample
14171(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14172
14173(@value{GDBP}) @b{trace +2} // 2 lines forward
14174
14175(@value{GDBP}) @b{trace my_function} // first source line of function
14176
14177(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14178
14179(@value{GDBP}) @b{trace *0x2117c4} // an address
14180@end smallexample
14181
14182@noindent
14183You can abbreviate @code{trace} as @code{tr}.
14184
782b2b07
SS
14185@item trace @var{location} if @var{cond}
14186Set a tracepoint with condition @var{cond}; evaluate the expression
14187@var{cond} each time the tracepoint is reached, and collect data only
14188if the value is nonzero---that is, if @var{cond} evaluates as true.
14189@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14190information on tracepoint conditions.
14191
7a697b8d
SS
14192@item ftrace @var{location} [ if @var{cond} ]
14193@cindex set fast tracepoint
74c761c1 14194@cindex fast tracepoints, setting
7a697b8d
SS
14195@kindex ftrace
14196The @code{ftrace} command sets a fast tracepoint. For targets that
14197support them, fast tracepoints will use a more efficient but possibly
14198less general technique to trigger data collection, such as a jump
14199instruction instead of a trap, or some sort of hardware support. It
14200may not be possible to create a fast tracepoint at the desired
14201location, in which case the command will exit with an explanatory
14202message.
14203
14204@value{GDBN} handles arguments to @code{ftrace} exactly as for
14205@code{trace}.
14206
405f8e94
SS
14207On 32-bit x86-architecture systems, fast tracepoints normally need to
14208be placed at an instruction that is 5 bytes or longer, but can be
14209placed at 4-byte instructions if the low 64K of memory of the target
14210program is available to install trampolines. Some Unix-type systems,
14211such as @sc{gnu}/Linux, exclude low addresses from the program's
14212address space; but for instance with the Linux kernel it is possible
14213to let @value{GDBN} use this area by doing a @command{sysctl} command
14214to set the @code{mmap_min_addr} kernel parameter, as in
14215
14216@example
14217sudo sysctl -w vm.mmap_min_addr=32768
14218@end example
14219
14220@noindent
14221which sets the low address to 32K, which leaves plenty of room for
14222trampolines. The minimum address should be set to a page boundary.
14223
0fb4aa4b 14224@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14225@cindex set static tracepoint
14226@cindex static tracepoints, setting
14227@cindex probe static tracepoint marker
0fb4aa4b
PA
14228@kindex strace
14229The @code{strace} command sets a static tracepoint. For targets that
14230support it, setting a static tracepoint probes a static
14231instrumentation point, or marker, found at @var{location}. It may not
14232be possible to set a static tracepoint at the desired location, in
14233which case the command will exit with an explanatory message.
14234
14235@value{GDBN} handles arguments to @code{strace} exactly as for
14236@code{trace}, with the addition that the user can also specify
14237@code{-m @var{marker}} as @var{location}. This probes the marker
14238identified by the @var{marker} string identifier. This identifier
14239depends on the static tracepoint backend library your program is
14240using. You can find all the marker identifiers in the @samp{ID} field
14241of the @code{info static-tracepoint-markers} command output.
14242@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14243Markers}. For example, in the following small program using the UST
14244tracing engine:
14245
14246@smallexample
14247main ()
14248@{
14249 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14250@}
14251@end smallexample
14252
14253@noindent
14254the marker id is composed of joining the first two arguments to the
14255@code{trace_mark} call with a slash, which translates to:
14256
14257@smallexample
14258(@value{GDBP}) info static-tracepoint-markers
14259Cnt Enb ID Address What
142601 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14261 Data: "str %s"
14262[etc...]
14263@end smallexample
14264
14265@noindent
14266so you may probe the marker above with:
14267
14268@smallexample
14269(@value{GDBP}) strace -m ust/bar33
14270@end smallexample
14271
14272Static tracepoints accept an extra collect action --- @code{collect
14273$_sdata}. This collects arbitrary user data passed in the probe point
14274call to the tracing library. In the UST example above, you'll see
14275that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14276string. The user data is then the result of running that formatting
0fb4aa4b
PA
14277string against the following arguments. Note that @code{info
14278static-tracepoint-markers} command output lists that format string in
14279the @samp{Data:} field.
14280
14281You can inspect this data when analyzing the trace buffer, by printing
14282the $_sdata variable like any other variable available to
14283@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14284
b37052ae
EZ
14285@vindex $tpnum
14286@cindex last tracepoint number
14287@cindex recent tracepoint number
14288@cindex tracepoint number
14289The convenience variable @code{$tpnum} records the tracepoint number
14290of the most recently set tracepoint.
14291
14292@kindex delete tracepoint
14293@cindex tracepoint deletion
14294@item delete tracepoint @r{[}@var{num}@r{]}
14295Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14296default is to delete all tracepoints. Note that the regular
14297@code{delete} command can remove tracepoints also.
b37052ae
EZ
14298
14299Examples:
14300
14301@smallexample
14302(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14303
14304(@value{GDBP}) @b{delete trace} // remove all tracepoints
14305@end smallexample
14306
14307@noindent
14308You can abbreviate this command as @code{del tr}.
14309@end table
14310
14311@node Enable and Disable Tracepoints
14312@subsection Enable and Disable Tracepoints
14313
1042e4c0
SS
14314These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14315
b37052ae
EZ
14316@table @code
14317@kindex disable tracepoint
14318@item disable tracepoint @r{[}@var{num}@r{]}
14319Disable tracepoint @var{num}, or all tracepoints if no argument
14320@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14321a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14322a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14323If the command is issued during a trace experiment and the debug target
14324has support for disabling tracepoints during a trace experiment, then the
14325change will be effective immediately. Otherwise, it will be applied to the
14326next trace experiment.
b37052ae
EZ
14327
14328@kindex enable tracepoint
14329@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14330Enable tracepoint @var{num}, or all tracepoints. If this command is
14331issued during a trace experiment and the debug target supports enabling
14332tracepoints during a trace experiment, then the enabled tracepoints will
14333become effective immediately. Otherwise, they will become effective the
14334next time a trace experiment is run.
b37052ae
EZ
14335@end table
14336
14337@node Tracepoint Passcounts
14338@subsection Tracepoint Passcounts
14339
14340@table @code
14341@kindex passcount
14342@cindex tracepoint pass count
14343@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14344Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14345automatically stop a trace experiment. If a tracepoint's passcount is
14346@var{n}, then the trace experiment will be automatically stopped on
14347the @var{n}'th time that tracepoint is hit. If the tracepoint number
14348@var{num} is not specified, the @code{passcount} command sets the
14349passcount of the most recently defined tracepoint. If no passcount is
14350given, the trace experiment will run until stopped explicitly by the
14351user.
14352
14353Examples:
14354
14355@smallexample
b383017d 14356(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14357@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14358
14359(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14360@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14361(@value{GDBP}) @b{trace foo}
14362(@value{GDBP}) @b{pass 3}
14363(@value{GDBP}) @b{trace bar}
14364(@value{GDBP}) @b{pass 2}
14365(@value{GDBP}) @b{trace baz}
14366(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14367@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14368@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14369@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14370@end smallexample
14371@end table
14372
782b2b07
SS
14373@node Tracepoint Conditions
14374@subsection Tracepoint Conditions
14375@cindex conditional tracepoints
14376@cindex tracepoint conditions
14377
14378The simplest sort of tracepoint collects data every time your program
14379reaches a specified place. You can also specify a @dfn{condition} for
14380a tracepoint. A condition is just a Boolean expression in your
14381programming language (@pxref{Expressions, ,Expressions}). A
14382tracepoint with a condition evaluates the expression each time your
14383program reaches it, and data collection happens only if the condition
14384is true.
14385
14386Tracepoint conditions can be specified when a tracepoint is set, by
14387using @samp{if} in the arguments to the @code{trace} command.
14388@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14389also be set or changed at any time with the @code{condition} command,
14390just as with breakpoints.
14391
14392Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14393the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14394expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14395suitable for execution on the target, independently of @value{GDBN}.
14396Global variables become raw memory locations, locals become stack
14397accesses, and so forth.
14398
14399For instance, suppose you have a function that is usually called
14400frequently, but should not be called after an error has occurred. You
14401could use the following tracepoint command to collect data about calls
14402of that function that happen while the error code is propagating
14403through the program; an unconditional tracepoint could end up
14404collecting thousands of useless trace frames that you would have to
14405search through.
14406
14407@smallexample
14408(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14409@end smallexample
14410
f61e138d
SS
14411@node Trace State Variables
14412@subsection Trace State Variables
14413@cindex trace state variables
14414
14415A @dfn{trace state variable} is a special type of variable that is
14416created and managed by target-side code. The syntax is the same as
14417that for GDB's convenience variables (a string prefixed with ``$''),
14418but they are stored on the target. They must be created explicitly,
14419using a @code{tvariable} command. They are always 64-bit signed
14420integers.
14421
14422Trace state variables are remembered by @value{GDBN}, and downloaded
14423to the target along with tracepoint information when the trace
14424experiment starts. There are no intrinsic limits on the number of
14425trace state variables, beyond memory limitations of the target.
14426
14427@cindex convenience variables, and trace state variables
14428Although trace state variables are managed by the target, you can use
14429them in print commands and expressions as if they were convenience
14430variables; @value{GDBN} will get the current value from the target
14431while the trace experiment is running. Trace state variables share
14432the same namespace as other ``$'' variables, which means that you
14433cannot have trace state variables with names like @code{$23} or
14434@code{$pc}, nor can you have a trace state variable and a convenience
14435variable with the same name.
14436
14437@table @code
14438
14439@item tvariable $@var{name} [ = @var{expression} ]
14440@kindex tvariable
14441The @code{tvariable} command creates a new trace state variable named
14442@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14443@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14444entered; the result will be converted to an integer if possible,
14445otherwise @value{GDBN} will report an error. A subsequent
14446@code{tvariable} command specifying the same name does not create a
14447variable, but instead assigns the supplied initial value to the
14448existing variable of that name, overwriting any previous initial
14449value. The default initial value is 0.
14450
14451@item info tvariables
14452@kindex info tvariables
14453List all the trace state variables along with their initial values.
14454Their current values may also be displayed, if the trace experiment is
14455currently running.
14456
14457@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14458@kindex delete tvariable
14459Delete the given trace state variables, or all of them if no arguments
14460are specified.
14461
14462@end table
14463
b37052ae
EZ
14464@node Tracepoint Actions
14465@subsection Tracepoint Action Lists
14466
14467@table @code
14468@kindex actions
14469@cindex tracepoint actions
14470@item actions @r{[}@var{num}@r{]}
14471This command will prompt for a list of actions to be taken when the
14472tracepoint is hit. If the tracepoint number @var{num} is not
14473specified, this command sets the actions for the one that was most
14474recently defined (so that you can define a tracepoint and then say
14475@code{actions} without bothering about its number). You specify the
14476actions themselves on the following lines, one action at a time, and
14477terminate the actions list with a line containing just @code{end}. So
7d13fe92 14478far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14479@code{while-stepping}.
14480
5a9351ae
SS
14481@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14482Commands, ,Breakpoint Command Lists}), except that only the defined
14483actions are allowed; any other @value{GDBN} command is rejected.
14484
b37052ae
EZ
14485@cindex remove actions from a tracepoint
14486To remove all actions from a tracepoint, type @samp{actions @var{num}}
14487and follow it immediately with @samp{end}.
14488
14489@smallexample
14490(@value{GDBP}) @b{collect @var{data}} // collect some data
14491
6826cf00 14492(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14493
6826cf00 14494(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14495@end smallexample
14496
14497In the following example, the action list begins with @code{collect}
14498commands indicating the things to be collected when the tracepoint is
14499hit. Then, in order to single-step and collect additional data
14500following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14501followed by the list of things to be collected after each step in a
14502sequence of single steps. The @code{while-stepping} command is
14503terminated by its own separate @code{end} command. Lastly, the action
14504list is terminated by an @code{end} command.
b37052ae
EZ
14505
14506@smallexample
14507(@value{GDBP}) @b{trace foo}
14508(@value{GDBP}) @b{actions}
14509Enter actions for tracepoint 1, one per line:
14510> collect bar,baz
14511> collect $regs
14512> while-stepping 12
5a9351ae 14513 > collect $pc, arr[i]
b37052ae
EZ
14514 > end
14515end
14516@end smallexample
14517
14518@kindex collect @r{(tracepoints)}
3065dfb6 14519@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14520Collect values of the given expressions when the tracepoint is hit.
14521This command accepts a comma-separated list of any valid expressions.
14522In addition to global, static, or local variables, the following
14523special arguments are supported:
14524
14525@table @code
14526@item $regs
0fb4aa4b 14527Collect all registers.
b37052ae
EZ
14528
14529@item $args
0fb4aa4b 14530Collect all function arguments.
b37052ae
EZ
14531
14532@item $locals
0fb4aa4b
PA
14533Collect all local variables.
14534
6710bf39
SS
14535@item $_ret
14536Collect the return address. This is helpful if you want to see more
14537of a backtrace.
14538
2a60e18f 14539@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14540determined up front, and the wrong address / registers may end up
14541collected instead. On some architectures the reliability is higher
14542for tracepoints at function entry, while on others it's the opposite.
14543When this happens, backtracing will stop because the return address is
14544found unavailable (unless another collect rule happened to match it).
14545
62e5f89c
SDJ
14546@item $_probe_argc
14547Collects the number of arguments from the static probe at which the
14548tracepoint is located.
14549@xref{Static Probe Points}.
14550
14551@item $_probe_arg@var{n}
14552@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14553from the static probe at which the tracepoint is located.
14554@xref{Static Probe Points}.
14555
0fb4aa4b
PA
14556@item $_sdata
14557@vindex $_sdata@r{, collect}
14558Collect static tracepoint marker specific data. Only available for
14559static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14560Lists}. On the UST static tracepoints library backend, an
14561instrumentation point resembles a @code{printf} function call. The
14562tracing library is able to collect user specified data formatted to a
14563character string using the format provided by the programmer that
14564instrumented the program. Other backends have similar mechanisms.
14565Here's an example of a UST marker call:
14566
14567@smallexample
14568 const char master_name[] = "$your_name";
14569 trace_mark(channel1, marker1, "hello %s", master_name)
14570@end smallexample
14571
14572In this case, collecting @code{$_sdata} collects the string
14573@samp{hello $yourname}. When analyzing the trace buffer, you can
14574inspect @samp{$_sdata} like any other variable available to
14575@value{GDBN}.
b37052ae
EZ
14576@end table
14577
14578You can give several consecutive @code{collect} commands, each one
14579with a single argument, or one @code{collect} command with several
5a9351ae 14580arguments separated by commas; the effect is the same.
b37052ae 14581
3065dfb6
SS
14582The optional @var{mods} changes the usual handling of the arguments.
14583@code{s} requests that pointers to chars be handled as strings, in
14584particular collecting the contents of the memory being pointed at, up
14585to the first zero. The upper bound is by default the value of the
14586@code{print elements} variable; if @code{s} is followed by a decimal
14587number, that is the upper bound instead. So for instance
14588@samp{collect/s25 mystr} collects as many as 25 characters at
14589@samp{mystr}.
14590
f5c37c66
EZ
14591The command @code{info scope} (@pxref{Symbols, info scope}) is
14592particularly useful for figuring out what data to collect.
14593
6da95a67
SS
14594@kindex teval @r{(tracepoints)}
14595@item teval @var{expr1}, @var{expr2}, @dots{}
14596Evaluate the given expressions when the tracepoint is hit. This
14597command accepts a comma-separated list of expressions. The results
14598are discarded, so this is mainly useful for assigning values to trace
14599state variables (@pxref{Trace State Variables}) without adding those
14600values to the trace buffer, as would be the case if the @code{collect}
14601action were used.
14602
b37052ae
EZ
14603@kindex while-stepping @r{(tracepoints)}
14604@item while-stepping @var{n}
c9429232 14605Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14606collecting new data after each step. The @code{while-stepping}
c9429232
SS
14607command is followed by the list of what to collect while stepping
14608(followed by its own @code{end} command):
b37052ae
EZ
14609
14610@smallexample
14611> while-stepping 12
14612 > collect $regs, myglobal
14613 > end
14614>
14615@end smallexample
14616
14617@noindent
7d13fe92
SS
14618Note that @code{$pc} is not automatically collected by
14619@code{while-stepping}; you need to explicitly collect that register if
14620you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14621@code{stepping}.
236f1d4d
SS
14622
14623@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14624@kindex set default-collect
14625@cindex default collection action
14626This variable is a list of expressions to collect at each tracepoint
14627hit. It is effectively an additional @code{collect} action prepended
14628to every tracepoint action list. The expressions are parsed
14629individually for each tracepoint, so for instance a variable named
14630@code{xyz} may be interpreted as a global for one tracepoint, and a
14631local for another, as appropriate to the tracepoint's location.
14632
14633@item show default-collect
14634@kindex show default-collect
14635Show the list of expressions that are collected by default at each
14636tracepoint hit.
14637
b37052ae
EZ
14638@end table
14639
14640@node Listing Tracepoints
14641@subsection Listing Tracepoints
14642
14643@table @code
e5a67952
MS
14644@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14645@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14646@cindex information about tracepoints
e5a67952 14647@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14648Display information about the tracepoint @var{num}. If you don't
14649specify a tracepoint number, displays information about all the
14650tracepoints defined so far. The format is similar to that used for
14651@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14652command, simply restricting itself to tracepoints.
14653
14654A tracepoint's listing may include additional information specific to
14655tracing:
b37052ae
EZ
14656
14657@itemize @bullet
14658@item
b37052ae 14659its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14660
14661@item
14662the state about installed on target of each location
b37052ae
EZ
14663@end itemize
14664
14665@smallexample
14666(@value{GDBP}) @b{info trace}
1042e4c0
SS
14667Num Type Disp Enb Address What
146681 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14669 while-stepping 20
14670 collect globfoo, $regs
14671 end
14672 collect globfoo2
14673 end
1042e4c0 14674 pass count 1200
f2a8bc8a
YQ
146752 tracepoint keep y <MULTIPLE>
14676 collect $eip
146772.1 y 0x0804859c in func4 at change-loc.h:35
14678 installed on target
146792.2 y 0xb7ffc480 in func4 at change-loc.h:35
14680 installed on target
146812.3 y <PENDING> set_tracepoint
146823 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14683 not installed on target
b37052ae
EZ
14684(@value{GDBP})
14685@end smallexample
14686
14687@noindent
14688This command can be abbreviated @code{info tp}.
14689@end table
14690
0fb4aa4b
PA
14691@node Listing Static Tracepoint Markers
14692@subsection Listing Static Tracepoint Markers
14693
14694@table @code
14695@kindex info static-tracepoint-markers
14696@cindex information about static tracepoint markers
14697@item info static-tracepoint-markers
14698Display information about all static tracepoint markers defined in the
14699program.
14700
14701For each marker, the following columns are printed:
14702
14703@table @emph
14704@item Count
14705An incrementing counter, output to help readability. This is not a
14706stable identifier.
14707@item ID
14708The marker ID, as reported by the target.
14709@item Enabled or Disabled
14710Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14711that are not enabled.
14712@item Address
14713Where the marker is in your program, as a memory address.
14714@item What
14715Where the marker is in the source for your program, as a file and line
14716number. If the debug information included in the program does not
14717allow @value{GDBN} to locate the source of the marker, this column
14718will be left blank.
14719@end table
14720
14721@noindent
14722In addition, the following information may be printed for each marker:
14723
14724@table @emph
14725@item Data
14726User data passed to the tracing library by the marker call. In the
14727UST backend, this is the format string passed as argument to the
14728marker call.
14729@item Static tracepoints probing the marker
14730The list of static tracepoints attached to the marker.
14731@end table
14732
14733@smallexample
14734(@value{GDBP}) info static-tracepoint-markers
14735Cnt ID Enb Address What
147361 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14737 Data: number1 %d number2 %d
14738 Probed by static tracepoints: #2
147392 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14740 Data: str %s
14741(@value{GDBP})
14742@end smallexample
14743@end table
14744
79a6e687
BW
14745@node Starting and Stopping Trace Experiments
14746@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14747
14748@table @code
f196051f 14749@kindex tstart [ @var{notes} ]
b37052ae
EZ
14750@cindex start a new trace experiment
14751@cindex collected data discarded
14752@item tstart
f196051f
SS
14753This command starts the trace experiment, and begins collecting data.
14754It has the side effect of discarding all the data collected in the
14755trace buffer during the previous trace experiment. If any arguments
14756are supplied, they are taken as a note and stored with the trace
14757experiment's state. The notes may be arbitrary text, and are
14758especially useful with disconnected tracing in a multi-user context;
14759the notes can explain what the trace is doing, supply user contact
14760information, and so forth.
14761
14762@kindex tstop [ @var{notes} ]
b37052ae
EZ
14763@cindex stop a running trace experiment
14764@item tstop
f196051f
SS
14765This command stops the trace experiment. If any arguments are
14766supplied, they are recorded with the experiment as a note. This is
14767useful if you are stopping a trace started by someone else, for
14768instance if the trace is interfering with the system's behavior and
14769needs to be stopped quickly.
b37052ae 14770
68c71a2e 14771@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14772automatically if any tracepoint's passcount is reached
14773(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14774
14775@kindex tstatus
14776@cindex status of trace data collection
14777@cindex trace experiment, status of
14778@item tstatus
14779This command displays the status of the current trace data
14780collection.
14781@end table
14782
14783Here is an example of the commands we described so far:
14784
14785@smallexample
14786(@value{GDBP}) @b{trace gdb_c_test}
14787(@value{GDBP}) @b{actions}
14788Enter actions for tracepoint #1, one per line.
14789> collect $regs,$locals,$args
14790> while-stepping 11
14791 > collect $regs
14792 > end
14793> end
14794(@value{GDBP}) @b{tstart}
14795 [time passes @dots{}]
14796(@value{GDBP}) @b{tstop}
14797@end smallexample
14798
03f2bd59 14799@anchor{disconnected tracing}
d5551862
SS
14800@cindex disconnected tracing
14801You can choose to continue running the trace experiment even if
14802@value{GDBN} disconnects from the target, voluntarily or
14803involuntarily. For commands such as @code{detach}, the debugger will
14804ask what you want to do with the trace. But for unexpected
14805terminations (@value{GDBN} crash, network outage), it would be
14806unfortunate to lose hard-won trace data, so the variable
14807@code{disconnected-tracing} lets you decide whether the trace should
14808continue running without @value{GDBN}.
14809
14810@table @code
14811@item set disconnected-tracing on
14812@itemx set disconnected-tracing off
14813@kindex set disconnected-tracing
14814Choose whether a tracing run should continue to run if @value{GDBN}
14815has disconnected from the target. Note that @code{detach} or
14816@code{quit} will ask you directly what to do about a running trace no
14817matter what this variable's setting, so the variable is mainly useful
14818for handling unexpected situations, such as loss of the network.
14819
14820@item show disconnected-tracing
14821@kindex show disconnected-tracing
14822Show the current choice for disconnected tracing.
14823
14824@end table
14825
14826When you reconnect to the target, the trace experiment may or may not
14827still be running; it might have filled the trace buffer in the
14828meantime, or stopped for one of the other reasons. If it is running,
14829it will continue after reconnection.
14830
14831Upon reconnection, the target will upload information about the
14832tracepoints in effect. @value{GDBN} will then compare that
14833information to the set of tracepoints currently defined, and attempt
14834to match them up, allowing for the possibility that the numbers may
14835have changed due to creation and deletion in the meantime. If one of
14836the target's tracepoints does not match any in @value{GDBN}, the
14837debugger will create a new tracepoint, so that you have a number with
14838which to specify that tracepoint. This matching-up process is
14839necessarily heuristic, and it may result in useless tracepoints being
14840created; you may simply delete them if they are of no use.
b37052ae 14841
4daf5ac0
SS
14842@cindex circular trace buffer
14843If your target agent supports a @dfn{circular trace buffer}, then you
14844can run a trace experiment indefinitely without filling the trace
14845buffer; when space runs out, the agent deletes already-collected trace
14846frames, oldest first, until there is enough room to continue
14847collecting. This is especially useful if your tracepoints are being
14848hit too often, and your trace gets terminated prematurely because the
14849buffer is full. To ask for a circular trace buffer, simply set
81896e36 14850@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14851including during tracing; if the agent can do it, it will change
14852buffer handling on the fly, otherwise it will not take effect until
14853the next run.
14854
14855@table @code
14856@item set circular-trace-buffer on
14857@itemx set circular-trace-buffer off
14858@kindex set circular-trace-buffer
14859Choose whether a tracing run should use a linear or circular buffer
14860for trace data. A linear buffer will not lose any trace data, but may
14861fill up prematurely, while a circular buffer will discard old trace
14862data, but it will have always room for the latest tracepoint hits.
14863
14864@item show circular-trace-buffer
14865@kindex show circular-trace-buffer
14866Show the current choice for the trace buffer. Note that this may not
14867match the agent's current buffer handling, nor is it guaranteed to
14868match the setting that might have been in effect during a past run,
14869for instance if you are looking at frames from a trace file.
14870
14871@end table
14872
f6f899bf
HAQ
14873@table @code
14874@item set trace-buffer-size @var{n}
f81d1120 14875@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14876@kindex set trace-buffer-size
14877Request that the target use a trace buffer of @var{n} bytes. Not all
14878targets will honor the request; they may have a compiled-in size for
14879the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14880@code{unlimited} or @code{-1} to let the target use whatever size it
14881likes. This is also the default.
f6f899bf
HAQ
14882
14883@item show trace-buffer-size
14884@kindex show trace-buffer-size
14885Show the current requested size for the trace buffer. Note that this
14886will only match the actual size if the target supports size-setting,
14887and was able to handle the requested size. For instance, if the
14888target can only change buffer size between runs, this variable will
14889not reflect the change until the next run starts. Use @code{tstatus}
14890to get a report of the actual buffer size.
14891@end table
14892
f196051f
SS
14893@table @code
14894@item set trace-user @var{text}
14895@kindex set trace-user
14896
14897@item show trace-user
14898@kindex show trace-user
14899
14900@item set trace-notes @var{text}
14901@kindex set trace-notes
14902Set the trace run's notes.
14903
14904@item show trace-notes
14905@kindex show trace-notes
14906Show the trace run's notes.
14907
14908@item set trace-stop-notes @var{text}
14909@kindex set trace-stop-notes
14910Set the trace run's stop notes. The handling of the note is as for
14911@code{tstop} arguments; the set command is convenient way to fix a
14912stop note that is mistaken or incomplete.
14913
14914@item show trace-stop-notes
14915@kindex show trace-stop-notes
14916Show the trace run's stop notes.
14917
14918@end table
14919
c9429232
SS
14920@node Tracepoint Restrictions
14921@subsection Tracepoint Restrictions
14922
14923@cindex tracepoint restrictions
14924There are a number of restrictions on the use of tracepoints. As
14925described above, tracepoint data gathering occurs on the target
14926without interaction from @value{GDBN}. Thus the full capabilities of
14927the debugger are not available during data gathering, and then at data
14928examination time, you will be limited by only having what was
14929collected. The following items describe some common problems, but it
14930is not exhaustive, and you may run into additional difficulties not
14931mentioned here.
14932
14933@itemize @bullet
14934
14935@item
14936Tracepoint expressions are intended to gather objects (lvalues). Thus
14937the full flexibility of GDB's expression evaluator is not available.
14938You cannot call functions, cast objects to aggregate types, access
14939convenience variables or modify values (except by assignment to trace
14940state variables). Some language features may implicitly call
14941functions (for instance Objective-C fields with accessors), and therefore
14942cannot be collected either.
14943
14944@item
14945Collection of local variables, either individually or in bulk with
14946@code{$locals} or @code{$args}, during @code{while-stepping} may
14947behave erratically. The stepping action may enter a new scope (for
14948instance by stepping into a function), or the location of the variable
14949may change (for instance it is loaded into a register). The
14950tracepoint data recorded uses the location information for the
14951variables that is correct for the tracepoint location. When the
14952tracepoint is created, it is not possible, in general, to determine
14953where the steps of a @code{while-stepping} sequence will advance the
14954program---particularly if a conditional branch is stepped.
14955
14956@item
14957Collection of an incompletely-initialized or partially-destroyed object
14958may result in something that @value{GDBN} cannot display, or displays
14959in a misleading way.
14960
14961@item
14962When @value{GDBN} displays a pointer to character it automatically
14963dereferences the pointer to also display characters of the string
14964being pointed to. However, collecting the pointer during tracing does
14965not automatically collect the string. You need to explicitly
14966dereference the pointer and provide size information if you want to
14967collect not only the pointer, but the memory pointed to. For example,
14968@code{*ptr@@50} can be used to collect the 50 element array pointed to
14969by @code{ptr}.
14970
14971@item
14972It is not possible to collect a complete stack backtrace at a
14973tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 14974bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
14975(adjust to use the name of the actual stack pointer register on your
14976target architecture, and the amount of stack you wish to capture).
14977Then the @code{backtrace} command will show a partial backtrace when
14978using a trace frame. The number of stack frames that can be examined
14979depends on the sizes of the frames in the collected stack. Note that
14980if you ask for a block so large that it goes past the bottom of the
14981stack, the target agent may report an error trying to read from an
14982invalid address.
14983
af54718e
SS
14984@item
14985If you do not collect registers at a tracepoint, @value{GDBN} can
14986infer that the value of @code{$pc} must be the same as the address of
14987the tracepoint and use that when you are looking at a trace frame
14988for that tracepoint. However, this cannot work if the tracepoint has
14989multiple locations (for instance if it was set in a function that was
14990inlined), or if it has a @code{while-stepping} loop. In those cases
14991@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14992it to zero.
14993
c9429232
SS
14994@end itemize
14995
b37052ae 14996@node Analyze Collected Data
79a6e687 14997@section Using the Collected Data
b37052ae
EZ
14998
14999After the tracepoint experiment ends, you use @value{GDBN} commands
15000for examining the trace data. The basic idea is that each tracepoint
15001collects a trace @dfn{snapshot} every time it is hit and another
15002snapshot every time it single-steps. All these snapshots are
15003consecutively numbered from zero and go into a buffer, and you can
15004examine them later. The way you examine them is to @dfn{focus} on a
15005specific trace snapshot. When the remote stub is focused on a trace
15006snapshot, it will respond to all @value{GDBN} requests for memory and
15007registers by reading from the buffer which belongs to that snapshot,
15008rather than from @emph{real} memory or registers of the program being
15009debugged. This means that @strong{all} @value{GDBN} commands
15010(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15011behave as if we were currently debugging the program state as it was
15012when the tracepoint occurred. Any requests for data that are not in
15013the buffer will fail.
15014
15015@menu
15016* tfind:: How to select a trace snapshot
15017* tdump:: How to display all data for a snapshot
6149aea9 15018* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
15019@end menu
15020
15021@node tfind
15022@subsection @code{tfind @var{n}}
15023
15024@kindex tfind
15025@cindex select trace snapshot
15026@cindex find trace snapshot
15027The basic command for selecting a trace snapshot from the buffer is
15028@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15029counting from zero. If no argument @var{n} is given, the next
15030snapshot is selected.
15031
15032Here are the various forms of using the @code{tfind} command.
15033
15034@table @code
15035@item tfind start
15036Find the first snapshot in the buffer. This is a synonym for
15037@code{tfind 0} (since 0 is the number of the first snapshot).
15038
15039@item tfind none
15040Stop debugging trace snapshots, resume @emph{live} debugging.
15041
15042@item tfind end
15043Same as @samp{tfind none}.
15044
15045@item tfind
310cdbb6
YQ
15046No argument means find the next trace snapshot or find the first
15047one if no trace snapshot is selected.
b37052ae
EZ
15048
15049@item tfind -
15050Find the previous trace snapshot before the current one. This permits
15051retracing earlier steps.
15052
15053@item tfind tracepoint @var{num}
15054Find the next snapshot associated with tracepoint @var{num}. Search
15055proceeds forward from the last examined trace snapshot. If no
15056argument @var{num} is given, it means find the next snapshot collected
15057for the same tracepoint as the current snapshot.
15058
15059@item tfind pc @var{addr}
15060Find the next snapshot associated with the value @var{addr} of the
15061program counter. Search proceeds forward from the last examined trace
15062snapshot. If no argument @var{addr} is given, it means find the next
15063snapshot with the same value of PC as the current snapshot.
15064
15065@item tfind outside @var{addr1}, @var{addr2}
15066Find the next snapshot whose PC is outside the given range of
081dfbf7 15067addresses (exclusive).
b37052ae
EZ
15068
15069@item tfind range @var{addr1}, @var{addr2}
15070Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 15071@var{addr2} (inclusive).
b37052ae
EZ
15072
15073@item tfind line @r{[}@var{file}:@r{]}@var{n}
15074Find the next snapshot associated with the source line @var{n}. If
15075the optional argument @var{file} is given, refer to line @var{n} in
15076that source file. Search proceeds forward from the last examined
15077trace snapshot. If no argument @var{n} is given, it means find the
15078next line other than the one currently being examined; thus saying
15079@code{tfind line} repeatedly can appear to have the same effect as
15080stepping from line to line in a @emph{live} debugging session.
15081@end table
15082
15083The default arguments for the @code{tfind} commands are specifically
15084designed to make it easy to scan through the trace buffer. For
15085instance, @code{tfind} with no argument selects the next trace
15086snapshot, and @code{tfind -} with no argument selects the previous
15087trace snapshot. So, by giving one @code{tfind} command, and then
15088simply hitting @key{RET} repeatedly you can examine all the trace
15089snapshots in order. Or, by saying @code{tfind -} and then hitting
15090@key{RET} repeatedly you can examine the snapshots in reverse order.
15091The @code{tfind line} command with no argument selects the snapshot
15092for the next source line executed. The @code{tfind pc} command with
15093no argument selects the next snapshot with the same program counter
15094(PC) as the current frame. The @code{tfind tracepoint} command with
15095no argument selects the next trace snapshot collected by the same
15096tracepoint as the current one.
15097
15098In addition to letting you scan through the trace buffer manually,
15099these commands make it easy to construct @value{GDBN} scripts that
15100scan through the trace buffer and print out whatever collected data
15101you are interested in. Thus, if we want to examine the PC, FP, and SP
15102registers from each trace frame in the buffer, we can say this:
15103
15104@smallexample
15105(@value{GDBP}) @b{tfind start}
15106(@value{GDBP}) @b{while ($trace_frame != -1)}
15107> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15108 $trace_frame, $pc, $sp, $fp
15109> tfind
15110> end
15111
15112Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15113Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15114Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15115Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15116Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15117Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15118Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15119Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15120Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15121Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15122Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15123@end smallexample
15124
15125Or, if we want to examine the variable @code{X} at each source line in
15126the buffer:
15127
15128@smallexample
15129(@value{GDBP}) @b{tfind start}
15130(@value{GDBP}) @b{while ($trace_frame != -1)}
15131> printf "Frame %d, X == %d\n", $trace_frame, X
15132> tfind line
15133> end
15134
15135Frame 0, X = 1
15136Frame 7, X = 2
15137Frame 13, X = 255
15138@end smallexample
15139
15140@node tdump
15141@subsection @code{tdump}
15142@kindex tdump
15143@cindex dump all data collected at tracepoint
15144@cindex tracepoint data, display
15145
15146This command takes no arguments. It prints all the data collected at
15147the current trace snapshot.
15148
15149@smallexample
15150(@value{GDBP}) @b{trace 444}
15151(@value{GDBP}) @b{actions}
15152Enter actions for tracepoint #2, one per line:
15153> collect $regs, $locals, $args, gdb_long_test
15154> end
15155
15156(@value{GDBP}) @b{tstart}
15157
15158(@value{GDBP}) @b{tfind line 444}
15159#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15160at gdb_test.c:444
15161444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15162
15163(@value{GDBP}) @b{tdump}
15164Data collected at tracepoint 2, trace frame 1:
15165d0 0xc4aa0085 -995491707
15166d1 0x18 24
15167d2 0x80 128
15168d3 0x33 51
15169d4 0x71aea3d 119204413
15170d5 0x22 34
15171d6 0xe0 224
15172d7 0x380035 3670069
15173a0 0x19e24a 1696330
15174a1 0x3000668 50333288
15175a2 0x100 256
15176a3 0x322000 3284992
15177a4 0x3000698 50333336
15178a5 0x1ad3cc 1758156
15179fp 0x30bf3c 0x30bf3c
15180sp 0x30bf34 0x30bf34
15181ps 0x0 0
15182pc 0x20b2c8 0x20b2c8
15183fpcontrol 0x0 0
15184fpstatus 0x0 0
15185fpiaddr 0x0 0
15186p = 0x20e5b4 "gdb-test"
15187p1 = (void *) 0x11
15188p2 = (void *) 0x22
15189p3 = (void *) 0x33
15190p4 = (void *) 0x44
15191p5 = (void *) 0x55
15192p6 = (void *) 0x66
15193gdb_long_test = 17 '\021'
15194
15195(@value{GDBP})
15196@end smallexample
15197
af54718e
SS
15198@code{tdump} works by scanning the tracepoint's current collection
15199actions and printing the value of each expression listed. So
15200@code{tdump} can fail, if after a run, you change the tracepoint's
15201actions to mention variables that were not collected during the run.
15202
15203Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15204uses the collected value of @code{$pc} to distinguish between trace
15205frames that were collected at the tracepoint hit, and frames that were
15206collected while stepping. This allows it to correctly choose whether
15207to display the basic list of collections, or the collections from the
15208body of the while-stepping loop. However, if @code{$pc} was not collected,
15209then @code{tdump} will always attempt to dump using the basic collection
15210list, and may fail if a while-stepping frame does not include all the
15211same data that is collected at the tracepoint hit.
15212@c This is getting pretty arcane, example would be good.
15213
6149aea9
PA
15214@node save tracepoints
15215@subsection @code{save tracepoints @var{filename}}
15216@kindex save tracepoints
b37052ae
EZ
15217@kindex save-tracepoints
15218@cindex save tracepoints for future sessions
15219
15220This command saves all current tracepoint definitions together with
15221their actions and passcounts, into a file @file{@var{filename}}
15222suitable for use in a later debugging session. To read the saved
15223tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15224Files}). The @w{@code{save-tracepoints}} command is a deprecated
15225alias for @w{@code{save tracepoints}}
b37052ae
EZ
15226
15227@node Tracepoint Variables
15228@section Convenience Variables for Tracepoints
15229@cindex tracepoint variables
15230@cindex convenience variables for tracepoints
15231
15232@table @code
15233@vindex $trace_frame
15234@item (int) $trace_frame
15235The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15236snapshot is selected.
15237
15238@vindex $tracepoint
15239@item (int) $tracepoint
15240The tracepoint for the current trace snapshot.
15241
15242@vindex $trace_line
15243@item (int) $trace_line
15244The line number for the current trace snapshot.
15245
15246@vindex $trace_file
15247@item (char []) $trace_file
15248The source file for the current trace snapshot.
15249
15250@vindex $trace_func
15251@item (char []) $trace_func
15252The name of the function containing @code{$tracepoint}.
15253@end table
15254
15255Note: @code{$trace_file} is not suitable for use in @code{printf},
15256use @code{output} instead.
15257
15258Here's a simple example of using these convenience variables for
15259stepping through all the trace snapshots and printing some of their
f61e138d
SS
15260data. Note that these are not the same as trace state variables,
15261which are managed by the target.
b37052ae
EZ
15262
15263@smallexample
15264(@value{GDBP}) @b{tfind start}
15265
15266(@value{GDBP}) @b{while $trace_frame != -1}
15267> output $trace_file
15268> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15269> tfind
15270> end
15271@end smallexample
15272
00bf0b85
SS
15273@node Trace Files
15274@section Using Trace Files
15275@cindex trace files
15276
15277In some situations, the target running a trace experiment may no
15278longer be available; perhaps it crashed, or the hardware was needed
15279for a different activity. To handle these cases, you can arrange to
15280dump the trace data into a file, and later use that file as a source
15281of trace data, via the @code{target tfile} command.
15282
15283@table @code
15284
15285@kindex tsave
15286@item tsave [ -r ] @var{filename}
d0353e76 15287@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15288Save the trace data to @var{filename}. By default, this command
15289assumes that @var{filename} refers to the host filesystem, so if
15290necessary @value{GDBN} will copy raw trace data up from the target and
15291then save it. If the target supports it, you can also supply the
15292optional argument @code{-r} (``remote'') to direct the target to save
15293the data directly into @var{filename} in its own filesystem, which may be
15294more efficient if the trace buffer is very large. (Note, however, that
15295@code{target tfile} can only read from files accessible to the host.)
d0353e76 15296By default, this command will save trace frame in tfile format.
be06ba8c 15297You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15298format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15299that can be shared by multiple debugging and tracing tools. Please go to
15300@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15301
15302@kindex target tfile
15303@kindex tfile
393fd4c3
YQ
15304@kindex target ctf
15305@kindex ctf
00bf0b85 15306@item target tfile @var{filename}
393fd4c3
YQ
15307@itemx target ctf @var{dirname}
15308Use the file named @var{filename} or directory named @var{dirname} as
15309a source of trace data. Commands that examine data work as they do with
15310a live target, but it is not possible to run any new trace experiments.
15311@code{tstatus} will report the state of the trace run at the moment
15312the data was saved, as well as the current trace frame you are examining.
697aa1b7 15313Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15314the host.
15315
15316@smallexample
15317(@value{GDBP}) target ctf ctf.ctf
15318(@value{GDBP}) tfind
15319Found trace frame 0, tracepoint 2
1532039 ++a; /* set tracepoint 1 here */
15321(@value{GDBP}) tdump
15322Data collected at tracepoint 2, trace frame 0:
15323i = 0
15324a = 0
15325b = 1 '\001'
15326c = @{"123", "456", "789", "123", "456", "789"@}
15327d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15328(@value{GDBP}) p b
15329$1 = 1
15330@end smallexample
00bf0b85
SS
15331
15332@end table
15333
df0cd8c5
JB
15334@node Overlays
15335@chapter Debugging Programs That Use Overlays
15336@cindex overlays
15337
15338If your program is too large to fit completely in your target system's
15339memory, you can sometimes use @dfn{overlays} to work around this
15340problem. @value{GDBN} provides some support for debugging programs that
15341use overlays.
15342
15343@menu
15344* How Overlays Work:: A general explanation of overlays.
15345* Overlay Commands:: Managing overlays in @value{GDBN}.
15346* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15347 mapped by asking the inferior.
15348* Overlay Sample Program:: A sample program using overlays.
15349@end menu
15350
15351@node How Overlays Work
15352@section How Overlays Work
15353@cindex mapped overlays
15354@cindex unmapped overlays
15355@cindex load address, overlay's
15356@cindex mapped address
15357@cindex overlay area
15358
15359Suppose you have a computer whose instruction address space is only 64
15360kilobytes long, but which has much more memory which can be accessed by
15361other means: special instructions, segment registers, or memory
15362management hardware, for example. Suppose further that you want to
15363adapt a program which is larger than 64 kilobytes to run on this system.
15364
15365One solution is to identify modules of your program which are relatively
15366independent, and need not call each other directly; call these modules
15367@dfn{overlays}. Separate the overlays from the main program, and place
15368their machine code in the larger memory. Place your main program in
15369instruction memory, but leave at least enough space there to hold the
15370largest overlay as well.
15371
15372Now, to call a function located in an overlay, you must first copy that
15373overlay's machine code from the large memory into the space set aside
15374for it in the instruction memory, and then jump to its entry point
15375there.
15376
c928edc0
AC
15377@c NB: In the below the mapped area's size is greater or equal to the
15378@c size of all overlays. This is intentional to remind the developer
15379@c that overlays don't necessarily need to be the same size.
15380
474c8240 15381@smallexample
df0cd8c5 15382@group
c928edc0
AC
15383 Data Instruction Larger
15384Address Space Address Space Address Space
15385+-----------+ +-----------+ +-----------+
15386| | | | | |
15387+-----------+ +-----------+ +-----------+<-- overlay 1
15388| program | | main | .----| overlay 1 | load address
15389| variables | | program | | +-----------+
15390| and heap | | | | | |
15391+-----------+ | | | +-----------+<-- overlay 2
15392| | +-----------+ | | | load address
15393+-----------+ | | | .-| overlay 2 |
15394 | | | | | |
15395 mapped --->+-----------+ | | +-----------+
15396 address | | | | | |
15397 | overlay | <-' | | |
15398 | area | <---' +-----------+<-- overlay 3
15399 | | <---. | | load address
15400 +-----------+ `--| overlay 3 |
15401 | | | |
15402 +-----------+ | |
15403 +-----------+
15404 | |
15405 +-----------+
15406
15407 @anchor{A code overlay}A code overlay
df0cd8c5 15408@end group
474c8240 15409@end smallexample
df0cd8c5 15410
c928edc0
AC
15411The diagram (@pxref{A code overlay}) shows a system with separate data
15412and instruction address spaces. To map an overlay, the program copies
15413its code from the larger address space to the instruction address space.
15414Since the overlays shown here all use the same mapped address, only one
15415may be mapped at a time. For a system with a single address space for
15416data and instructions, the diagram would be similar, except that the
15417program variables and heap would share an address space with the main
15418program and the overlay area.
df0cd8c5
JB
15419
15420An overlay loaded into instruction memory and ready for use is called a
15421@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15422instruction memory. An overlay not present (or only partially present)
15423in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15424is its address in the larger memory. The mapped address is also called
15425the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15426called the @dfn{load memory address}, or @dfn{LMA}.
15427
15428Unfortunately, overlays are not a completely transparent way to adapt a
15429program to limited instruction memory. They introduce a new set of
15430global constraints you must keep in mind as you design your program:
15431
15432@itemize @bullet
15433
15434@item
15435Before calling or returning to a function in an overlay, your program
15436must make sure that overlay is actually mapped. Otherwise, the call or
15437return will transfer control to the right address, but in the wrong
15438overlay, and your program will probably crash.
15439
15440@item
15441If the process of mapping an overlay is expensive on your system, you
15442will need to choose your overlays carefully to minimize their effect on
15443your program's performance.
15444
15445@item
15446The executable file you load onto your system must contain each
15447overlay's instructions, appearing at the overlay's load address, not its
15448mapped address. However, each overlay's instructions must be relocated
15449and its symbols defined as if the overlay were at its mapped address.
15450You can use GNU linker scripts to specify different load and relocation
15451addresses for pieces of your program; see @ref{Overlay Description,,,
15452ld.info, Using ld: the GNU linker}.
15453
15454@item
15455The procedure for loading executable files onto your system must be able
15456to load their contents into the larger address space as well as the
15457instruction and data spaces.
15458
15459@end itemize
15460
15461The overlay system described above is rather simple, and could be
15462improved in many ways:
15463
15464@itemize @bullet
15465
15466@item
15467If your system has suitable bank switch registers or memory management
15468hardware, you could use those facilities to make an overlay's load area
15469contents simply appear at their mapped address in instruction space.
15470This would probably be faster than copying the overlay to its mapped
15471area in the usual way.
15472
15473@item
15474If your overlays are small enough, you could set aside more than one
15475overlay area, and have more than one overlay mapped at a time.
15476
15477@item
15478You can use overlays to manage data, as well as instructions. In
15479general, data overlays are even less transparent to your design than
15480code overlays: whereas code overlays only require care when you call or
15481return to functions, data overlays require care every time you access
15482the data. Also, if you change the contents of a data overlay, you
15483must copy its contents back out to its load address before you can copy a
15484different data overlay into the same mapped area.
15485
15486@end itemize
15487
15488
15489@node Overlay Commands
15490@section Overlay Commands
15491
15492To use @value{GDBN}'s overlay support, each overlay in your program must
15493correspond to a separate section of the executable file. The section's
15494virtual memory address and load memory address must be the overlay's
15495mapped and load addresses. Identifying overlays with sections allows
15496@value{GDBN} to determine the appropriate address of a function or
15497variable, depending on whether the overlay is mapped or not.
15498
15499@value{GDBN}'s overlay commands all start with the word @code{overlay};
15500you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15501
15502@table @code
15503@item overlay off
4644b6e3 15504@kindex overlay
df0cd8c5
JB
15505Disable @value{GDBN}'s overlay support. When overlay support is
15506disabled, @value{GDBN} assumes that all functions and variables are
15507always present at their mapped addresses. By default, @value{GDBN}'s
15508overlay support is disabled.
15509
15510@item overlay manual
df0cd8c5
JB
15511@cindex manual overlay debugging
15512Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15513relies on you to tell it which overlays are mapped, and which are not,
15514using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15515commands described below.
15516
15517@item overlay map-overlay @var{overlay}
15518@itemx overlay map @var{overlay}
df0cd8c5
JB
15519@cindex map an overlay
15520Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15521be the name of the object file section containing the overlay. When an
15522overlay is mapped, @value{GDBN} assumes it can find the overlay's
15523functions and variables at their mapped addresses. @value{GDBN} assumes
15524that any other overlays whose mapped ranges overlap that of
15525@var{overlay} are now unmapped.
15526
15527@item overlay unmap-overlay @var{overlay}
15528@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15529@cindex unmap an overlay
15530Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15531must be the name of the object file section containing the overlay.
15532When an overlay is unmapped, @value{GDBN} assumes it can find the
15533overlay's functions and variables at their load addresses.
15534
15535@item overlay auto
df0cd8c5
JB
15536Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15537consults a data structure the overlay manager maintains in the inferior
15538to see which overlays are mapped. For details, see @ref{Automatic
15539Overlay Debugging}.
15540
15541@item overlay load-target
15542@itemx overlay load
df0cd8c5
JB
15543@cindex reloading the overlay table
15544Re-read the overlay table from the inferior. Normally, @value{GDBN}
15545re-reads the table @value{GDBN} automatically each time the inferior
15546stops, so this command should only be necessary if you have changed the
15547overlay mapping yourself using @value{GDBN}. This command is only
15548useful when using automatic overlay debugging.
15549
15550@item overlay list-overlays
15551@itemx overlay list
15552@cindex listing mapped overlays
15553Display a list of the overlays currently mapped, along with their mapped
15554addresses, load addresses, and sizes.
15555
15556@end table
15557
15558Normally, when @value{GDBN} prints a code address, it includes the name
15559of the function the address falls in:
15560
474c8240 15561@smallexample
f7dc1244 15562(@value{GDBP}) print main
df0cd8c5 15563$3 = @{int ()@} 0x11a0 <main>
474c8240 15564@end smallexample
df0cd8c5
JB
15565@noindent
15566When overlay debugging is enabled, @value{GDBN} recognizes code in
15567unmapped overlays, and prints the names of unmapped functions with
15568asterisks around them. For example, if @code{foo} is a function in an
15569unmapped overlay, @value{GDBN} prints it this way:
15570
474c8240 15571@smallexample
f7dc1244 15572(@value{GDBP}) overlay list
df0cd8c5 15573No sections are mapped.
f7dc1244 15574(@value{GDBP}) print foo
df0cd8c5 15575$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15576@end smallexample
df0cd8c5
JB
15577@noindent
15578When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15579name normally:
15580
474c8240 15581@smallexample
f7dc1244 15582(@value{GDBP}) overlay list
b383017d 15583Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15584 mapped at 0x1016 - 0x104a
f7dc1244 15585(@value{GDBP}) print foo
df0cd8c5 15586$6 = @{int (int)@} 0x1016 <foo>
474c8240 15587@end smallexample
df0cd8c5
JB
15588
15589When overlay debugging is enabled, @value{GDBN} can find the correct
15590address for functions and variables in an overlay, whether or not the
15591overlay is mapped. This allows most @value{GDBN} commands, like
15592@code{break} and @code{disassemble}, to work normally, even on unmapped
15593code. However, @value{GDBN}'s breakpoint support has some limitations:
15594
15595@itemize @bullet
15596@item
15597@cindex breakpoints in overlays
15598@cindex overlays, setting breakpoints in
15599You can set breakpoints in functions in unmapped overlays, as long as
15600@value{GDBN} can write to the overlay at its load address.
15601@item
15602@value{GDBN} can not set hardware or simulator-based breakpoints in
15603unmapped overlays. However, if you set a breakpoint at the end of your
15604overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15605you are using manual overlay management), @value{GDBN} will re-set its
15606breakpoints properly.
15607@end itemize
15608
15609
15610@node Automatic Overlay Debugging
15611@section Automatic Overlay Debugging
15612@cindex automatic overlay debugging
15613
15614@value{GDBN} can automatically track which overlays are mapped and which
15615are not, given some simple co-operation from the overlay manager in the
15616inferior. If you enable automatic overlay debugging with the
15617@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15618looks in the inferior's memory for certain variables describing the
15619current state of the overlays.
15620
15621Here are the variables your overlay manager must define to support
15622@value{GDBN}'s automatic overlay debugging:
15623
15624@table @asis
15625
15626@item @code{_ovly_table}:
15627This variable must be an array of the following structures:
15628
474c8240 15629@smallexample
df0cd8c5
JB
15630struct
15631@{
15632 /* The overlay's mapped address. */
15633 unsigned long vma;
15634
15635 /* The size of the overlay, in bytes. */
15636 unsigned long size;
15637
15638 /* The overlay's load address. */
15639 unsigned long lma;
15640
15641 /* Non-zero if the overlay is currently mapped;
15642 zero otherwise. */
15643 unsigned long mapped;
15644@}
474c8240 15645@end smallexample
df0cd8c5
JB
15646
15647@item @code{_novlys}:
15648This variable must be a four-byte signed integer, holding the total
15649number of elements in @code{_ovly_table}.
15650
15651@end table
15652
15653To decide whether a particular overlay is mapped or not, @value{GDBN}
15654looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15655@code{lma} members equal the VMA and LMA of the overlay's section in the
15656executable file. When @value{GDBN} finds a matching entry, it consults
15657the entry's @code{mapped} member to determine whether the overlay is
15658currently mapped.
15659
81d46470 15660In addition, your overlay manager may define a function called
def71bfa 15661@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15662will silently set a breakpoint there. If the overlay manager then
15663calls this function whenever it has changed the overlay table, this
15664will enable @value{GDBN} to accurately keep track of which overlays
15665are in program memory, and update any breakpoints that may be set
b383017d 15666in overlays. This will allow breakpoints to work even if the
81d46470
MS
15667overlays are kept in ROM or other non-writable memory while they
15668are not being executed.
df0cd8c5
JB
15669
15670@node Overlay Sample Program
15671@section Overlay Sample Program
15672@cindex overlay example program
15673
15674When linking a program which uses overlays, you must place the overlays
15675at their load addresses, while relocating them to run at their mapped
15676addresses. To do this, you must write a linker script (@pxref{Overlay
15677Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15678since linker scripts are specific to a particular host system, target
15679architecture, and target memory layout, this manual cannot provide
15680portable sample code demonstrating @value{GDBN}'s overlay support.
15681
15682However, the @value{GDBN} source distribution does contain an overlaid
15683program, with linker scripts for a few systems, as part of its test
15684suite. The program consists of the following files from
15685@file{gdb/testsuite/gdb.base}:
15686
15687@table @file
15688@item overlays.c
15689The main program file.
15690@item ovlymgr.c
15691A simple overlay manager, used by @file{overlays.c}.
15692@item foo.c
15693@itemx bar.c
15694@itemx baz.c
15695@itemx grbx.c
15696Overlay modules, loaded and used by @file{overlays.c}.
15697@item d10v.ld
15698@itemx m32r.ld
15699Linker scripts for linking the test program on the @code{d10v-elf}
15700and @code{m32r-elf} targets.
15701@end table
15702
15703You can build the test program using the @code{d10v-elf} GCC
15704cross-compiler like this:
15705
474c8240 15706@smallexample
df0cd8c5
JB
15707$ d10v-elf-gcc -g -c overlays.c
15708$ d10v-elf-gcc -g -c ovlymgr.c
15709$ d10v-elf-gcc -g -c foo.c
15710$ d10v-elf-gcc -g -c bar.c
15711$ d10v-elf-gcc -g -c baz.c
15712$ d10v-elf-gcc -g -c grbx.c
15713$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15714 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15715@end smallexample
df0cd8c5
JB
15716
15717The build process is identical for any other architecture, except that
15718you must substitute the appropriate compiler and linker script for the
15719target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15720
15721
6d2ebf8b 15722@node Languages
c906108c
SS
15723@chapter Using @value{GDBN} with Different Languages
15724@cindex languages
15725
c906108c
SS
15726Although programming languages generally have common aspects, they are
15727rarely expressed in the same manner. For instance, in ANSI C,
15728dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15729Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15730represented (and displayed) differently. Hex numbers in C appear as
c906108c 15731@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15732
15733@cindex working language
15734Language-specific information is built into @value{GDBN} for some languages,
15735allowing you to express operations like the above in your program's
15736native language, and allowing @value{GDBN} to output values in a manner
15737consistent with the syntax of your program's native language. The
15738language you use to build expressions is called the @dfn{working
15739language}.
15740
15741@menu
15742* Setting:: Switching between source languages
15743* Show:: Displaying the language
c906108c 15744* Checks:: Type and range checks
79a6e687
BW
15745* Supported Languages:: Supported languages
15746* Unsupported Languages:: Unsupported languages
c906108c
SS
15747@end menu
15748
6d2ebf8b 15749@node Setting
79a6e687 15750@section Switching Between Source Languages
c906108c
SS
15751
15752There are two ways to control the working language---either have @value{GDBN}
15753set it automatically, or select it manually yourself. You can use the
15754@code{set language} command for either purpose. On startup, @value{GDBN}
15755defaults to setting the language automatically. The working language is
15756used to determine how expressions you type are interpreted, how values
15757are printed, etc.
15758
15759In addition to the working language, every source file that
15760@value{GDBN} knows about has its own working language. For some object
15761file formats, the compiler might indicate which language a particular
15762source file is in. However, most of the time @value{GDBN} infers the
15763language from the name of the file. The language of a source file
b37052ae 15764controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15765show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15766set the language of a source file from within @value{GDBN}, but you can
15767set the language associated with a filename extension. @xref{Show, ,
79a6e687 15768Displaying the Language}.
c906108c
SS
15769
15770This is most commonly a problem when you use a program, such
5d161b24 15771as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15772another language. In that case, make the
15773program use @code{#line} directives in its C output; that way
15774@value{GDBN} will know the correct language of the source code of the original
15775program, and will display that source code, not the generated C code.
15776
15777@menu
15778* Filenames:: Filename extensions and languages.
15779* Manually:: Setting the working language manually
15780* Automatically:: Having @value{GDBN} infer the source language
15781@end menu
15782
6d2ebf8b 15783@node Filenames
79a6e687 15784@subsection List of Filename Extensions and Languages
c906108c
SS
15785
15786If a source file name ends in one of the following extensions, then
15787@value{GDBN} infers that its language is the one indicated.
15788
15789@table @file
e07c999f
PH
15790@item .ada
15791@itemx .ads
15792@itemx .adb
15793@itemx .a
15794Ada source file.
c906108c
SS
15795
15796@item .c
15797C source file
15798
15799@item .C
15800@itemx .cc
15801@itemx .cp
15802@itemx .cpp
15803@itemx .cxx
15804@itemx .c++
b37052ae 15805C@t{++} source file
c906108c 15806
6aecb9c2
JB
15807@item .d
15808D source file
15809
b37303ee
AF
15810@item .m
15811Objective-C source file
15812
c906108c
SS
15813@item .f
15814@itemx .F
15815Fortran source file
15816
c906108c
SS
15817@item .mod
15818Modula-2 source file
c906108c
SS
15819
15820@item .s
15821@itemx .S
15822Assembler source file. This actually behaves almost like C, but
15823@value{GDBN} does not skip over function prologues when stepping.
15824@end table
15825
15826In addition, you may set the language associated with a filename
79a6e687 15827extension. @xref{Show, , Displaying the Language}.
c906108c 15828
6d2ebf8b 15829@node Manually
79a6e687 15830@subsection Setting the Working Language
c906108c
SS
15831
15832If you allow @value{GDBN} to set the language automatically,
15833expressions are interpreted the same way in your debugging session and
15834your program.
15835
15836@kindex set language
15837If you wish, you may set the language manually. To do this, issue the
15838command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15839a language, such as
c906108c 15840@code{c} or @code{modula-2}.
c906108c
SS
15841For a list of the supported languages, type @samp{set language}.
15842
c906108c
SS
15843Setting the language manually prevents @value{GDBN} from updating the working
15844language automatically. This can lead to confusion if you try
15845to debug a program when the working language is not the same as the
15846source language, when an expression is acceptable to both
15847languages---but means different things. For instance, if the current
15848source file were written in C, and @value{GDBN} was parsing Modula-2, a
15849command such as:
15850
474c8240 15851@smallexample
c906108c 15852print a = b + c
474c8240 15853@end smallexample
c906108c
SS
15854
15855@noindent
15856might not have the effect you intended. In C, this means to add
15857@code{b} and @code{c} and place the result in @code{a}. The result
15858printed would be the value of @code{a}. In Modula-2, this means to compare
15859@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15860
6d2ebf8b 15861@node Automatically
79a6e687 15862@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15863
15864To have @value{GDBN} set the working language automatically, use
15865@samp{set language local} or @samp{set language auto}. @value{GDBN}
15866then infers the working language. That is, when your program stops in a
15867frame (usually by encountering a breakpoint), @value{GDBN} sets the
15868working language to the language recorded for the function in that
15869frame. If the language for a frame is unknown (that is, if the function
15870or block corresponding to the frame was defined in a source file that
15871does not have a recognized extension), the current working language is
15872not changed, and @value{GDBN} issues a warning.
15873
15874This may not seem necessary for most programs, which are written
15875entirely in one source language. However, program modules and libraries
15876written in one source language can be used by a main program written in
15877a different source language. Using @samp{set language auto} in this
15878case frees you from having to set the working language manually.
15879
6d2ebf8b 15880@node Show
79a6e687 15881@section Displaying the Language
c906108c
SS
15882
15883The following commands help you find out which language is the
15884working language, and also what language source files were written in.
15885
c906108c
SS
15886@table @code
15887@item show language
403cb6b1 15888@anchor{show language}
9c16f35a 15889@kindex show language
c906108c
SS
15890Display the current working language. This is the
15891language you can use with commands such as @code{print} to
15892build and compute expressions that may involve variables in your program.
15893
15894@item info frame
4644b6e3 15895@kindex info frame@r{, show the source language}
5d161b24 15896Display the source language for this frame. This language becomes the
c906108c 15897working language if you use an identifier from this frame.
79a6e687 15898@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15899information listed here.
15900
15901@item info source
4644b6e3 15902@kindex info source@r{, show the source language}
c906108c 15903Display the source language of this source file.
5d161b24 15904@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15905information listed here.
15906@end table
15907
15908In unusual circumstances, you may have source files with extensions
15909not in the standard list. You can then set the extension associated
15910with a language explicitly:
15911
c906108c 15912@table @code
09d4efe1 15913@item set extension-language @var{ext} @var{language}
9c16f35a 15914@kindex set extension-language
09d4efe1
EZ
15915Tell @value{GDBN} that source files with extension @var{ext} are to be
15916assumed as written in the source language @var{language}.
c906108c
SS
15917
15918@item info extensions
9c16f35a 15919@kindex info extensions
c906108c
SS
15920List all the filename extensions and the associated languages.
15921@end table
15922
6d2ebf8b 15923@node Checks
79a6e687 15924@section Type and Range Checking
c906108c 15925
c906108c
SS
15926Some languages are designed to guard you against making seemingly common
15927errors through a series of compile- and run-time checks. These include
a451cb65 15928checking the type of arguments to functions and operators and making
c906108c
SS
15929sure mathematical overflows are caught at run time. Checks such as
15930these help to ensure a program's correctness once it has been compiled
a451cb65 15931by eliminating type mismatches and providing active checks for range
c906108c
SS
15932errors when your program is running.
15933
a451cb65
KS
15934By default @value{GDBN} checks for these errors according to the
15935rules of the current source language. Although @value{GDBN} does not check
15936the statements in your program, it can check expressions entered directly
15937into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15938
15939@menu
15940* Type Checking:: An overview of type checking
15941* Range Checking:: An overview of range checking
15942@end menu
15943
15944@cindex type checking
15945@cindex checks, type
6d2ebf8b 15946@node Type Checking
79a6e687 15947@subsection An Overview of Type Checking
c906108c 15948
a451cb65 15949Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
15950arguments to operators and functions have to be of the correct type,
15951otherwise an error occurs. These checks prevent type mismatch
15952errors from ever causing any run-time problems. For example,
15953
15954@smallexample
a451cb65
KS
15955int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15956
15957(@value{GDBP}) print obj.my_method (0)
15958$1 = 2
c906108c 15959@exdent but
a451cb65
KS
15960(@value{GDBP}) print obj.my_method (0x1234)
15961Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
15962@end smallexample
15963
a451cb65
KS
15964The second example fails because in C@t{++} the integer constant
15965@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 15966
a451cb65
KS
15967For the expressions you use in @value{GDBN} commands, you can tell
15968@value{GDBN} to not enforce strict type checking or
5d161b24 15969to treat any mismatches as errors and abandon the expression;
a451cb65
KS
15970When type checking is disabled, @value{GDBN} successfully evaluates
15971expressions like the second example above.
c906108c 15972
a451cb65 15973Even if type checking is off, there may be other reasons
5d161b24
DB
15974related to type that prevent @value{GDBN} from evaluating an expression.
15975For instance, @value{GDBN} does not know how to add an @code{int} and
15976a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
15977with the language in use and usually arise from expressions which make
15978little sense to evaluate anyway.
c906108c 15979
a451cb65 15980@value{GDBN} provides some additional commands for controlling type checking:
c906108c 15981
c906108c
SS
15982@kindex set check type
15983@kindex show check type
15984@table @code
c906108c
SS
15985@item set check type on
15986@itemx set check type off
a451cb65 15987Set strict type checking on or off. If any type mismatches occur in
d4f3574e 15988evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
15989message and aborts evaluation of the expression.
15990
a451cb65
KS
15991@item show check type
15992Show the current setting of type checking and whether @value{GDBN}
15993is enforcing strict type checking rules.
c906108c
SS
15994@end table
15995
15996@cindex range checking
15997@cindex checks, range
6d2ebf8b 15998@node Range Checking
79a6e687 15999@subsection An Overview of Range Checking
c906108c
SS
16000
16001In some languages (such as Modula-2), it is an error to exceed the
16002bounds of a type; this is enforced with run-time checks. Such range
16003checking is meant to ensure program correctness by making sure
16004computations do not overflow, or indices on an array element access do
16005not exceed the bounds of the array.
16006
16007For expressions you use in @value{GDBN} commands, you can tell
16008@value{GDBN} to treat range errors in one of three ways: ignore them,
16009always treat them as errors and abandon the expression, or issue
16010warnings but evaluate the expression anyway.
16011
16012A range error can result from numerical overflow, from exceeding an
16013array index bound, or when you type a constant that is not a member
16014of any type. Some languages, however, do not treat overflows as an
16015error. In many implementations of C, mathematical overflow causes the
16016result to ``wrap around'' to lower values---for example, if @var{m} is
16017the largest integer value, and @var{s} is the smallest, then
16018
474c8240 16019@smallexample
c906108c 16020@var{m} + 1 @result{} @var{s}
474c8240 16021@end smallexample
c906108c
SS
16022
16023This, too, is specific to individual languages, and in some cases
79a6e687
BW
16024specific to individual compilers or machines. @xref{Supported Languages, ,
16025Supported Languages}, for further details on specific languages.
c906108c
SS
16026
16027@value{GDBN} provides some additional commands for controlling the range checker:
16028
c906108c
SS
16029@kindex set check range
16030@kindex show check range
16031@table @code
16032@item set check range auto
16033Set range checking on or off based on the current working language.
79a6e687 16034@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
16035each language.
16036
16037@item set check range on
16038@itemx set check range off
16039Set range checking on or off, overriding the default setting for the
16040current working language. A warning is issued if the setting does not
c3f6f71d
JM
16041match the language default. If a range error occurs and range checking is on,
16042then a message is printed and evaluation of the expression is aborted.
c906108c
SS
16043
16044@item set check range warn
16045Output messages when the @value{GDBN} range checker detects a range error,
16046but attempt to evaluate the expression anyway. Evaluating the
16047expression may still be impossible for other reasons, such as accessing
16048memory that the process does not own (a typical example from many Unix
16049systems).
16050
16051@item show range
16052Show the current setting of the range checker, and whether or not it is
16053being set automatically by @value{GDBN}.
16054@end table
c906108c 16055
79a6e687
BW
16056@node Supported Languages
16057@section Supported Languages
c906108c 16058
9c37b5ae 16059@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 16060OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 16061@c This is false ...
c906108c
SS
16062Some @value{GDBN} features may be used in expressions regardless of the
16063language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16064and the @samp{@{type@}addr} construct (@pxref{Expressions,
16065,Expressions}) can be used with the constructs of any supported
16066language.
16067
16068The following sections detail to what degree each source language is
16069supported by @value{GDBN}. These sections are not meant to be language
16070tutorials or references, but serve only as a reference guide to what the
16071@value{GDBN} expression parser accepts, and what input and output
16072formats should look like for different languages. There are many good
16073books written on each of these languages; please look to these for a
16074language reference or tutorial.
16075
c906108c 16076@menu
b37303ee 16077* C:: C and C@t{++}
6aecb9c2 16078* D:: D
a766d390 16079* Go:: Go
b383017d 16080* Objective-C:: Objective-C
f4b8a18d 16081* OpenCL C:: OpenCL C
09d4efe1 16082* Fortran:: Fortran
9c16f35a 16083* Pascal:: Pascal
0bdfa368 16084* Rust:: Rust
b37303ee 16085* Modula-2:: Modula-2
e07c999f 16086* Ada:: Ada
c906108c
SS
16087@end menu
16088
6d2ebf8b 16089@node C
b37052ae 16090@subsection C and C@t{++}
7a292a7a 16091
b37052ae
EZ
16092@cindex C and C@t{++}
16093@cindex expressions in C or C@t{++}
c906108c 16094
b37052ae 16095Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
16096to both languages. Whenever this is the case, we discuss those languages
16097together.
16098
41afff9a
EZ
16099@cindex C@t{++}
16100@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
16101@cindex @sc{gnu} C@t{++}
16102The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16103compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16104effectively, you must compile your C@t{++} programs with a supported
16105C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
16106compiler (@code{aCC}).
16107
c906108c 16108@menu
b37052ae
EZ
16109* C Operators:: C and C@t{++} operators
16110* C Constants:: C and C@t{++} constants
79a6e687 16111* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
16112* C Defaults:: Default settings for C and C@t{++}
16113* C Checks:: C and C@t{++} type and range checks
c906108c 16114* Debugging C:: @value{GDBN} and C
79a6e687 16115* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 16116* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 16117@end menu
c906108c 16118
6d2ebf8b 16119@node C Operators
79a6e687 16120@subsubsection C and C@t{++} Operators
7a292a7a 16121
b37052ae 16122@cindex C and C@t{++} operators
c906108c
SS
16123
16124Operators must be defined on values of specific types. For instance,
16125@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16126often defined on groups of types.
c906108c 16127
b37052ae 16128For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16129
16130@itemize @bullet
53a5351d 16131
c906108c 16132@item
c906108c 16133@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16134specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16135
16136@item
d4f3574e
SS
16137@emph{Floating-point types} include @code{float}, @code{double}, and
16138@code{long double} (if supported by the target platform).
c906108c
SS
16139
16140@item
53a5351d 16141@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16142
16143@item
16144@emph{Scalar types} include all of the above.
53a5351d 16145
c906108c
SS
16146@end itemize
16147
16148@noindent
16149The following operators are supported. They are listed here
16150in order of increasing precedence:
16151
16152@table @code
16153@item ,
16154The comma or sequencing operator. Expressions in a comma-separated list
16155are evaluated from left to right, with the result of the entire
16156expression being the last expression evaluated.
16157
16158@item =
16159Assignment. The value of an assignment expression is the value
16160assigned. Defined on scalar types.
16161
16162@item @var{op}=
16163Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16164and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16165@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16166@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16167@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16168
16169@item ?:
16170The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16171of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16172should be of an integral type.
c906108c
SS
16173
16174@item ||
16175Logical @sc{or}. Defined on integral types.
16176
16177@item &&
16178Logical @sc{and}. Defined on integral types.
16179
16180@item |
16181Bitwise @sc{or}. Defined on integral types.
16182
16183@item ^
16184Bitwise exclusive-@sc{or}. Defined on integral types.
16185
16186@item &
16187Bitwise @sc{and}. Defined on integral types.
16188
16189@item ==@r{, }!=
16190Equality and inequality. Defined on scalar types. The value of these
16191expressions is 0 for false and non-zero for true.
16192
16193@item <@r{, }>@r{, }<=@r{, }>=
16194Less than, greater than, less than or equal, greater than or equal.
16195Defined on scalar types. The value of these expressions is 0 for false
16196and non-zero for true.
16197
16198@item <<@r{, }>>
16199left shift, and right shift. Defined on integral types.
16200
16201@item @@
16202The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16203
16204@item +@r{, }-
16205Addition and subtraction. Defined on integral types, floating-point types and
16206pointer types.
16207
16208@item *@r{, }/@r{, }%
16209Multiplication, division, and modulus. Multiplication and division are
16210defined on integral and floating-point types. Modulus is defined on
16211integral types.
16212
16213@item ++@r{, }--
16214Increment and decrement. When appearing before a variable, the
16215operation is performed before the variable is used in an expression;
16216when appearing after it, the variable's value is used before the
16217operation takes place.
16218
16219@item *
16220Pointer dereferencing. Defined on pointer types. Same precedence as
16221@code{++}.
16222
16223@item &
16224Address operator. Defined on variables. Same precedence as @code{++}.
16225
b37052ae
EZ
16226For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16227allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16228to examine the address
b37052ae 16229where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16230stored.
c906108c
SS
16231
16232@item -
16233Negative. Defined on integral and floating-point types. Same
16234precedence as @code{++}.
16235
16236@item !
16237Logical negation. Defined on integral types. Same precedence as
16238@code{++}.
16239
16240@item ~
16241Bitwise complement operator. Defined on integral types. Same precedence as
16242@code{++}.
16243
16244
16245@item .@r{, }->
16246Structure member, and pointer-to-structure member. For convenience,
16247@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16248pointer based on the stored type information.
16249Defined on @code{struct} and @code{union} data.
16250
c906108c
SS
16251@item .*@r{, }->*
16252Dereferences of pointers to members.
c906108c
SS
16253
16254@item []
16255Array indexing. @code{@var{a}[@var{i}]} is defined as
16256@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16257
16258@item ()
16259Function parameter list. Same precedence as @code{->}.
16260
c906108c 16261@item ::
b37052ae 16262C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16263and @code{class} types.
c906108c
SS
16264
16265@item ::
7a292a7a
SS
16266Doubled colons also represent the @value{GDBN} scope operator
16267(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16268above.
c906108c
SS
16269@end table
16270
c906108c
SS
16271If an operator is redefined in the user code, @value{GDBN} usually
16272attempts to invoke the redefined version instead of using the operator's
16273predefined meaning.
c906108c 16274
6d2ebf8b 16275@node C Constants
79a6e687 16276@subsubsection C and C@t{++} Constants
c906108c 16277
b37052ae 16278@cindex C and C@t{++} constants
c906108c 16279
b37052ae 16280@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16281following ways:
c906108c
SS
16282
16283@itemize @bullet
16284@item
16285Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16286specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16287by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16288@samp{l}, specifying that the constant should be treated as a
16289@code{long} value.
16290
16291@item
16292Floating point constants are a sequence of digits, followed by a decimal
16293point, followed by a sequence of digits, and optionally followed by an
16294exponent. An exponent is of the form:
16295@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16296sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16297A floating-point constant may also end with a letter @samp{f} or
16298@samp{F}, specifying that the constant should be treated as being of
16299the @code{float} (as opposed to the default @code{double}) type; or with
16300a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16301constant.
c906108c
SS
16302
16303@item
16304Enumerated constants consist of enumerated identifiers, or their
16305integral equivalents.
16306
16307@item
16308Character constants are a single character surrounded by single quotes
16309(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16310(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16311be represented by a letter or by @dfn{escape sequences}, which are of
16312the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16313of the character's ordinal value; or of the form @samp{\@var{x}}, where
16314@samp{@var{x}} is a predefined special character---for example,
16315@samp{\n} for newline.
16316
e0f8f636
TT
16317Wide character constants can be written by prefixing a character
16318constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16319form of @samp{x}. The target wide character set is used when
16320computing the value of this constant (@pxref{Character Sets}).
16321
c906108c 16322@item
96a2c332
SS
16323String constants are a sequence of character constants surrounded by
16324double quotes (@code{"}). Any valid character constant (as described
16325above) may appear. Double quotes within the string must be preceded by
16326a backslash, so for instance @samp{"a\"b'c"} is a string of five
16327characters.
c906108c 16328
e0f8f636
TT
16329Wide string constants can be written by prefixing a string constant
16330with @samp{L}, as in C. The target wide character set is used when
16331computing the value of this constant (@pxref{Character Sets}).
16332
c906108c
SS
16333@item
16334Pointer constants are an integral value. You can also write pointers
16335to constants using the C operator @samp{&}.
16336
16337@item
16338Array constants are comma-separated lists surrounded by braces @samp{@{}
16339and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16340integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16341and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16342@end itemize
16343
79a6e687
BW
16344@node C Plus Plus Expressions
16345@subsubsection C@t{++} Expressions
b37052ae
EZ
16346
16347@cindex expressions in C@t{++}
16348@value{GDBN} expression handling can interpret most C@t{++} expressions.
16349
0179ffac
DC
16350@cindex debugging C@t{++} programs
16351@cindex C@t{++} compilers
16352@cindex debug formats and C@t{++}
16353@cindex @value{NGCC} and C@t{++}
c906108c 16354@quotation
e0f8f636
TT
16355@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16356the proper compiler and the proper debug format. Currently,
16357@value{GDBN} works best when debugging C@t{++} code that is compiled
16358with the most recent version of @value{NGCC} possible. The DWARF
16359debugging format is preferred; @value{NGCC} defaults to this on most
16360popular platforms. Other compilers and/or debug formats are likely to
16361work badly or not at all when using @value{GDBN} to debug C@t{++}
16362code. @xref{Compilation}.
c906108c 16363@end quotation
c906108c
SS
16364
16365@enumerate
16366
16367@cindex member functions
16368@item
16369Member function calls are allowed; you can use expressions like
16370
474c8240 16371@smallexample
c906108c 16372count = aml->GetOriginal(x, y)
474c8240 16373@end smallexample
c906108c 16374
41afff9a 16375@vindex this@r{, inside C@t{++} member functions}
b37052ae 16376@cindex namespace in C@t{++}
c906108c
SS
16377@item
16378While a member function is active (in the selected stack frame), your
16379expressions have the same namespace available as the member function;
16380that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16381pointer @code{this} following the same rules as C@t{++}. @code{using}
16382declarations in the current scope are also respected by @value{GDBN}.
c906108c 16383
c906108c 16384@cindex call overloaded functions
d4f3574e 16385@cindex overloaded functions, calling
b37052ae 16386@cindex type conversions in C@t{++}
c906108c
SS
16387@item
16388You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16389call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16390perform overload resolution involving user-defined type conversions,
16391calls to constructors, or instantiations of templates that do not exist
16392in the program. It also cannot handle ellipsis argument lists or
16393default arguments.
16394
16395It does perform integral conversions and promotions, floating-point
16396promotions, arithmetic conversions, pointer conversions, conversions of
16397class objects to base classes, and standard conversions such as those of
16398functions or arrays to pointers; it requires an exact match on the
16399number of function arguments.
16400
16401Overload resolution is always performed, unless you have specified
79a6e687
BW
16402@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16403,@value{GDBN} Features for C@t{++}}.
c906108c 16404
d4f3574e 16405You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16406explicit function signature to call an overloaded function, as in
16407@smallexample
16408p 'foo(char,int)'('x', 13)
16409@end smallexample
d4f3574e 16410
c906108c 16411The @value{GDBN} command-completion facility can simplify this;
79a6e687 16412see @ref{Completion, ,Command Completion}.
c906108c 16413
c906108c
SS
16414@cindex reference declarations
16415@item
c0f55cc6
AV
16416@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16417references; you can use them in expressions just as you do in C@t{++}
16418source---they are automatically dereferenced.
c906108c
SS
16419
16420In the parameter list shown when @value{GDBN} displays a frame, the values of
16421reference variables are not displayed (unlike other variables); this
16422avoids clutter, since references are often used for large structures.
16423The @emph{address} of a reference variable is always shown, unless
16424you have specified @samp{set print address off}.
16425
16426@item
b37052ae 16427@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16428expressions can use it just as expressions in your program do. Since
16429one scope may be defined in another, you can use @code{::} repeatedly if
16430necessary, for example in an expression like
16431@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16432resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16433debugging (@pxref{Variables, ,Program Variables}).
c906108c 16434
e0f8f636
TT
16435@item
16436@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16437specification.
16438@end enumerate
c906108c 16439
6d2ebf8b 16440@node C Defaults
79a6e687 16441@subsubsection C and C@t{++} Defaults
7a292a7a 16442
b37052ae 16443@cindex C and C@t{++} defaults
c906108c 16444
a451cb65
KS
16445If you allow @value{GDBN} to set range checking automatically, it
16446defaults to @code{off} whenever the working language changes to
b37052ae 16447C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16448selects the working language.
c906108c
SS
16449
16450If you allow @value{GDBN} to set the language automatically, it
16451recognizes source files whose names end with @file{.c}, @file{.C}, or
16452@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16453these files, it sets the working language to C or C@t{++}.
79a6e687 16454@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16455for further details.
16456
6d2ebf8b 16457@node C Checks
79a6e687 16458@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16459
b37052ae 16460@cindex C and C@t{++} checks
c906108c 16461
a451cb65
KS
16462By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16463checking is used. However, if you turn type checking off, @value{GDBN}
16464will allow certain non-standard conversions, such as promoting integer
16465constants to pointers.
c906108c
SS
16466
16467Range checking, if turned on, is done on mathematical operations. Array
16468indices are not checked, since they are often used to index a pointer
16469that is not itself an array.
c906108c 16470
6d2ebf8b 16471@node Debugging C
c906108c 16472@subsubsection @value{GDBN} and C
c906108c
SS
16473
16474The @code{set print union} and @code{show print union} commands apply to
16475the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16476inside a @code{struct} or @code{class} is also printed. Otherwise, it
16477appears as @samp{@{...@}}.
c906108c
SS
16478
16479The @code{@@} operator aids in the debugging of dynamic arrays, formed
16480with pointers and a memory allocation function. @xref{Expressions,
16481,Expressions}.
16482
79a6e687
BW
16483@node Debugging C Plus Plus
16484@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16485
b37052ae 16486@cindex commands for C@t{++}
7a292a7a 16487
b37052ae
EZ
16488Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16489designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16490
16491@table @code
16492@cindex break in overloaded functions
16493@item @r{breakpoint menus}
16494When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16495@value{GDBN} has the capability to display a menu of possible breakpoint
16496locations to help you specify which function definition you want.
16497@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16498
b37052ae 16499@cindex overloading in C@t{++}
c906108c
SS
16500@item rbreak @var{regex}
16501Setting breakpoints using regular expressions is helpful for setting
16502breakpoints on overloaded functions that are not members of any special
16503classes.
79a6e687 16504@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16505
b37052ae 16506@cindex C@t{++} exception handling
c906108c 16507@item catch throw
591f19e8 16508@itemx catch rethrow
c906108c 16509@itemx catch catch
b37052ae 16510Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16511Catchpoints, , Setting Catchpoints}.
c906108c
SS
16512
16513@cindex inheritance
16514@item ptype @var{typename}
16515Print inheritance relationships as well as other information for type
16516@var{typename}.
16517@xref{Symbols, ,Examining the Symbol Table}.
16518
c4aeac85
TT
16519@item info vtbl @var{expression}.
16520The @code{info vtbl} command can be used to display the virtual
16521method tables of the object computed by @var{expression}. This shows
16522one entry per virtual table; there may be multiple virtual tables when
16523multiple inheritance is in use.
16524
439250fb
DE
16525@cindex C@t{++} demangling
16526@item demangle @var{name}
16527Demangle @var{name}.
16528@xref{Symbols}, for a more complete description of the @code{demangle} command.
16529
b37052ae 16530@cindex C@t{++} symbol display
c906108c
SS
16531@item set print demangle
16532@itemx show print demangle
16533@itemx set print asm-demangle
16534@itemx show print asm-demangle
b37052ae
EZ
16535Control whether C@t{++} symbols display in their source form, both when
16536displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16537@xref{Print Settings, ,Print Settings}.
c906108c
SS
16538
16539@item set print object
16540@itemx show print object
16541Choose whether to print derived (actual) or declared types of objects.
79a6e687 16542@xref{Print Settings, ,Print Settings}.
c906108c
SS
16543
16544@item set print vtbl
16545@itemx show print vtbl
16546Control the format for printing virtual function tables.
79a6e687 16547@xref{Print Settings, ,Print Settings}.
c906108c 16548(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16549ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16550
16551@kindex set overload-resolution
d4f3574e 16552@cindex overloaded functions, overload resolution
c906108c 16553@item set overload-resolution on
b37052ae 16554Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16555is on. For overloaded functions, @value{GDBN} evaluates the arguments
16556and searches for a function whose signature matches the argument types,
79a6e687
BW
16557using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16558Expressions, ,C@t{++} Expressions}, for details).
16559If it cannot find a match, it emits a message.
c906108c
SS
16560
16561@item set overload-resolution off
b37052ae 16562Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16563overloaded functions that are not class member functions, @value{GDBN}
16564chooses the first function of the specified name that it finds in the
16565symbol table, whether or not its arguments are of the correct type. For
16566overloaded functions that are class member functions, @value{GDBN}
16567searches for a function whose signature @emph{exactly} matches the
16568argument types.
c906108c 16569
9c16f35a
EZ
16570@kindex show overload-resolution
16571@item show overload-resolution
16572Show the current setting of overload resolution.
16573
c906108c
SS
16574@item @r{Overloaded symbol names}
16575You can specify a particular definition of an overloaded symbol, using
b37052ae 16576the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16577@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16578also use the @value{GDBN} command-line word completion facilities to list the
16579available choices, or to finish the type list for you.
79a6e687 16580@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16581
16582@item @r{Breakpoints in functions with ABI tags}
16583
16584The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16585correspond to changes in the ABI of a type, function, or variable that
16586would not otherwise be reflected in a mangled name. See
16587@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16588for more detail.
16589
16590The ABI tags are visible in C@t{++} demangled names. For example, a
16591function that returns a std::string:
16592
16593@smallexample
16594std::string function(int);
16595@end smallexample
16596
16597@noindent
16598when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16599tag, and @value{GDBN} displays the symbol like this:
16600
16601@smallexample
16602function[abi:cxx11](int)
16603@end smallexample
16604
16605You can set a breakpoint on such functions simply as if they had no
16606tag. For example:
16607
16608@smallexample
16609(gdb) b function(int)
16610Breakpoint 2 at 0x40060d: file main.cc, line 10.
16611(gdb) info breakpoints
16612Num Type Disp Enb Address What
166131 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16614 at main.cc:10
16615@end smallexample
16616
16617On the rare occasion you need to disambiguate between different ABI
16618tags, you can do so by simply including the ABI tag in the function
16619name, like:
16620
16621@smallexample
16622(@value{GDBP}) b ambiguous[abi:other_tag](int)
16623@end smallexample
c906108c 16624@end table
c906108c 16625
febe4383
TJB
16626@node Decimal Floating Point
16627@subsubsection Decimal Floating Point format
16628@cindex decimal floating point format
16629
16630@value{GDBN} can examine, set and perform computations with numbers in
16631decimal floating point format, which in the C language correspond to the
16632@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16633specified by the extension to support decimal floating-point arithmetic.
16634
16635There are two encodings in use, depending on the architecture: BID (Binary
16636Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16637PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16638configured target.
febe4383
TJB
16639
16640Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16641to manipulate decimal floating point numbers, it is not possible to convert
16642(using a cast, for example) integers wider than 32-bit to decimal float.
16643
16644In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16645point computations, error checking in decimal float operations ignores
16646underflow, overflow and divide by zero exceptions.
16647
4acd40f3 16648In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16649to inspect @code{_Decimal128} values stored in floating point registers.
16650See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16651
6aecb9c2
JB
16652@node D
16653@subsection D
16654
16655@cindex D
16656@value{GDBN} can be used to debug programs written in D and compiled with
16657GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16658specific feature --- dynamic arrays.
16659
a766d390
DE
16660@node Go
16661@subsection Go
16662
16663@cindex Go (programming language)
16664@value{GDBN} can be used to debug programs written in Go and compiled with
16665@file{gccgo} or @file{6g} compilers.
16666
16667Here is a summary of the Go-specific features and restrictions:
16668
16669@table @code
16670@cindex current Go package
16671@item The current Go package
16672The name of the current package does not need to be specified when
16673specifying global variables and functions.
16674
16675For example, given the program:
16676
16677@example
16678package main
16679var myglob = "Shall we?"
16680func main () @{
16681 // ...
16682@}
16683@end example
16684
16685When stopped inside @code{main} either of these work:
16686
16687@example
16688(gdb) p myglob
16689(gdb) p main.myglob
16690@end example
16691
16692@cindex builtin Go types
16693@item Builtin Go types
16694The @code{string} type is recognized by @value{GDBN} and is printed
16695as a string.
16696
16697@cindex builtin Go functions
16698@item Builtin Go functions
16699The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16700function and handles it internally.
a766d390
DE
16701
16702@cindex restrictions on Go expressions
16703@item Restrictions on Go expressions
16704All Go operators are supported except @code{&^}.
16705The Go @code{_} ``blank identifier'' is not supported.
16706Automatic dereferencing of pointers is not supported.
50f042b9 16707@end table
a766d390 16708
b37303ee
AF
16709@node Objective-C
16710@subsection Objective-C
16711
16712@cindex Objective-C
16713This section provides information about some commands and command
721c2651
EZ
16714options that are useful for debugging Objective-C code. See also
16715@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16716few more commands specific to Objective-C support.
b37303ee
AF
16717
16718@menu
b383017d
RM
16719* Method Names in Commands::
16720* The Print Command with Objective-C::
b37303ee
AF
16721@end menu
16722
c8f4133a 16723@node Method Names in Commands
b37303ee
AF
16724@subsubsection Method Names in Commands
16725
16726The following commands have been extended to accept Objective-C method
16727names as line specifications:
16728
16729@kindex clear@r{, and Objective-C}
16730@kindex break@r{, and Objective-C}
16731@kindex info line@r{, and Objective-C}
16732@kindex jump@r{, and Objective-C}
16733@kindex list@r{, and Objective-C}
16734@itemize
16735@item @code{clear}
16736@item @code{break}
16737@item @code{info line}
16738@item @code{jump}
16739@item @code{list}
16740@end itemize
16741
16742A fully qualified Objective-C method name is specified as
16743
16744@smallexample
16745-[@var{Class} @var{methodName}]
16746@end smallexample
16747
c552b3bb
JM
16748where the minus sign is used to indicate an instance method and a
16749plus sign (not shown) is used to indicate a class method. The class
16750name @var{Class} and method name @var{methodName} are enclosed in
16751brackets, similar to the way messages are specified in Objective-C
16752source code. For example, to set a breakpoint at the @code{create}
16753instance method of class @code{Fruit} in the program currently being
16754debugged, enter:
b37303ee
AF
16755
16756@smallexample
16757break -[Fruit create]
16758@end smallexample
16759
16760To list ten program lines around the @code{initialize} class method,
16761enter:
16762
16763@smallexample
16764list +[NSText initialize]
16765@end smallexample
16766
c552b3bb
JM
16767In the current version of @value{GDBN}, the plus or minus sign is
16768required. In future versions of @value{GDBN}, the plus or minus
16769sign will be optional, but you can use it to narrow the search. It
16770is also possible to specify just a method name:
b37303ee
AF
16771
16772@smallexample
16773break create
16774@end smallexample
16775
16776You must specify the complete method name, including any colons. If
16777your program's source files contain more than one @code{create} method,
16778you'll be presented with a numbered list of classes that implement that
16779method. Indicate your choice by number, or type @samp{0} to exit if
16780none apply.
16781
16782As another example, to clear a breakpoint established at the
16783@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16784
16785@smallexample
16786clear -[NSWindow makeKeyAndOrderFront:]
16787@end smallexample
16788
16789@node The Print Command with Objective-C
16790@subsubsection The Print Command With Objective-C
721c2651 16791@cindex Objective-C, print objects
c552b3bb
JM
16792@kindex print-object
16793@kindex po @r{(@code{print-object})}
b37303ee 16794
c552b3bb 16795The print command has also been extended to accept methods. For example:
b37303ee
AF
16796
16797@smallexample
c552b3bb 16798print -[@var{object} hash]
b37303ee
AF
16799@end smallexample
16800
16801@cindex print an Objective-C object description
c552b3bb
JM
16802@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16803@noindent
16804will tell @value{GDBN} to send the @code{hash} message to @var{object}
16805and print the result. Also, an additional command has been added,
16806@code{print-object} or @code{po} for short, which is meant to print
16807the description of an object. However, this command may only work
16808with certain Objective-C libraries that have a particular hook
16809function, @code{_NSPrintForDebugger}, defined.
b37303ee 16810
f4b8a18d
KW
16811@node OpenCL C
16812@subsection OpenCL C
16813
16814@cindex OpenCL C
16815This section provides information about @value{GDBN}s OpenCL C support.
16816
16817@menu
16818* OpenCL C Datatypes::
16819* OpenCL C Expressions::
16820* OpenCL C Operators::
16821@end menu
16822
16823@node OpenCL C Datatypes
16824@subsubsection OpenCL C Datatypes
16825
16826@cindex OpenCL C Datatypes
16827@value{GDBN} supports the builtin scalar and vector datatypes specified
16828by OpenCL 1.1. In addition the half- and double-precision floating point
16829data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16830extensions are also known to @value{GDBN}.
16831
16832@node OpenCL C Expressions
16833@subsubsection OpenCL C Expressions
16834
16835@cindex OpenCL C Expressions
16836@value{GDBN} supports accesses to vector components including the access as
16837lvalue where possible. Since OpenCL C is based on C99 most C expressions
16838supported by @value{GDBN} can be used as well.
16839
16840@node OpenCL C Operators
16841@subsubsection OpenCL C Operators
16842
16843@cindex OpenCL C Operators
16844@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16845vector data types.
16846
09d4efe1
EZ
16847@node Fortran
16848@subsection Fortran
16849@cindex Fortran-specific support in @value{GDBN}
16850
814e32d7
WZ
16851@value{GDBN} can be used to debug programs written in Fortran, but it
16852currently supports only the features of Fortran 77 language.
16853
16854@cindex trailing underscore, in Fortran symbols
16855Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16856among them) append an underscore to the names of variables and
16857functions. When you debug programs compiled by those compilers, you
16858will need to refer to variables and functions with a trailing
16859underscore.
16860
16861@menu
16862* Fortran Operators:: Fortran operators and expressions
16863* Fortran Defaults:: Default settings for Fortran
79a6e687 16864* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16865@end menu
16866
16867@node Fortran Operators
79a6e687 16868@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16869
16870@cindex Fortran operators and expressions
16871
16872Operators must be defined on values of specific types. For instance,
16873@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16874arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16875
16876@table @code
16877@item **
99e008fe 16878The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16879of the second one.
16880
16881@item :
16882The range operator. Normally used in the form of array(low:high) to
16883represent a section of array.
68837c9d
MD
16884
16885@item %
16886The access component operator. Normally used to access elements in derived
16887types. Also suitable for unions. As unions aren't part of regular Fortran,
16888this can only happen when accessing a register that uses a gdbarch-defined
16889union type.
0a4b0913
AB
16890@item ::
16891The scope operator. Normally used to access variables in modules or
16892to set breakpoints on subroutines nested in modules or in other
16893subroutines (internal subroutines).
814e32d7
WZ
16894@end table
16895
16896@node Fortran Defaults
16897@subsubsection Fortran Defaults
16898
16899@cindex Fortran Defaults
16900
16901Fortran symbols are usually case-insensitive, so @value{GDBN} by
16902default uses case-insensitive matches for Fortran symbols. You can
16903change that with the @samp{set case-insensitive} command, see
16904@ref{Symbols}, for the details.
16905
79a6e687
BW
16906@node Special Fortran Commands
16907@subsubsection Special Fortran Commands
814e32d7
WZ
16908
16909@cindex Special Fortran commands
16910
db2e3e2e
BW
16911@value{GDBN} has some commands to support Fortran-specific features,
16912such as displaying common blocks.
814e32d7 16913
09d4efe1
EZ
16914@table @code
16915@cindex @code{COMMON} blocks, Fortran
16916@kindex info common
16917@item info common @r{[}@var{common-name}@r{]}
16918This command prints the values contained in the Fortran @code{COMMON}
16919block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16920all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
16921printed.
16922@end table
16923
9c16f35a
EZ
16924@node Pascal
16925@subsection Pascal
16926
16927@cindex Pascal support in @value{GDBN}, limitations
16928Debugging Pascal programs which use sets, subranges, file variables, or
16929nested functions does not currently work. @value{GDBN} does not support
16930entering expressions, printing values, or similar features using Pascal
16931syntax.
16932
16933The Pascal-specific command @code{set print pascal_static-members}
16934controls whether static members of Pascal objects are displayed.
16935@xref{Print Settings, pascal_static-members}.
16936
0bdfa368
TT
16937@node Rust
16938@subsection Rust
16939
16940@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16941Programming Language}. Type- and value-printing, and expression
16942parsing, are reasonably complete. However, there are a few
16943peculiarities and holes to be aware of.
16944
16945@itemize @bullet
16946@item
16947Linespecs (@pxref{Specify Location}) are never relative to the current
16948crate. Instead, they act as if there were a global namespace of
16949crates, somewhat similar to the way @code{extern crate} behaves.
16950
16951That is, if @value{GDBN} is stopped at a breakpoint in a function in
16952crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16953to set a breakpoint in a function named @samp{f} in a crate named
16954@samp{B}.
16955
16956As a consequence of this approach, linespecs also cannot refer to
16957items using @samp{self::} or @samp{super::}.
16958
16959@item
16960Because @value{GDBN} implements Rust name-lookup semantics in
16961expressions, it will sometimes prepend the current crate to a name.
16962For example, if @value{GDBN} is stopped at a breakpoint in the crate
16963@samp{K}, then @code{print ::x::y} will try to find the symbol
16964@samp{K::x::y}.
16965
16966However, since it is useful to be able to refer to other crates when
16967debugging, @value{GDBN} provides the @code{extern} extension to
16968circumvent this. To use the extension, just put @code{extern} before
16969a path expression to refer to the otherwise unavailable ``global''
16970scope.
16971
16972In the above example, if you wanted to refer to the symbol @samp{y} in
16973the crate @samp{x}, you would use @code{print extern x::y}.
16974
16975@item
16976The Rust expression evaluator does not support ``statement-like''
16977expressions such as @code{if} or @code{match}, or lambda expressions.
16978
16979@item
16980Tuple expressions are not implemented.
16981
16982@item
16983The Rust expression evaluator does not currently implement the
16984@code{Drop} trait. Objects that may be created by the evaluator will
16985never be destroyed.
16986
16987@item
16988@value{GDBN} does not implement type inference for generics. In order
16989to call generic functions or otherwise refer to generic items, you
16990will have to specify the type parameters manually.
16991
16992@item
16993@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16994cases this does not cause any problems. However, in an expression
16995context, completing a generic function name will give syntactically
16996invalid results. This happens because Rust requires the @samp{::}
16997operator between the function name and its generic arguments. For
16998example, @value{GDBN} might provide a completion like
16999@code{crate::f<u32>}, where the parser would require
17000@code{crate::f::<u32>}.
17001
17002@item
17003As of this writing, the Rust compiler (version 1.8) has a few holes in
17004the debugging information it generates. These holes prevent certain
17005features from being implemented by @value{GDBN}:
17006@itemize @bullet
17007
17008@item
17009Method calls cannot be made via traits.
17010
0bdfa368
TT
17011@item
17012Operator overloading is not implemented.
17013
17014@item
17015When debugging in a monomorphized function, you cannot use the generic
17016type names.
17017
17018@item
17019The type @code{Self} is not available.
17020
17021@item
17022@code{use} statements are not available, so some names may not be
17023available in the crate.
17024@end itemize
17025@end itemize
17026
09d4efe1 17027@node Modula-2
c906108c 17028@subsection Modula-2
7a292a7a 17029
d4f3574e 17030@cindex Modula-2, @value{GDBN} support
c906108c
SS
17031
17032The extensions made to @value{GDBN} to support Modula-2 only support
17033output from the @sc{gnu} Modula-2 compiler (which is currently being
17034developed). Other Modula-2 compilers are not currently supported, and
17035attempting to debug executables produced by them is most likely
17036to give an error as @value{GDBN} reads in the executable's symbol
17037table.
17038
17039@cindex expressions in Modula-2
17040@menu
17041* M2 Operators:: Built-in operators
17042* Built-In Func/Proc:: Built-in functions and procedures
17043* M2 Constants:: Modula-2 constants
72019c9c 17044* M2 Types:: Modula-2 types
c906108c
SS
17045* M2 Defaults:: Default settings for Modula-2
17046* Deviations:: Deviations from standard Modula-2
17047* M2 Checks:: Modula-2 type and range checks
17048* M2 Scope:: The scope operators @code{::} and @code{.}
17049* GDB/M2:: @value{GDBN} and Modula-2
17050@end menu
17051
6d2ebf8b 17052@node M2 Operators
c906108c
SS
17053@subsubsection Operators
17054@cindex Modula-2 operators
17055
17056Operators must be defined on values of specific types. For instance,
17057@code{+} is defined on numbers, but not on structures. Operators are
17058often defined on groups of types. For the purposes of Modula-2, the
17059following definitions hold:
17060
17061@itemize @bullet
17062
17063@item
17064@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17065their subranges.
17066
17067@item
17068@emph{Character types} consist of @code{CHAR} and its subranges.
17069
17070@item
17071@emph{Floating-point types} consist of @code{REAL}.
17072
17073@item
17074@emph{Pointer types} consist of anything declared as @code{POINTER TO
17075@var{type}}.
17076
17077@item
17078@emph{Scalar types} consist of all of the above.
17079
17080@item
17081@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17082
17083@item
17084@emph{Boolean types} consist of @code{BOOLEAN}.
17085@end itemize
17086
17087@noindent
17088The following operators are supported, and appear in order of
17089increasing precedence:
17090
17091@table @code
17092@item ,
17093Function argument or array index separator.
17094
17095@item :=
17096Assignment. The value of @var{var} @code{:=} @var{value} is
17097@var{value}.
17098
17099@item <@r{, }>
17100Less than, greater than on integral, floating-point, or enumerated
17101types.
17102
17103@item <=@r{, }>=
96a2c332 17104Less than or equal to, greater than or equal to
c906108c
SS
17105on integral, floating-point and enumerated types, or set inclusion on
17106set types. Same precedence as @code{<}.
17107
17108@item =@r{, }<>@r{, }#
17109Equality and two ways of expressing inequality, valid on scalar types.
17110Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17111available for inequality, since @code{#} conflicts with the script
17112comment character.
17113
17114@item IN
17115Set membership. Defined on set types and the types of their members.
17116Same precedence as @code{<}.
17117
17118@item OR
17119Boolean disjunction. Defined on boolean types.
17120
17121@item AND@r{, }&
d4f3574e 17122Boolean conjunction. Defined on boolean types.
c906108c
SS
17123
17124@item @@
17125The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17126
17127@item +@r{, }-
17128Addition and subtraction on integral and floating-point types, or union
17129and difference on set types.
17130
17131@item *
17132Multiplication on integral and floating-point types, or set intersection
17133on set types.
17134
17135@item /
17136Division on floating-point types, or symmetric set difference on set
17137types. Same precedence as @code{*}.
17138
17139@item DIV@r{, }MOD
17140Integer division and remainder. Defined on integral types. Same
17141precedence as @code{*}.
17142
17143@item -
99e008fe 17144Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17145
17146@item ^
17147Pointer dereferencing. Defined on pointer types.
17148
17149@item NOT
17150Boolean negation. Defined on boolean types. Same precedence as
17151@code{^}.
17152
17153@item .
17154@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17155precedence as @code{^}.
17156
17157@item []
17158Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17159
17160@item ()
17161Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17162as @code{^}.
17163
17164@item ::@r{, }.
17165@value{GDBN} and Modula-2 scope operators.
17166@end table
17167
17168@quotation
72019c9c 17169@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17170treats the use of the operator @code{IN}, or the use of operators
17171@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17172@code{<=}, and @code{>=} on sets as an error.
17173@end quotation
17174
cb51c4e0 17175
6d2ebf8b 17176@node Built-In Func/Proc
79a6e687 17177@subsubsection Built-in Functions and Procedures
cb51c4e0 17178@cindex Modula-2 built-ins
c906108c
SS
17179
17180Modula-2 also makes available several built-in procedures and functions.
17181In describing these, the following metavariables are used:
17182
17183@table @var
17184
17185@item a
17186represents an @code{ARRAY} variable.
17187
17188@item c
17189represents a @code{CHAR} constant or variable.
17190
17191@item i
17192represents a variable or constant of integral type.
17193
17194@item m
17195represents an identifier that belongs to a set. Generally used in the
17196same function with the metavariable @var{s}. The type of @var{s} should
17197be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17198
17199@item n
17200represents a variable or constant of integral or floating-point type.
17201
17202@item r
17203represents a variable or constant of floating-point type.
17204
17205@item t
17206represents a type.
17207
17208@item v
17209represents a variable.
17210
17211@item x
17212represents a variable or constant of one of many types. See the
17213explanation of the function for details.
17214@end table
17215
17216All Modula-2 built-in procedures also return a result, described below.
17217
17218@table @code
17219@item ABS(@var{n})
17220Returns the absolute value of @var{n}.
17221
17222@item CAP(@var{c})
17223If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17224equivalent, otherwise it returns its argument.
c906108c
SS
17225
17226@item CHR(@var{i})
17227Returns the character whose ordinal value is @var{i}.
17228
17229@item DEC(@var{v})
c3f6f71d 17230Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17231
17232@item DEC(@var{v},@var{i})
17233Decrements the value in the variable @var{v} by @var{i}. Returns the
17234new value.
17235
17236@item EXCL(@var{m},@var{s})
17237Removes the element @var{m} from the set @var{s}. Returns the new
17238set.
17239
17240@item FLOAT(@var{i})
17241Returns the floating point equivalent of the integer @var{i}.
17242
17243@item HIGH(@var{a})
17244Returns the index of the last member of @var{a}.
17245
17246@item INC(@var{v})
c3f6f71d 17247Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17248
17249@item INC(@var{v},@var{i})
17250Increments the value in the variable @var{v} by @var{i}. Returns the
17251new value.
17252
17253@item INCL(@var{m},@var{s})
17254Adds the element @var{m} to the set @var{s} if it is not already
17255there. Returns the new set.
17256
17257@item MAX(@var{t})
17258Returns the maximum value of the type @var{t}.
17259
17260@item MIN(@var{t})
17261Returns the minimum value of the type @var{t}.
17262
17263@item ODD(@var{i})
17264Returns boolean TRUE if @var{i} is an odd number.
17265
17266@item ORD(@var{x})
17267Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17268value of a character is its @sc{ascii} value (on machines supporting
17269the @sc{ascii} character set). The argument @var{x} must be of an
17270ordered type, which include integral, character and enumerated types.
c906108c
SS
17271
17272@item SIZE(@var{x})
697aa1b7
EZ
17273Returns the size of its argument. The argument @var{x} can be a
17274variable or a type.
c906108c
SS
17275
17276@item TRUNC(@var{r})
17277Returns the integral part of @var{r}.
17278
844781a1 17279@item TSIZE(@var{x})
697aa1b7
EZ
17280Returns the size of its argument. The argument @var{x} can be a
17281variable or a type.
844781a1 17282
c906108c
SS
17283@item VAL(@var{t},@var{i})
17284Returns the member of the type @var{t} whose ordinal value is @var{i}.
17285@end table
17286
17287@quotation
17288@emph{Warning:} Sets and their operations are not yet supported, so
17289@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17290an error.
17291@end quotation
17292
17293@cindex Modula-2 constants
6d2ebf8b 17294@node M2 Constants
c906108c
SS
17295@subsubsection Constants
17296
17297@value{GDBN} allows you to express the constants of Modula-2 in the following
17298ways:
17299
17300@itemize @bullet
17301
17302@item
17303Integer constants are simply a sequence of digits. When used in an
17304expression, a constant is interpreted to be type-compatible with the
17305rest of the expression. Hexadecimal integers are specified by a
17306trailing @samp{H}, and octal integers by a trailing @samp{B}.
17307
17308@item
17309Floating point constants appear as a sequence of digits, followed by a
17310decimal point and another sequence of digits. An optional exponent can
17311then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17312@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17313digits of the floating point constant must be valid decimal (base 10)
17314digits.
17315
17316@item
17317Character constants consist of a single character enclosed by a pair of
17318like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17319also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17320followed by a @samp{C}.
17321
17322@item
17323String constants consist of a sequence of characters enclosed by a
17324pair of like quotes, either single (@code{'}) or double (@code{"}).
17325Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17326Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17327sequences.
17328
17329@item
17330Enumerated constants consist of an enumerated identifier.
17331
17332@item
17333Boolean constants consist of the identifiers @code{TRUE} and
17334@code{FALSE}.
17335
17336@item
17337Pointer constants consist of integral values only.
17338
17339@item
17340Set constants are not yet supported.
17341@end itemize
17342
72019c9c
GM
17343@node M2 Types
17344@subsubsection Modula-2 Types
17345@cindex Modula-2 types
17346
17347Currently @value{GDBN} can print the following data types in Modula-2
17348syntax: array types, record types, set types, pointer types, procedure
17349types, enumerated types, subrange types and base types. You can also
17350print the contents of variables declared using these type.
17351This section gives a number of simple source code examples together with
17352sample @value{GDBN} sessions.
17353
17354The first example contains the following section of code:
17355
17356@smallexample
17357VAR
17358 s: SET OF CHAR ;
17359 r: [20..40] ;
17360@end smallexample
17361
17362@noindent
17363and you can request @value{GDBN} to interrogate the type and value of
17364@code{r} and @code{s}.
17365
17366@smallexample
17367(@value{GDBP}) print s
17368@{'A'..'C', 'Z'@}
17369(@value{GDBP}) ptype s
17370SET OF CHAR
17371(@value{GDBP}) print r
1737221
17373(@value{GDBP}) ptype r
17374[20..40]
17375@end smallexample
17376
17377@noindent
17378Likewise if your source code declares @code{s} as:
17379
17380@smallexample
17381VAR
17382 s: SET ['A'..'Z'] ;
17383@end smallexample
17384
17385@noindent
17386then you may query the type of @code{s} by:
17387
17388@smallexample
17389(@value{GDBP}) ptype s
17390type = SET ['A'..'Z']
17391@end smallexample
17392
17393@noindent
17394Note that at present you cannot interactively manipulate set
17395expressions using the debugger.
17396
17397The following example shows how you might declare an array in Modula-2
17398and how you can interact with @value{GDBN} to print its type and contents:
17399
17400@smallexample
17401VAR
17402 s: ARRAY [-10..10] OF CHAR ;
17403@end smallexample
17404
17405@smallexample
17406(@value{GDBP}) ptype s
17407ARRAY [-10..10] OF CHAR
17408@end smallexample
17409
17410Note that the array handling is not yet complete and although the type
17411is printed correctly, expression handling still assumes that all
17412arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17413above.
72019c9c
GM
17414
17415Here are some more type related Modula-2 examples:
17416
17417@smallexample
17418TYPE
17419 colour = (blue, red, yellow, green) ;
17420 t = [blue..yellow] ;
17421VAR
17422 s: t ;
17423BEGIN
17424 s := blue ;
17425@end smallexample
17426
17427@noindent
17428The @value{GDBN} interaction shows how you can query the data type
17429and value of a variable.
17430
17431@smallexample
17432(@value{GDBP}) print s
17433$1 = blue
17434(@value{GDBP}) ptype t
17435type = [blue..yellow]
17436@end smallexample
17437
17438@noindent
17439In this example a Modula-2 array is declared and its contents
17440displayed. Observe that the contents are written in the same way as
17441their @code{C} counterparts.
17442
17443@smallexample
17444VAR
17445 s: ARRAY [1..5] OF CARDINAL ;
17446BEGIN
17447 s[1] := 1 ;
17448@end smallexample
17449
17450@smallexample
17451(@value{GDBP}) print s
17452$1 = @{1, 0, 0, 0, 0@}
17453(@value{GDBP}) ptype s
17454type = ARRAY [1..5] OF CARDINAL
17455@end smallexample
17456
17457The Modula-2 language interface to @value{GDBN} also understands
17458pointer types as shown in this example:
17459
17460@smallexample
17461VAR
17462 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17463BEGIN
17464 NEW(s) ;
17465 s^[1] := 1 ;
17466@end smallexample
17467
17468@noindent
17469and you can request that @value{GDBN} describes the type of @code{s}.
17470
17471@smallexample
17472(@value{GDBP}) ptype s
17473type = POINTER TO ARRAY [1..5] OF CARDINAL
17474@end smallexample
17475
17476@value{GDBN} handles compound types as we can see in this example.
17477Here we combine array types, record types, pointer types and subrange
17478types:
17479
17480@smallexample
17481TYPE
17482 foo = RECORD
17483 f1: CARDINAL ;
17484 f2: CHAR ;
17485 f3: myarray ;
17486 END ;
17487
17488 myarray = ARRAY myrange OF CARDINAL ;
17489 myrange = [-2..2] ;
17490VAR
17491 s: POINTER TO ARRAY myrange OF foo ;
17492@end smallexample
17493
17494@noindent
17495and you can ask @value{GDBN} to describe the type of @code{s} as shown
17496below.
17497
17498@smallexample
17499(@value{GDBP}) ptype s
17500type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17501 f1 : CARDINAL;
17502 f2 : CHAR;
17503 f3 : ARRAY [-2..2] OF CARDINAL;
17504END
17505@end smallexample
17506
6d2ebf8b 17507@node M2 Defaults
79a6e687 17508@subsubsection Modula-2 Defaults
c906108c
SS
17509@cindex Modula-2 defaults
17510
17511If type and range checking are set automatically by @value{GDBN}, they
17512both default to @code{on} whenever the working language changes to
d4f3574e 17513Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17514selected the working language.
17515
17516If you allow @value{GDBN} to set the language automatically, then entering
17517code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17518working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17519Infer the Source Language}, for further details.
c906108c 17520
6d2ebf8b 17521@node Deviations
79a6e687 17522@subsubsection Deviations from Standard Modula-2
c906108c
SS
17523@cindex Modula-2, deviations from
17524
17525A few changes have been made to make Modula-2 programs easier to debug.
17526This is done primarily via loosening its type strictness:
17527
17528@itemize @bullet
17529@item
17530Unlike in standard Modula-2, pointer constants can be formed by
17531integers. This allows you to modify pointer variables during
17532debugging. (In standard Modula-2, the actual address contained in a
17533pointer variable is hidden from you; it can only be modified
17534through direct assignment to another pointer variable or expression that
17535returned a pointer.)
17536
17537@item
17538C escape sequences can be used in strings and characters to represent
17539non-printable characters. @value{GDBN} prints out strings with these
17540escape sequences embedded. Single non-printable characters are
17541printed using the @samp{CHR(@var{nnn})} format.
17542
17543@item
17544The assignment operator (@code{:=}) returns the value of its right-hand
17545argument.
17546
17547@item
17548All built-in procedures both modify @emph{and} return their argument.
17549@end itemize
17550
6d2ebf8b 17551@node M2 Checks
79a6e687 17552@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17553@cindex Modula-2 checks
17554
17555@quotation
17556@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17557range checking.
17558@end quotation
17559@c FIXME remove warning when type/range checks added
17560
17561@value{GDBN} considers two Modula-2 variables type equivalent if:
17562
17563@itemize @bullet
17564@item
17565They are of types that have been declared equivalent via a @code{TYPE
17566@var{t1} = @var{t2}} statement
17567
17568@item
17569They have been declared on the same line. (Note: This is true of the
17570@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17571@end itemize
17572
17573As long as type checking is enabled, any attempt to combine variables
17574whose types are not equivalent is an error.
17575
17576Range checking is done on all mathematical operations, assignment, array
17577index bounds, and all built-in functions and procedures.
17578
6d2ebf8b 17579@node M2 Scope
79a6e687 17580@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17581@cindex scope
41afff9a 17582@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17583@cindex colon, doubled as scope operator
17584@ifinfo
41afff9a 17585@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17586@c Info cannot handle :: but TeX can.
17587@end ifinfo
a67ec3f4 17588@ifnotinfo
41afff9a 17589@vindex ::@r{, in Modula-2}
a67ec3f4 17590@end ifnotinfo
c906108c
SS
17591
17592There are a few subtle differences between the Modula-2 scope operator
17593(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17594similar syntax:
17595
474c8240 17596@smallexample
c906108c
SS
17597
17598@var{module} . @var{id}
17599@var{scope} :: @var{id}
474c8240 17600@end smallexample
c906108c
SS
17601
17602@noindent
17603where @var{scope} is the name of a module or a procedure,
17604@var{module} the name of a module, and @var{id} is any declared
17605identifier within your program, except another module.
17606
17607Using the @code{::} operator makes @value{GDBN} search the scope
17608specified by @var{scope} for the identifier @var{id}. If it is not
17609found in the specified scope, then @value{GDBN} searches all scopes
17610enclosing the one specified by @var{scope}.
17611
17612Using the @code{.} operator makes @value{GDBN} search the current scope for
17613the identifier specified by @var{id} that was imported from the
17614definition module specified by @var{module}. With this operator, it is
17615an error if the identifier @var{id} was not imported from definition
17616module @var{module}, or if @var{id} is not an identifier in
17617@var{module}.
17618
6d2ebf8b 17619@node GDB/M2
c906108c
SS
17620@subsubsection @value{GDBN} and Modula-2
17621
17622Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17623Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17624specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17625@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17626apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17627analogue in Modula-2.
17628
17629The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17630with any language, is not useful with Modula-2. Its
c906108c 17631intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17632created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17633address can be specified by an integral constant, the construct
d4f3574e 17634@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17635
17636@cindex @code{#} in Modula-2
17637In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17638interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17639
e07c999f
PH
17640@node Ada
17641@subsection Ada
17642@cindex Ada
17643
17644The extensions made to @value{GDBN} for Ada only support
17645output from the @sc{gnu} Ada (GNAT) compiler.
17646Other Ada compilers are not currently supported, and
17647attempting to debug executables produced by them is most likely
17648to be difficult.
17649
17650
17651@cindex expressions in Ada
17652@menu
17653* Ada Mode Intro:: General remarks on the Ada syntax
17654 and semantics supported by Ada mode
17655 in @value{GDBN}.
17656* Omissions from Ada:: Restrictions on the Ada expression syntax.
17657* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17658* Overloading support for Ada:: Support for expressions involving overloaded
17659 subprograms.
e07c999f 17660* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17661* Ada Exceptions:: Ada Exceptions
20924a55
JB
17662* Ada Tasks:: Listing and setting breakpoints in tasks.
17663* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17664* Ravenscar Profile:: Tasking Support when using the Ravenscar
17665 Profile
3fcded8f 17666* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17667* Ada Glitches:: Known peculiarities of Ada mode.
17668@end menu
17669
17670@node Ada Mode Intro
17671@subsubsection Introduction
17672@cindex Ada mode, general
17673
17674The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17675syntax, with some extensions.
17676The philosophy behind the design of this subset is
17677
17678@itemize @bullet
17679@item
17680That @value{GDBN} should provide basic literals and access to operations for
17681arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17682leaving more sophisticated computations to subprograms written into the
17683program (which therefore may be called from @value{GDBN}).
17684
17685@item
17686That type safety and strict adherence to Ada language restrictions
17687are not particularly important to the @value{GDBN} user.
17688
17689@item
17690That brevity is important to the @value{GDBN} user.
17691@end itemize
17692
f3a2dd1a
JB
17693Thus, for brevity, the debugger acts as if all names declared in
17694user-written packages are directly visible, even if they are not visible
17695according to Ada rules, thus making it unnecessary to fully qualify most
17696names with their packages, regardless of context. Where this causes
17697ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17698
17699The debugger will start in Ada mode if it detects an Ada main program.
17700As for other languages, it will enter Ada mode when stopped in a program that
17701was translated from an Ada source file.
17702
17703While in Ada mode, you may use `@t{--}' for comments. This is useful
17704mostly for documenting command files. The standard @value{GDBN} comment
17705(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17706middle (to allow based literals).
17707
e07c999f
PH
17708@node Omissions from Ada
17709@subsubsection Omissions from Ada
17710@cindex Ada, omissions from
17711
17712Here are the notable omissions from the subset:
17713
17714@itemize @bullet
17715@item
17716Only a subset of the attributes are supported:
17717
17718@itemize @minus
17719@item
17720@t{'First}, @t{'Last}, and @t{'Length}
17721 on array objects (not on types and subtypes).
17722
17723@item
17724@t{'Min} and @t{'Max}.
17725
17726@item
17727@t{'Pos} and @t{'Val}.
17728
17729@item
17730@t{'Tag}.
17731
17732@item
17733@t{'Range} on array objects (not subtypes), but only as the right
17734operand of the membership (@code{in}) operator.
17735
17736@item
17737@t{'Access}, @t{'Unchecked_Access}, and
17738@t{'Unrestricted_Access} (a GNAT extension).
17739
17740@item
17741@t{'Address}.
17742@end itemize
17743
17744@item
17745The names in
17746@code{Characters.Latin_1} are not available and
17747concatenation is not implemented. Thus, escape characters in strings are
17748not currently available.
17749
17750@item
17751Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17752equality of representations. They will generally work correctly
17753for strings and arrays whose elements have integer or enumeration types.
17754They may not work correctly for arrays whose element
17755types have user-defined equality, for arrays of real values
17756(in particular, IEEE-conformant floating point, because of negative
17757zeroes and NaNs), and for arrays whose elements contain unused bits with
17758indeterminate values.
17759
17760@item
17761The other component-by-component array operations (@code{and}, @code{or},
17762@code{xor}, @code{not}, and relational tests other than equality)
17763are not implemented.
17764
17765@item
860701dc
PH
17766@cindex array aggregates (Ada)
17767@cindex record aggregates (Ada)
17768@cindex aggregates (Ada)
17769There is limited support for array and record aggregates. They are
17770permitted only on the right sides of assignments, as in these examples:
17771
17772@smallexample
077e0a52
JB
17773(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17774(@value{GDBP}) set An_Array := (1, others => 0)
17775(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17776(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17777(@value{GDBP}) set A_Record := (1, "Peter", True);
17778(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17779@end smallexample
17780
17781Changing a
17782discriminant's value by assigning an aggregate has an
17783undefined effect if that discriminant is used within the record.
17784However, you can first modify discriminants by directly assigning to
17785them (which normally would not be allowed in Ada), and then performing an
17786aggregate assignment. For example, given a variable @code{A_Rec}
17787declared to have a type such as:
17788
17789@smallexample
17790type Rec (Len : Small_Integer := 0) is record
17791 Id : Integer;
17792 Vals : IntArray (1 .. Len);
17793end record;
17794@end smallexample
17795
17796you can assign a value with a different size of @code{Vals} with two
17797assignments:
17798
17799@smallexample
077e0a52
JB
17800(@value{GDBP}) set A_Rec.Len := 4
17801(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17802@end smallexample
17803
17804As this example also illustrates, @value{GDBN} is very loose about the usual
17805rules concerning aggregates. You may leave out some of the
17806components of an array or record aggregate (such as the @code{Len}
17807component in the assignment to @code{A_Rec} above); they will retain their
17808original values upon assignment. You may freely use dynamic values as
17809indices in component associations. You may even use overlapping or
17810redundant component associations, although which component values are
17811assigned in such cases is not defined.
e07c999f
PH
17812
17813@item
17814Calls to dispatching subprograms are not implemented.
17815
17816@item
17817The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17818than that of real Ada. It makes only limited use of the context in
17819which a subexpression appears to resolve its meaning, and it is much
17820looser in its rules for allowing type matches. As a result, some
17821function calls will be ambiguous, and the user will be asked to choose
17822the proper resolution.
e07c999f
PH
17823
17824@item
17825The @code{new} operator is not implemented.
17826
17827@item
17828Entry calls are not implemented.
17829
17830@item
17831Aside from printing, arithmetic operations on the native VAX floating-point
17832formats are not supported.
17833
17834@item
17835It is not possible to slice a packed array.
158c7665
PH
17836
17837@item
17838The names @code{True} and @code{False}, when not part of a qualified name,
17839are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17840context.
17841Should your program
17842redefine these names in a package or procedure (at best a dubious practice),
17843you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17844@end itemize
17845
17846@node Additions to Ada
17847@subsubsection Additions to Ada
17848@cindex Ada, deviations from
17849
17850As it does for other languages, @value{GDBN} makes certain generic
17851extensions to Ada (@pxref{Expressions}):
17852
17853@itemize @bullet
17854@item
ae21e955
BW
17855If the expression @var{E} is a variable residing in memory (typically
17856a local variable or array element) and @var{N} is a positive integer,
17857then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17858@var{N}-1 adjacent variables following it in memory as an array. In
17859Ada, this operator is generally not necessary, since its prime use is
17860in displaying parts of an array, and slicing will usually do this in
17861Ada. However, there are occasional uses when debugging programs in
17862which certain debugging information has been optimized away.
e07c999f
PH
17863
17864@item
ae21e955
BW
17865@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17866appears in function or file @var{B}.'' When @var{B} is a file name,
17867you must typically surround it in single quotes.
e07c999f
PH
17868
17869@item
17870The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17871@var{type} that appears at address @var{addr}.''
17872
17873@item
17874A name starting with @samp{$} is a convenience variable
17875(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17876@end itemize
17877
ae21e955
BW
17878In addition, @value{GDBN} provides a few other shortcuts and outright
17879additions specific to Ada:
e07c999f
PH
17880
17881@itemize @bullet
17882@item
17883The assignment statement is allowed as an expression, returning
17884its right-hand operand as its value. Thus, you may enter
17885
17886@smallexample
077e0a52
JB
17887(@value{GDBP}) set x := y + 3
17888(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17889@end smallexample
17890
17891@item
17892The semicolon is allowed as an ``operator,'' returning as its value
17893the value of its right-hand operand.
17894This allows, for example,
17895complex conditional breaks:
17896
17897@smallexample
077e0a52
JB
17898(@value{GDBP}) break f
17899(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17900@end smallexample
17901
17902@item
17903Rather than use catenation and symbolic character names to introduce special
17904characters into strings, one may instead use a special bracket notation,
17905which is also used to print strings. A sequence of characters of the form
17906@samp{["@var{XX}"]} within a string or character literal denotes the
17907(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17908sequence of characters @samp{["""]} also denotes a single quotation mark
17909in strings. For example,
17910@smallexample
17911 "One line.["0a"]Next line.["0a"]"
17912@end smallexample
17913@noindent
ae21e955
BW
17914contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17915after each period.
e07c999f
PH
17916
17917@item
17918The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17919@t{'Max} is optional (and is ignored in any case). For example, it is valid
17920to write
17921
17922@smallexample
077e0a52 17923(@value{GDBP}) print 'max(x, y)
e07c999f
PH
17924@end smallexample
17925
17926@item
17927When printing arrays, @value{GDBN} uses positional notation when the
17928array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
17929For example, a one-dimensional array of three integers with a lower bound
17930of 3 might print as
e07c999f
PH
17931
17932@smallexample
17933(3 => 10, 17, 1)
17934@end smallexample
17935
17936@noindent
17937That is, in contrast to valid Ada, only the first component has a @code{=>}
17938clause.
17939
17940@item
17941You may abbreviate attributes in expressions with any unique,
17942multi-character subsequence of
17943their names (an exact match gets preference).
17944For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17945in place of @t{a'length}.
17946
17947@item
17948@cindex quoting Ada internal identifiers
17949Since Ada is case-insensitive, the debugger normally maps identifiers you type
17950to lower case. The GNAT compiler uses upper-case characters for
17951some of its internal identifiers, which are normally of no interest to users.
17952For the rare occasions when you actually have to look at them,
17953enclose them in angle brackets to avoid the lower-case mapping.
17954For example,
17955@smallexample
077e0a52 17956(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
17957@end smallexample
17958
17959@item
17960Printing an object of class-wide type or dereferencing an
17961access-to-class-wide value will display all the components of the object's
17962specific type (as indicated by its run-time tag). Likewise, component
17963selection on such a value will operate on the specific type of the
17964object.
17965
17966@end itemize
17967
3685b09f
PMR
17968@node Overloading support for Ada
17969@subsubsection Overloading support for Ada
17970@cindex overloading, Ada
17971
17972The debugger supports limited overloading. Given a subprogram call in which
17973the function symbol has multiple definitions, it will use the number of
17974actual parameters and some information about their types to attempt to narrow
17975the set of definitions. It also makes very limited use of context, preferring
17976procedures to functions in the context of the @code{call} command, and
17977functions to procedures elsewhere.
17978
17979If, after narrowing, the set of matching definitions still contains more than
17980one definition, @value{GDBN} will display a menu to query which one it should
17981use, for instance:
17982
17983@smallexample
17984(@value{GDBP}) print f(1)
17985Multiple matches for f
17986[0] cancel
17987[1] foo.f (integer) return boolean at foo.adb:23
17988[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17989>
17990@end smallexample
17991
17992In this case, just select one menu entry either to cancel expression evaluation
17993(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17994instance (type the corresponding number and press @key{RET}).
17995
17996Here are a couple of commands to customize @value{GDBN}'s behavior in this
17997case:
17998
17999@table @code
18000
18001@kindex set ada print-signatures
18002@item set ada print-signatures
18003Control whether parameter types and return types are displayed in overloads
18004selection menus. It is @code{on} by default.
18005@xref{Overloading support for Ada}.
18006
18007@kindex show ada print-signatures
18008@item show ada print-signatures
18009Show the current setting for displaying parameter types and return types in
18010overloads selection menu.
18011@xref{Overloading support for Ada}.
18012
18013@end table
18014
e07c999f
PH
18015@node Stopping Before Main Program
18016@subsubsection Stopping at the Very Beginning
18017
18018@cindex breakpointing Ada elaboration code
18019It is sometimes necessary to debug the program during elaboration, and
18020before reaching the main procedure.
18021As defined in the Ada Reference
18022Manual, the elaboration code is invoked from a procedure called
18023@code{adainit}. To run your program up to the beginning of
18024elaboration, simply use the following two commands:
18025@code{tbreak adainit} and @code{run}.
18026
58d06528
JB
18027@node Ada Exceptions
18028@subsubsection Ada Exceptions
18029
18030A command is provided to list all Ada exceptions:
18031
18032@table @code
18033@kindex info exceptions
18034@item info exceptions
18035@itemx info exceptions @var{regexp}
18036The @code{info exceptions} command allows you to list all Ada exceptions
18037defined within the program being debugged, as well as their addresses.
18038With a regular expression, @var{regexp}, as argument, only those exceptions
18039whose names match @var{regexp} are listed.
18040@end table
18041
18042Below is a small example, showing how the command can be used, first
18043without argument, and next with a regular expression passed as an
18044argument.
18045
18046@smallexample
18047(@value{GDBP}) info exceptions
18048All defined Ada exceptions:
18049constraint_error: 0x613da0
18050program_error: 0x613d20
18051storage_error: 0x613ce0
18052tasking_error: 0x613ca0
18053const.aint_global_e: 0x613b00
18054(@value{GDBP}) info exceptions const.aint
18055All Ada exceptions matching regular expression "const.aint":
18056constraint_error: 0x613da0
18057const.aint_global_e: 0x613b00
18058@end smallexample
18059
18060It is also possible to ask @value{GDBN} to stop your program's execution
18061when an exception is raised. For more details, see @ref{Set Catchpoints}.
18062
20924a55
JB
18063@node Ada Tasks
18064@subsubsection Extensions for Ada Tasks
18065@cindex Ada, tasking
18066
18067Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18068@value{GDBN} provides the following task-related commands:
18069
18070@table @code
18071@kindex info tasks
18072@item info tasks
18073This command shows a list of current Ada tasks, as in the following example:
18074
18075
18076@smallexample
18077@iftex
18078@leftskip=0.5cm
18079@end iftex
18080(@value{GDBP}) info tasks
18081 ID TID P-ID Pri State Name
18082 1 8088000 0 15 Child Activation Wait main_task
18083 2 80a4000 1 15 Accept Statement b
18084 3 809a800 1 15 Child Activation Wait a
32cd1edc 18085* 4 80ae800 3 15 Runnable c
20924a55
JB
18086
18087@end smallexample
18088
18089@noindent
18090In this listing, the asterisk before the last task indicates it to be the
18091task currently being inspected.
18092
18093@table @asis
18094@item ID
18095Represents @value{GDBN}'s internal task number.
18096
18097@item TID
18098The Ada task ID.
18099
18100@item P-ID
18101The parent's task ID (@value{GDBN}'s internal task number).
18102
18103@item Pri
18104The base priority of the task.
18105
18106@item State
18107Current state of the task.
18108
18109@table @code
18110@item Unactivated
18111The task has been created but has not been activated. It cannot be
18112executing.
18113
20924a55
JB
18114@item Runnable
18115The task is not blocked for any reason known to Ada. (It may be waiting
18116for a mutex, though.) It is conceptually "executing" in normal mode.
18117
18118@item Terminated
18119The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18120that were waiting on terminate alternatives have been awakened and have
18121terminated themselves.
18122
18123@item Child Activation Wait
18124The task is waiting for created tasks to complete activation.
18125
18126@item Accept Statement
18127The task is waiting on an accept or selective wait statement.
18128
18129@item Waiting on entry call
18130The task is waiting on an entry call.
18131
18132@item Async Select Wait
18133The task is waiting to start the abortable part of an asynchronous
18134select statement.
18135
18136@item Delay Sleep
18137The task is waiting on a select statement with only a delay
18138alternative open.
18139
18140@item Child Termination Wait
18141The task is sleeping having completed a master within itself, and is
18142waiting for the tasks dependent on that master to become terminated or
18143waiting on a terminate Phase.
18144
18145@item Wait Child in Term Alt
18146The task is sleeping waiting for tasks on terminate alternatives to
18147finish terminating.
18148
18149@item Accepting RV with @var{taskno}
18150The task is accepting a rendez-vous with the task @var{taskno}.
18151@end table
18152
18153@item Name
18154Name of the task in the program.
18155
18156@end table
18157
18158@kindex info task @var{taskno}
18159@item info task @var{taskno}
6b92c0d3 18160This command shows detailed informations on the specified task, as in
20924a55
JB
18161the following example:
18162@smallexample
18163@iftex
18164@leftskip=0.5cm
18165@end iftex
18166(@value{GDBP}) info tasks
18167 ID TID P-ID Pri State Name
18168 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18169* 2 807c468 1 15 Runnable task_1
20924a55
JB
18170(@value{GDBP}) info task 2
18171Ada Task: 0x807c468
4993045d 18172Name: "task_1"
87f7ab7b
JB
18173Thread: 0
18174LWP: 0x1fac
4993045d 18175Parent: 1 ("main_task")
20924a55
JB
18176Base Priority: 15
18177State: Runnable
18178@end smallexample
18179
18180@item task
18181@kindex task@r{ (Ada)}
18182@cindex current Ada task ID
4993045d 18183This command prints the ID and name of the current task.
20924a55
JB
18184
18185@smallexample
18186@iftex
18187@leftskip=0.5cm
18188@end iftex
18189(@value{GDBP}) info tasks
18190 ID TID P-ID Pri State Name
18191 1 8077870 0 15 Child Activation Wait main_task
4993045d 18192* 2 807c458 1 15 Runnable some_task
20924a55 18193(@value{GDBP}) task
4993045d 18194[Current task is 2 "some_task"]
20924a55
JB
18195@end smallexample
18196
18197@item task @var{taskno}
18198@cindex Ada task switching
5d5658a1 18199This command is like the @code{thread @var{thread-id}}
20924a55
JB
18200command (@pxref{Threads}). It switches the context of debugging
18201from the current task to the given task.
18202
18203@smallexample
18204@iftex
18205@leftskip=0.5cm
18206@end iftex
18207(@value{GDBP}) info tasks
18208 ID TID P-ID Pri State Name
18209 1 8077870 0 15 Child Activation Wait main_task
4993045d 18210* 2 807c458 1 15 Runnable some_task
20924a55 18211(@value{GDBP}) task 1
4993045d 18212[Switching to task 1 "main_task"]
20924a55
JB
18213#0 0x8067726 in pthread_cond_wait ()
18214(@value{GDBP}) bt
18215#0 0x8067726 in pthread_cond_wait ()
18216#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18217#2 0x805cb63 in system.task_primitives.operations.sleep ()
18218#3 0x806153e in system.tasking.stages.activate_tasks ()
18219#4 0x804aacc in un () at un.adb:5
18220@end smallexample
18221
629500fa
KS
18222@item break @var{location} task @var{taskno}
18223@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18224@cindex breakpoints and tasks, in Ada
18225@cindex task breakpoints, in Ada
18226@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18227These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18228command (@pxref{Thread Stops}). The
629500fa 18229@var{location} argument specifies source lines, as described
45ac276d
JB
18230in @ref{Specify Location}.
18231
18232Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18233to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18234particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18235numeric task identifiers assigned by @value{GDBN}, shown in the first
18236column of the @samp{info tasks} display.
18237
18238If you do not specify @samp{task @var{taskno}} when you set a
18239breakpoint, the breakpoint applies to @emph{all} tasks of your
18240program.
18241
18242You can use the @code{task} qualifier on conditional breakpoints as
18243well; in this case, place @samp{task @var{taskno}} before the
18244breakpoint condition (before the @code{if}).
18245
18246For example,
18247
18248@smallexample
18249@iftex
18250@leftskip=0.5cm
18251@end iftex
18252(@value{GDBP}) info tasks
18253 ID TID P-ID Pri State Name
18254 1 140022020 0 15 Child Activation Wait main_task
18255 2 140045060 1 15 Accept/Select Wait t2
18256 3 140044840 1 15 Runnable t1
18257* 4 140056040 1 15 Runnable t3
18258(@value{GDBP}) b 15 task 2
18259Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18260(@value{GDBP}) cont
18261Continuing.
18262task # 1 running
18263task # 2 running
18264
18265Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1826615 flush;
18267(@value{GDBP}) info tasks
18268 ID TID P-ID Pri State Name
18269 1 140022020 0 15 Child Activation Wait main_task
18270* 2 140045060 1 15 Runnable t2
18271 3 140044840 1 15 Runnable t1
18272 4 140056040 1 15 Delay Sleep t3
18273@end smallexample
20924a55
JB
18274@end table
18275
18276@node Ada Tasks and Core Files
18277@subsubsection Tasking Support when Debugging Core Files
18278@cindex Ada tasking and core file debugging
18279
18280When inspecting a core file, as opposed to debugging a live program,
18281tasking support may be limited or even unavailable, depending on
18282the platform being used.
18283For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18284switching is not supported.
20924a55 18285
32a8097b 18286On certain platforms, the debugger needs to perform some
20924a55
JB
18287memory writes in order to provide Ada tasking support. When inspecting
18288a core file, this means that the core file must be opened with read-write
18289privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18290Under these circumstances, you should make a backup copy of the core
18291file before inspecting it with @value{GDBN}.
18292
6e1bb179
JB
18293@node Ravenscar Profile
18294@subsubsection Tasking Support when using the Ravenscar Profile
18295@cindex Ravenscar Profile
18296
18297The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18298specifically designed for systems with safety-critical real-time
18299requirements.
18300
18301@table @code
18302@kindex set ravenscar task-switching on
18303@cindex task switching with program using Ravenscar Profile
18304@item set ravenscar task-switching on
18305Allows task switching when debugging a program that uses the Ravenscar
18306Profile. This is the default.
18307
18308@kindex set ravenscar task-switching off
18309@item set ravenscar task-switching off
18310Turn off task switching when debugging a program that uses the Ravenscar
18311Profile. This is mostly intended to disable the code that adds support
18312for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18313the Ravenscar runtime is preventing @value{GDBN} from working properly.
18314To be effective, this command should be run before the program is started.
18315
18316@kindex show ravenscar task-switching
18317@item show ravenscar task-switching
18318Show whether it is possible to switch from task to task in a program
18319using the Ravenscar Profile.
18320
18321@end table
18322
e09eef98
TT
18323@cindex Ravenscar thread
18324When Ravenscar task-switching is enabled, Ravenscar tasks are
18325announced by @value{GDBN} as if they were threads:
18326
18327@smallexample
18328(gdb) continue
18329[New Ravenscar Thread 0x2b8f0]
18330@end smallexample
18331
18332Both Ravenscar tasks and the underlying CPU threads will show up in
18333the output of @code{info threads}:
18334
18335@smallexample
18336(gdb) info threads
18337 Id Target Id Frame
18338 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18339 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18340 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18341 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18342* 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18343 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18344@end smallexample
18345
18346One known limitation of the Ravenscar support in @value{GDBN} is that
18347it isn't currently possible to single-step through the runtime
18348initialization sequence. If you need to debug this code, you should
18349use @code{set ravenscar task-switching off}.
18350
3fcded8f
JB
18351@node Ada Settings
18352@subsubsection Ada Settings
18353@cindex Ada settings
18354
18355@table @code
18356@kindex set varsize-limit
18357@item set varsize-limit @var{size}
18358Prevent @value{GDBN} from attempting to evaluate objects whose size
18359is above the given limit (@var{size}) when those sizes are computed
18360from run-time quantities. This is typically the case when the object
18361has a variable size, such as an array whose bounds are not known at
18362compile time for example. Setting @var{size} to @code{unlimited}
18363removes the size limitation. By default, the limit is about 65KB.
18364
18365The purpose of having such a limit is to prevent @value{GDBN} from
18366trying to grab enormous chunks of virtual memory when asked to evaluate
18367a quantity whose bounds have been corrupted or have not yet been fully
18368initialized. The limit applies to the results of some subexpressions
18369as well as to complete expressions. For example, an expression denoting
18370a simple integer component, such as @code{x.y.z}, may fail if the size of
18371@code{x.y} is variable and exceeds @code{size}. On the other hand,
18372@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18373@code{A} is an array variable with non-constant size, will generally
18374succeed regardless of the bounds on @code{A}, as long as the component
18375size is less than @var{size}.
18376
18377@kindex show varsize-limit
18378@item show varsize-limit
18379Show the limit on types whose size is determined by run-time quantities.
18380@end table
18381
e07c999f
PH
18382@node Ada Glitches
18383@subsubsection Known Peculiarities of Ada Mode
18384@cindex Ada, problems
18385
18386Besides the omissions listed previously (@pxref{Omissions from Ada}),
18387we know of several problems with and limitations of Ada mode in
18388@value{GDBN},
18389some of which will be fixed with planned future releases of the debugger
18390and the GNU Ada compiler.
18391
18392@itemize @bullet
e07c999f
PH
18393@item
18394Static constants that the compiler chooses not to materialize as objects in
18395storage are invisible to the debugger.
18396
18397@item
18398Named parameter associations in function argument lists are ignored (the
18399argument lists are treated as positional).
18400
18401@item
18402Many useful library packages are currently invisible to the debugger.
18403
18404@item
18405Fixed-point arithmetic, conversions, input, and output is carried out using
18406floating-point arithmetic, and may give results that only approximate those on
18407the host machine.
18408
e07c999f
PH
18409@item
18410The GNAT compiler never generates the prefix @code{Standard} for any of
18411the standard symbols defined by the Ada language. @value{GDBN} knows about
18412this: it will strip the prefix from names when you use it, and will never
18413look for a name you have so qualified among local symbols, nor match against
18414symbols in other packages or subprograms. If you have
18415defined entities anywhere in your program other than parameters and
18416local variables whose simple names match names in @code{Standard},
18417GNAT's lack of qualification here can cause confusion. When this happens,
18418you can usually resolve the confusion
18419by qualifying the problematic names with package
18420@code{Standard} explicitly.
18421@end itemize
18422
95433b34
JB
18423Older versions of the compiler sometimes generate erroneous debugging
18424information, resulting in the debugger incorrectly printing the value
18425of affected entities. In some cases, the debugger is able to work
18426around an issue automatically. In other cases, the debugger is able
18427to work around the issue, but the work-around has to be specifically
18428enabled.
18429
18430@kindex set ada trust-PAD-over-XVS
18431@kindex show ada trust-PAD-over-XVS
18432@table @code
18433
18434@item set ada trust-PAD-over-XVS on
18435Configure GDB to strictly follow the GNAT encoding when computing the
18436value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18437types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18438a complete description of the encoding used by the GNAT compiler).
18439This is the default.
18440
18441@item set ada trust-PAD-over-XVS off
18442This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18443sometimes prints the wrong value for certain entities, changing @code{ada
18444trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18445the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18446@code{off}, but this incurs a slight performance penalty, so it is
18447recommended to leave this setting to @code{on} unless necessary.
18448
18449@end table
18450
c6044dd1
JB
18451@cindex GNAT descriptive types
18452@cindex GNAT encoding
18453Internally, the debugger also relies on the compiler following a number
18454of conventions known as the @samp{GNAT Encoding}, all documented in
18455@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18456how the debugging information should be generated for certain types.
18457In particular, this convention makes use of @dfn{descriptive types},
18458which are artificial types generated purely to help the debugger.
18459
18460These encodings were defined at a time when the debugging information
18461format used was not powerful enough to describe some of the more complex
18462types available in Ada. Since DWARF allows us to express nearly all
18463Ada features, the long-term goal is to slowly replace these descriptive
18464types by their pure DWARF equivalent. To facilitate that transition,
18465a new maintenance option is available to force the debugger to ignore
18466those descriptive types. It allows the user to quickly evaluate how
18467well @value{GDBN} works without them.
18468
18469@table @code
18470
18471@kindex maint ada set ignore-descriptive-types
18472@item maintenance ada set ignore-descriptive-types [on|off]
18473Control whether the debugger should ignore descriptive types.
18474The default is not to ignore descriptives types (@code{off}).
18475
18476@kindex maint ada show ignore-descriptive-types
18477@item maintenance ada show ignore-descriptive-types
18478Show if descriptive types are ignored by @value{GDBN}.
18479
18480@end table
18481
79a6e687
BW
18482@node Unsupported Languages
18483@section Unsupported Languages
4e562065
JB
18484
18485@cindex unsupported languages
18486@cindex minimal language
18487In addition to the other fully-supported programming languages,
18488@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18489It does not represent a real programming language, but provides a set
18490of capabilities close to what the C or assembly languages provide.
18491This should allow most simple operations to be performed while debugging
18492an application that uses a language currently not supported by @value{GDBN}.
18493
18494If the language is set to @code{auto}, @value{GDBN} will automatically
18495select this language if the current frame corresponds to an unsupported
18496language.
18497
6d2ebf8b 18498@node Symbols
c906108c
SS
18499@chapter Examining the Symbol Table
18500
d4f3574e 18501The commands described in this chapter allow you to inquire about the
c906108c
SS
18502symbols (names of variables, functions and types) defined in your
18503program. This information is inherent in the text of your program and
18504does not change as your program executes. @value{GDBN} finds it in your
18505program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18506(@pxref{File Options, ,Choosing Files}), or by one of the
18507file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18508
18509@cindex symbol names
18510@cindex names of symbols
18511@cindex quoting names
d044bac8 18512@anchor{quoting names}
c906108c
SS
18513Occasionally, you may need to refer to symbols that contain unusual
18514characters, which @value{GDBN} ordinarily treats as word delimiters. The
18515most frequent case is in referring to static variables in other
79a6e687 18516source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18517are recorded in object files as debugging symbols, but @value{GDBN} would
18518ordinarily parse a typical file name, like @file{foo.c}, as the three words
18519@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18520@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18521
474c8240 18522@smallexample
c906108c 18523p 'foo.c'::x
474c8240 18524@end smallexample
c906108c
SS
18525
18526@noindent
18527looks up the value of @code{x} in the scope of the file @file{foo.c}.
18528
18529@table @code
a8f24a35
EZ
18530@cindex case-insensitive symbol names
18531@cindex case sensitivity in symbol names
18532@kindex set case-sensitive
18533@item set case-sensitive on
18534@itemx set case-sensitive off
18535@itemx set case-sensitive auto
18536Normally, when @value{GDBN} looks up symbols, it matches their names
18537with case sensitivity determined by the current source language.
18538Occasionally, you may wish to control that. The command @code{set
18539case-sensitive} lets you do that by specifying @code{on} for
18540case-sensitive matches or @code{off} for case-insensitive ones. If
18541you specify @code{auto}, case sensitivity is reset to the default
18542suitable for the source language. The default is case-sensitive
18543matches for all languages except for Fortran, for which the default is
18544case-insensitive matches.
18545
9c16f35a
EZ
18546@kindex show case-sensitive
18547@item show case-sensitive
a8f24a35
EZ
18548This command shows the current setting of case sensitivity for symbols
18549lookups.
18550
53342f27
TT
18551@kindex set print type methods
18552@item set print type methods
18553@itemx set print type methods on
18554@itemx set print type methods off
18555Normally, when @value{GDBN} prints a class, it displays any methods
18556declared in that class. You can control this behavior either by
18557passing the appropriate flag to @code{ptype}, or using @command{set
18558print type methods}. Specifying @code{on} will cause @value{GDBN} to
18559display the methods; this is the default. Specifying @code{off} will
18560cause @value{GDBN} to omit the methods.
18561
18562@kindex show print type methods
18563@item show print type methods
18564This command shows the current setting of method display when printing
18565classes.
18566
883fd55a
KS
18567@kindex set print type nested-type-limit
18568@item set print type nested-type-limit @var{limit}
18569@itemx set print type nested-type-limit unlimited
18570Set the limit of displayed nested types that the type printer will
18571show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18572nested definitions. By default, the type printer will not show any nested
18573types defined in classes.
18574
18575@kindex show print type nested-type-limit
18576@item show print type nested-type-limit
18577This command shows the current display limit of nested types when
18578printing classes.
18579
53342f27
TT
18580@kindex set print type typedefs
18581@item set print type typedefs
18582@itemx set print type typedefs on
18583@itemx set print type typedefs off
18584
18585Normally, when @value{GDBN} prints a class, it displays any typedefs
18586defined in that class. You can control this behavior either by
18587passing the appropriate flag to @code{ptype}, or using @command{set
18588print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18589display the typedef definitions; this is the default. Specifying
18590@code{off} will cause @value{GDBN} to omit the typedef definitions.
18591Note that this controls whether the typedef definition itself is
18592printed, not whether typedef names are substituted when printing other
18593types.
18594
18595@kindex show print type typedefs
18596@item show print type typedefs
18597This command shows the current setting of typedef display when
18598printing classes.
18599
c906108c 18600@kindex info address
b37052ae 18601@cindex address of a symbol
c906108c
SS
18602@item info address @var{symbol}
18603Describe where the data for @var{symbol} is stored. For a register
18604variable, this says which register it is kept in. For a non-register
18605local variable, this prints the stack-frame offset at which the variable
18606is always stored.
18607
18608Note the contrast with @samp{print &@var{symbol}}, which does not work
18609at all for a register variable, and for a stack local variable prints
18610the exact address of the current instantiation of the variable.
18611
3d67e040 18612@kindex info symbol
b37052ae 18613@cindex symbol from address
9c16f35a 18614@cindex closest symbol and offset for an address
3d67e040
EZ
18615@item info symbol @var{addr}
18616Print the name of a symbol which is stored at the address @var{addr}.
18617If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18618nearest symbol and an offset from it:
18619
474c8240 18620@smallexample
3d67e040
EZ
18621(@value{GDBP}) info symbol 0x54320
18622_initialize_vx + 396 in section .text
474c8240 18623@end smallexample
3d67e040
EZ
18624
18625@noindent
18626This is the opposite of the @code{info address} command. You can use
18627it to find out the name of a variable or a function given its address.
18628
c14c28ba
PP
18629For dynamically linked executables, the name of executable or shared
18630library containing the symbol is also printed:
18631
18632@smallexample
18633(@value{GDBP}) info symbol 0x400225
18634_start + 5 in section .text of /tmp/a.out
18635(@value{GDBP}) info symbol 0x2aaaac2811cf
18636__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18637@end smallexample
18638
439250fb
DE
18639@kindex demangle
18640@cindex demangle
18641@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18642Demangle @var{name}.
18643If @var{language} is provided it is the name of the language to demangle
18644@var{name} in. Otherwise @var{name} is demangled in the current language.
18645
18646The @samp{--} option specifies the end of options,
18647and is useful when @var{name} begins with a dash.
18648
18649The parameter @code{demangle-style} specifies how to interpret the kind
18650of mangling used. @xref{Print Settings}.
18651
c906108c 18652@kindex whatis
53342f27 18653@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18654Print the data type of @var{arg}, which can be either an expression
18655or a name of a data type. With no argument, print the data type of
18656@code{$}, the last value in the value history.
18657
18658If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18659is not actually evaluated, and any side-effecting operations (such as
18660assignments or function calls) inside it do not take place.
18661
18662If @var{arg} is a variable or an expression, @code{whatis} prints its
18663literal type as it is used in the source code. If the type was
18664defined using a @code{typedef}, @code{whatis} will @emph{not} print
18665the data type underlying the @code{typedef}. If the type of the
18666variable or the expression is a compound data type, such as
18667@code{struct} or @code{class}, @code{whatis} never prints their
18668fields or methods. It just prints the @code{struct}/@code{class}
18669name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18670such a compound data type, use @code{ptype}.
18671
18672If @var{arg} is a type name that was defined using @code{typedef},
18673@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18674Unrolling means that @code{whatis} will show the underlying type used
18675in the @code{typedef} declaration of @var{arg}. However, if that
18676underlying type is also a @code{typedef}, @code{whatis} will not
18677unroll it.
18678
18679For C code, the type names may also have the form @samp{class
18680@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18681@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18682
53342f27
TT
18683@var{flags} can be used to modify how the type is displayed.
18684Available flags are:
18685
18686@table @code
18687@item r
18688Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18689parameters and typedefs defined in a class when printing the class'
18690members. The @code{/r} flag disables this.
18691
18692@item m
18693Do not print methods defined in the class.
18694
18695@item M
18696Print methods defined in the class. This is the default, but the flag
18697exists in case you change the default with @command{set print type methods}.
18698
18699@item t
18700Do not print typedefs defined in the class. Note that this controls
18701whether the typedef definition itself is printed, not whether typedef
18702names are substituted when printing other types.
18703
18704@item T
18705Print typedefs defined in the class. This is the default, but the flag
18706exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18707
18708@item o
18709Print the offsets and sizes of fields in a struct, similar to what the
18710@command{pahole} tool does. This option implies the @code{/tm} flags.
18711
18712For example, given the following declarations:
18713
18714@smallexample
18715struct tuv
18716@{
18717 int a1;
18718 char *a2;
18719 int a3;
18720@};
18721
18722struct xyz
18723@{
18724 int f1;
18725 char f2;
18726 void *f3;
18727 struct tuv f4;
18728@};
18729
18730union qwe
18731@{
18732 struct tuv fff1;
18733 struct xyz fff2;
18734@};
18735
18736struct tyu
18737@{
18738 int a1 : 1;
18739 int a2 : 3;
18740 int a3 : 23;
18741 char a4 : 2;
18742 int64_t a5;
18743 int a6 : 5;
18744 int64_t a7 : 3;
18745@};
18746@end smallexample
18747
18748Issuing a @kbd{ptype /o struct tuv} command would print:
18749
18750@smallexample
18751(@value{GDBP}) ptype /o struct tuv
18752/* offset | size */ type = struct tuv @{
18753/* 0 | 4 */ int a1;
18754/* XXX 4-byte hole */
18755/* 8 | 8 */ char *a2;
18756/* 16 | 4 */ int a3;
18757
18758 /* total size (bytes): 24 */
18759 @}
18760@end smallexample
18761
18762Notice the format of the first column of comments. There, you can
18763find two parts separated by the @samp{|} character: the @emph{offset},
18764which indicates where the field is located inside the struct, in
18765bytes, and the @emph{size} of the field. Another interesting line is
18766the marker of a @emph{hole} in the struct, indicating that it may be
18767possible to pack the struct and make it use less space by reorganizing
18768its fields.
18769
18770It is also possible to print offsets inside an union:
18771
18772@smallexample
18773(@value{GDBP}) ptype /o union qwe
18774/* offset | size */ type = union qwe @{
18775/* 24 */ struct tuv @{
18776/* 0 | 4 */ int a1;
18777/* XXX 4-byte hole */
18778/* 8 | 8 */ char *a2;
18779/* 16 | 4 */ int a3;
18780
18781 /* total size (bytes): 24 */
18782 @} fff1;
18783/* 40 */ struct xyz @{
18784/* 0 | 4 */ int f1;
18785/* 4 | 1 */ char f2;
18786/* XXX 3-byte hole */
18787/* 8 | 8 */ void *f3;
18788/* 16 | 24 */ struct tuv @{
18789/* 16 | 4 */ int a1;
18790/* XXX 4-byte hole */
18791/* 24 | 8 */ char *a2;
18792/* 32 | 4 */ int a3;
18793
18794 /* total size (bytes): 24 */
18795 @} f4;
18796
18797 /* total size (bytes): 40 */
18798 @} fff2;
18799
18800 /* total size (bytes): 40 */
18801 @}
18802@end smallexample
18803
18804In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18805same space (because we are dealing with an union), the offset is not
18806printed for them. However, you can still examine the offset of each
18807of these structures' fields.
18808
18809Another useful scenario is printing the offsets of a struct containing
18810bitfields:
18811
18812@smallexample
18813(@value{GDBP}) ptype /o struct tyu
18814/* offset | size */ type = struct tyu @{
18815/* 0:31 | 4 */ int a1 : 1;
18816/* 0:28 | 4 */ int a2 : 3;
18817/* 0: 5 | 4 */ int a3 : 23;
18818/* 3: 3 | 1 */ signed char a4 : 2;
18819/* XXX 3-bit hole */
18820/* XXX 4-byte hole */
18821/* 8 | 8 */ int64_t a5;
9d3421af
TT
18822/* 16: 0 | 4 */ int a6 : 5;
18823/* 16: 5 | 8 */ int64_t a7 : 3;
18824"/* XXX 7-byte padding */
7c161838
SDJ
18825
18826 /* total size (bytes): 24 */
18827 @}
18828@end smallexample
18829
9d3421af
TT
18830Note how the offset information is now extended to also include the
18831first bit of the bitfield.
53342f27
TT
18832@end table
18833
c906108c 18834@kindex ptype
53342f27 18835@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18836@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18837detailed description of the type, instead of just the name of the type.
18838@xref{Expressions, ,Expressions}.
c906108c 18839
177bc839
JK
18840Contrary to @code{whatis}, @code{ptype} always unrolls any
18841@code{typedef}s in its argument declaration, whether the argument is
18842a variable, expression, or a data type. This means that @code{ptype}
18843of a variable or an expression will not print literally its type as
18844present in the source code---use @code{whatis} for that. @code{typedef}s at
18845the pointer or reference targets are also unrolled. Only @code{typedef}s of
18846fields, methods and inner @code{class typedef}s of @code{struct}s,
18847@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18848
c906108c
SS
18849For example, for this variable declaration:
18850
474c8240 18851@smallexample
177bc839
JK
18852typedef double real_t;
18853struct complex @{ real_t real; double imag; @};
18854typedef struct complex complex_t;
18855complex_t var;
18856real_t *real_pointer_var;
474c8240 18857@end smallexample
c906108c
SS
18858
18859@noindent
18860the two commands give this output:
18861
474c8240 18862@smallexample
c906108c 18863@group
177bc839
JK
18864(@value{GDBP}) whatis var
18865type = complex_t
18866(@value{GDBP}) ptype var
18867type = struct complex @{
18868 real_t real;
18869 double imag;
18870@}
18871(@value{GDBP}) whatis complex_t
18872type = struct complex
18873(@value{GDBP}) whatis struct complex
c906108c 18874type = struct complex
177bc839 18875(@value{GDBP}) ptype struct complex
c906108c 18876type = struct complex @{
177bc839 18877 real_t real;
c906108c
SS
18878 double imag;
18879@}
177bc839
JK
18880(@value{GDBP}) whatis real_pointer_var
18881type = real_t *
18882(@value{GDBP}) ptype real_pointer_var
18883type = double *
c906108c 18884@end group
474c8240 18885@end smallexample
c906108c
SS
18886
18887@noindent
18888As with @code{whatis}, using @code{ptype} without an argument refers to
18889the type of @code{$}, the last value in the value history.
18890
ab1adacd
EZ
18891@cindex incomplete type
18892Sometimes, programs use opaque data types or incomplete specifications
18893of complex data structure. If the debug information included in the
18894program does not allow @value{GDBN} to display a full declaration of
18895the data type, it will say @samp{<incomplete type>}. For example,
18896given these declarations:
18897
18898@smallexample
18899 struct foo;
18900 struct foo *fooptr;
18901@end smallexample
18902
18903@noindent
18904but no definition for @code{struct foo} itself, @value{GDBN} will say:
18905
18906@smallexample
ddb50cd7 18907 (@value{GDBP}) ptype foo
ab1adacd
EZ
18908 $1 = <incomplete type>
18909@end smallexample
18910
18911@noindent
18912``Incomplete type'' is C terminology for data types that are not
18913completely specified.
18914
d69cf9b2
PA
18915@cindex unknown type
18916Othertimes, information about a variable's type is completely absent
18917from the debug information included in the program. This most often
18918happens when the program or library where the variable is defined
18919includes no debug information at all. @value{GDBN} knows the variable
18920exists from inspecting the linker/loader symbol table (e.g., the ELF
18921dynamic symbol table), but such symbols do not contain type
18922information. Inspecting the type of a (global) variable for which
18923@value{GDBN} has no type information shows:
18924
18925@smallexample
18926 (@value{GDBP}) ptype var
18927 type = <data variable, no debug info>
18928@end smallexample
18929
18930@xref{Variables, no debug info variables}, for how to print the values
18931of such variables.
18932
c906108c 18933@kindex info types
a8eab7c6 18934@item info types [-q] [@var{regexp}]
09d4efe1
EZ
18935Print a brief description of all types whose names match the regular
18936expression @var{regexp} (or all types in your program, if you supply
18937no argument). Each complete typename is matched as though it were a
18938complete line; thus, @samp{i type value} gives information on all
18939types in your program whose names include the string @code{value}, but
18940@samp{i type ^value$} gives information only on types whose complete
18941name is @code{value}.
c906108c 18942
20813a0b
PW
18943In programs using different languages, @value{GDBN} chooses the syntax
18944to print the type description according to the
18945@samp{set language} value: using @samp{set language auto}
18946(see @ref{Automatically, ,Set Language Automatically}) means to use the
18947language of the type, other values mean to use
18948the manually specified language (see @ref{Manually, ,Set Language Manually}).
18949
c906108c
SS
18950This command differs from @code{ptype} in two ways: first, like
18951@code{whatis}, it does not print a detailed description; second, it
b744723f 18952lists all source files and line numbers where a type is defined.
c906108c 18953
a8eab7c6
AB
18954The output from @samp{into types} is proceeded with a header line
18955describing what types are being listed. The optional flag @samp{-q},
18956which stands for @samp{quiet}, disables printing this header
18957information.
18958
18a9fc12
TT
18959@kindex info type-printers
18960@item info type-printers
18961Versions of @value{GDBN} that ship with Python scripting enabled may
18962have ``type printers'' available. When using @command{ptype} or
18963@command{whatis}, these printers are consulted when the name of a type
18964is needed. @xref{Type Printing API}, for more information on writing
18965type printers.
18966
18967@code{info type-printers} displays all the available type printers.
18968
18969@kindex enable type-printer
18970@kindex disable type-printer
18971@item enable type-printer @var{name}@dots{}
18972@item disable type-printer @var{name}@dots{}
18973These commands can be used to enable or disable type printers.
18974
b37052ae
EZ
18975@kindex info scope
18976@cindex local variables
09d4efe1 18977@item info scope @var{location}
b37052ae 18978List all the variables local to a particular scope. This command
09d4efe1
EZ
18979accepts a @var{location} argument---a function name, a source line, or
18980an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
18981to the scope defined by that location. (@xref{Specify Location}, for
18982details about supported forms of @var{location}.) For example:
b37052ae
EZ
18983
18984@smallexample
18985(@value{GDBP}) @b{info scope command_line_handler}
18986Scope for command_line_handler:
18987Symbol rl is an argument at stack/frame offset 8, length 4.
18988Symbol linebuffer is in static storage at address 0x150a18, length 4.
18989Symbol linelength is in static storage at address 0x150a1c, length 4.
18990Symbol p is a local variable in register $esi, length 4.
18991Symbol p1 is a local variable in register $ebx, length 4.
18992Symbol nline is a local variable in register $edx, length 4.
18993Symbol repeat is a local variable at frame offset -8, length 4.
18994@end smallexample
18995
f5c37c66
EZ
18996@noindent
18997This command is especially useful for determining what data to collect
18998during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18999collect}.
19000
c906108c
SS
19001@kindex info source
19002@item info source
919d772c
JB
19003Show information about the current source file---that is, the source file for
19004the function containing the current point of execution:
19005@itemize @bullet
19006@item
19007the name of the source file, and the directory containing it,
19008@item
19009the directory it was compiled in,
19010@item
19011its length, in lines,
19012@item
19013which programming language it is written in,
19014@item
b6577aab
DE
19015if the debug information provides it, the program that compiled the file
19016(which may include, e.g., the compiler version and command line arguments),
19017@item
919d772c
JB
19018whether the executable includes debugging information for that file, and
19019if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19020@item
19021whether the debugging information includes information about
19022preprocessor macros.
19023@end itemize
19024
c906108c
SS
19025
19026@kindex info sources
19027@item info sources
19028Print the names of all source files in your program for which there is
19029debugging information, organized into two lists: files whose symbols
19030have already been read, and files whose symbols will be read when needed.
19031
ae60f04e
PW
19032@item info sources [-dirname | -basename] [--] [@var{regexp}]
19033Like @samp{info sources}, but only print the names of the files
19034matching the provided @var{regexp}.
19035By default, the @var{regexp} is used to match anywhere in the filename.
19036If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19037If @code{-basename}, only files having a basename matching @var{regexp}
19038are shown.
19039The matching is case-sensitive, except on operating systems that
19040have case-insensitive filesystem (e.g., MS-Windows).
19041
c906108c 19042@kindex info functions
4acfdd20 19043@item info functions [-q] [-n]
c906108c 19044Print the names and data types of all defined functions.
b744723f
AA
19045Similarly to @samp{info types}, this command groups its output by source
19046files and annotates each function definition with its source line
19047number.
c906108c 19048
20813a0b
PW
19049In programs using different languages, @value{GDBN} chooses the syntax
19050to print the function name and type according to the
19051@samp{set language} value: using @samp{set language auto}
19052(see @ref{Automatically, ,Set Language Automatically}) means to use the
19053language of the function, other values mean to use
19054the manually specified language (see @ref{Manually, ,Set Language Manually}).
19055
4acfdd20
AB
19056The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19057results. A non-debugging symbol is a symbol that comes from the
19058executable's symbol table, not from the debug information (for
19059example, DWARF) associated with the executable.
19060
d321477b
PW
19061The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19062printing header information and messages explaining why no functions
19063have been printed.
19064
4acfdd20 19065@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19066Like @samp{info functions}, but only print the names and data types
19067of the functions selected with the provided regexp(s).
19068
19069If @var{regexp} is provided, print only the functions whose names
19070match the regular expression @var{regexp}.
19071Thus, @samp{info fun step} finds all functions whose
b744723f
AA
19072names include @code{step}; @samp{info fun ^step} finds those whose names
19073start with @code{step}. If a function name contains characters that
19074conflict with the regular expression language (e.g.@:
1c5dfdad 19075@samp{operator*()}), they may be quoted with a backslash.
c906108c 19076
d321477b
PW
19077If @var{type_regexp} is provided, print only the functions whose
19078types, as printed by the @code{whatis} command, match
19079the regular expression @var{type_regexp}.
19080If @var{type_regexp} contains space(s), it should be enclosed in
19081quote characters. If needed, use backslash to escape the meaning
19082of special characters or quotes.
19083Thus, @samp{info fun -t '^int ('} finds the functions that return
19084an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19085have an argument type containing int; @samp{info fun -t '^int (' ^step}
19086finds the functions whose names start with @code{step} and that return
19087int.
19088
19089If both @var{regexp} and @var{type_regexp} are provided, a function
19090is printed only if its name matches @var{regexp} and its type matches
19091@var{type_regexp}.
19092
19093
c906108c 19094@kindex info variables
4acfdd20 19095@item info variables [-q] [-n]
0fe7935b 19096Print the names and data types of all variables that are defined
6ca652b0 19097outside of functions (i.e.@: excluding local variables).
b744723f
AA
19098The printed variables are grouped by source files and annotated with
19099their respective source line numbers.
c906108c 19100
20813a0b
PW
19101In programs using different languages, @value{GDBN} chooses the syntax
19102to print the variable name and type according to the
19103@samp{set language} value: using @samp{set language auto}
19104(see @ref{Automatically, ,Set Language Automatically}) means to use the
19105language of the variable, other values mean to use
19106the manually specified language (see @ref{Manually, ,Set Language Manually}).
19107
4acfdd20
AB
19108The @samp{-n} flag excludes non-debugging symbols from the results.
19109
d321477b
PW
19110The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19111printing header information and messages explaining why no variables
19112have been printed.
19113
4acfdd20 19114@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19115Like @kbd{info variables}, but only print the variables selected
19116with the provided regexp(s).
19117
19118If @var{regexp} is provided, print only the variables whose names
19119match the regular expression @var{regexp}.
19120
19121If @var{type_regexp} is provided, print only the variables whose
19122types, as printed by the @code{whatis} command, match
19123the regular expression @var{type_regexp}.
19124If @var{type_regexp} contains space(s), it should be enclosed in
19125quote characters. If needed, use backslash to escape the meaning
19126of special characters or quotes.
19127
19128If both @var{regexp} and @var{type_regexp} are provided, an argument
19129is printed only if its name matches @var{regexp} and its type matches
19130@var{type_regexp}.
c906108c 19131
59c35742
AB
19132@kindex info modules
19133@cindex modules
19134@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19135List all Fortran modules in the program, or all modules matching the
19136optional regular expression @var{regexp}.
19137
19138The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19139printing header information and messages explaining why no modules
19140have been printed.
165f8965
AB
19141
19142@kindex info module
19143@cindex Fortran modules, information about
19144@cindex functions and variables by Fortran module
19145@cindex module functions and variables
19146@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19147@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19148List all functions or variables within all Fortran modules. The set
19149of functions or variables listed can be limited by providing some or
19150all of the optional regular expressions. If @var{module-regexp} is
19151provided, then only Fortran modules matching @var{module-regexp} will
19152be searched. Only functions or variables whose type matches the
19153optional regular expression @var{type-regexp} will be listed. And
19154only functions or variables whose name matches the optional regular
19155expression @var{regexp} will be listed.
19156
19157The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19158printing header information and messages explaining why no functions
19159or variables have been printed.
59c35742 19160
b37303ee 19161@kindex info classes
721c2651 19162@cindex Objective-C, classes and selectors
b37303ee
AF
19163@item info classes
19164@itemx info classes @var{regexp}
19165Display all Objective-C classes in your program, or
19166(with the @var{regexp} argument) all those matching a particular regular
19167expression.
19168
19169@kindex info selectors
19170@item info selectors
19171@itemx info selectors @var{regexp}
19172Display all Objective-C selectors in your program, or
19173(with the @var{regexp} argument) all those matching a particular regular
19174expression.
19175
c906108c
SS
19176@ignore
19177This was never implemented.
19178@kindex info methods
19179@item info methods
19180@itemx info methods @var{regexp}
19181The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19182methods within C@t{++} program, or (with the @var{regexp} argument) a
19183specific set of methods found in the various C@t{++} classes. Many
19184C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19185from the @code{ptype} command can be overwhelming and hard to use. The
19186@code{info-methods} command filters the methods, printing only those
19187which match the regular-expression @var{regexp}.
19188@end ignore
19189
9c16f35a 19190@cindex opaque data types
c906108c
SS
19191@kindex set opaque-type-resolution
19192@item set opaque-type-resolution on
19193Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19194declared as a pointer to a @code{struct}, @code{class}, or
19195@code{union}---for example, @code{struct MyType *}---that is used in one
19196source file although the full declaration of @code{struct MyType} is in
19197another source file. The default is on.
19198
19199A change in the setting of this subcommand will not take effect until
19200the next time symbols for a file are loaded.
19201
19202@item set opaque-type-resolution off
19203Tell @value{GDBN} not to resolve opaque types. In this case, the type
19204is printed as follows:
19205@smallexample
19206@{<no data fields>@}
19207@end smallexample
19208
19209@kindex show opaque-type-resolution
19210@item show opaque-type-resolution
19211Show whether opaque types are resolved or not.
c906108c 19212
770e7fc7
DE
19213@kindex set print symbol-loading
19214@cindex print messages when symbols are loaded
19215@item set print symbol-loading
19216@itemx set print symbol-loading full
19217@itemx set print symbol-loading brief
19218@itemx set print symbol-loading off
19219The @code{set print symbol-loading} command allows you to control the
19220printing of messages when @value{GDBN} loads symbol information.
19221By default a message is printed for the executable and one for each
19222shared library, and normally this is what you want. However, when
19223debugging apps with large numbers of shared libraries these messages
19224can be annoying.
19225When set to @code{brief} a message is printed for each executable,
19226and when @value{GDBN} loads a collection of shared libraries at once
19227it will only print one message regardless of the number of shared
19228libraries. When set to @code{off} no messages are printed.
19229
19230@kindex show print symbol-loading
19231@item show print symbol-loading
19232Show whether messages will be printed when a @value{GDBN} command
19233entered from the keyboard causes symbol information to be loaded.
19234
c906108c
SS
19235@kindex maint print symbols
19236@cindex symbol dump
19237@kindex maint print psymbols
19238@cindex partial symbol dump
7c57fa1e
YQ
19239@kindex maint print msymbols
19240@cindex minimal symbol dump
34c41c68
DE
19241@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19242@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19243@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19244@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19245@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19246Write a dump of debugging symbol data into the file @var{filename} or
19247the terminal if @var{filename} is unspecified.
19248If @code{-objfile @var{objfile}} is specified, only dump symbols for
19249that objfile.
19250If @code{-pc @var{address}} is specified, only dump symbols for the file
19251with code at that address. Note that @var{address} may be a symbol like
19252@code{main}.
19253If @code{-source @var{source}} is specified, only dump symbols for that
19254source file.
19255
19256These commands are used to debug the @value{GDBN} symbol-reading code.
19257These commands do not modify internal @value{GDBN} state, therefore
19258@samp{maint print symbols} will only print symbols for already expanded symbol
19259tables.
19260You can use the command @code{info sources} to find out which files these are.
19261If you use @samp{maint print psymbols} instead, the dump shows information
19262about symbols that @value{GDBN} only knows partially---that is, symbols
19263defined in files that @value{GDBN} has skimmed, but not yet read completely.
19264Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19265``ELF symbols''.
19266
79a6e687 19267@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19268@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19269
5e7b2f39
JB
19270@kindex maint info symtabs
19271@kindex maint info psymtabs
44ea7b70
JB
19272@cindex listing @value{GDBN}'s internal symbol tables
19273@cindex symbol tables, listing @value{GDBN}'s internal
19274@cindex full symbol tables, listing @value{GDBN}'s internal
19275@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19276@item maint info symtabs @r{[} @var{regexp} @r{]}
19277@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19278
19279List the @code{struct symtab} or @code{struct partial_symtab}
19280structures whose names match @var{regexp}. If @var{regexp} is not
19281given, list them all. The output includes expressions which you can
19282copy into a @value{GDBN} debugging this one to examine a particular
19283structure in more detail. For example:
19284
19285@smallexample
5e7b2f39 19286(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19287@{ objfile /home/gnu/build/gdb/gdb
19288 ((struct objfile *) 0x82e69d0)
b383017d 19289 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19290 ((struct partial_symtab *) 0x8474b10)
19291 readin no
19292 fullname (null)
19293 text addresses 0x814d3c8 -- 0x8158074
19294 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19295 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19296 dependencies (none)
19297 @}
19298@}
5e7b2f39 19299(@value{GDBP}) maint info symtabs
44ea7b70
JB
19300(@value{GDBP})
19301@end smallexample
19302@noindent
19303We see that there is one partial symbol table whose filename contains
19304the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19305and we see that @value{GDBN} has not read in any symtabs yet at all.
19306If we set a breakpoint on a function, that will cause @value{GDBN} to
19307read the symtab for the compilation unit containing that function:
19308
19309@smallexample
19310(@value{GDBP}) break dwarf2_psymtab_to_symtab
19311Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19312line 1574.
5e7b2f39 19313(@value{GDBP}) maint info symtabs
b383017d 19314@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19315 ((struct objfile *) 0x82e69d0)
b383017d 19316 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19317 ((struct symtab *) 0x86c1f38)
19318 dirname (null)
19319 fullname (null)
19320 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19321 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19322 debugformat DWARF 2
19323 @}
19324@}
b383017d 19325(@value{GDBP})
44ea7b70 19326@end smallexample
44ea7b70 19327
f2403c39
AB
19328@kindex maint info line-table
19329@cindex listing @value{GDBN}'s internal line tables
19330@cindex line tables, listing @value{GDBN}'s internal
19331@item maint info line-table @r{[} @var{regexp} @r{]}
19332
19333List the @code{struct linetable} from all @code{struct symtab}
19334instances whose name matches @var{regexp}. If @var{regexp} is not
19335given, list the @code{struct linetable} from all @code{struct symtab}.
19336
f57d2163
DE
19337@kindex maint set symbol-cache-size
19338@cindex symbol cache size
19339@item maint set symbol-cache-size @var{size}
19340Set the size of the symbol cache to @var{size}.
19341The default size is intended to be good enough for debugging
19342most applications. This option exists to allow for experimenting
19343with different sizes.
19344
19345@kindex maint show symbol-cache-size
19346@item maint show symbol-cache-size
19347Show the size of the symbol cache.
19348
19349@kindex maint print symbol-cache
19350@cindex symbol cache, printing its contents
19351@item maint print symbol-cache
19352Print the contents of the symbol cache.
19353This is useful when debugging symbol cache issues.
19354
19355@kindex maint print symbol-cache-statistics
19356@cindex symbol cache, printing usage statistics
19357@item maint print symbol-cache-statistics
19358Print symbol cache usage statistics.
19359This helps determine how well the cache is being utilized.
19360
19361@kindex maint flush-symbol-cache
19362@cindex symbol cache, flushing
19363@item maint flush-symbol-cache
19364Flush the contents of the symbol cache, all entries are removed.
19365This command is useful when debugging the symbol cache.
19366It is also useful when collecting performance data.
19367
19368@end table
6a3ca067 19369
6d2ebf8b 19370@node Altering
c906108c
SS
19371@chapter Altering Execution
19372
19373Once you think you have found an error in your program, you might want to
19374find out for certain whether correcting the apparent error would lead to
19375correct results in the rest of the run. You can find the answer by
19376experiment, using the @value{GDBN} features for altering execution of the
19377program.
19378
19379For example, you can store new values into variables or memory
7a292a7a
SS
19380locations, give your program a signal, restart it at a different
19381address, or even return prematurely from a function.
c906108c
SS
19382
19383@menu
19384* Assignment:: Assignment to variables
19385* Jumping:: Continuing at a different address
c906108c 19386* Signaling:: Giving your program a signal
c906108c
SS
19387* Returning:: Returning from a function
19388* Calling:: Calling your program's functions
19389* Patching:: Patching your program
bb2ec1b3 19390* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19391@end menu
19392
6d2ebf8b 19393@node Assignment
79a6e687 19394@section Assignment to Variables
c906108c
SS
19395
19396@cindex assignment
19397@cindex setting variables
19398To alter the value of a variable, evaluate an assignment expression.
19399@xref{Expressions, ,Expressions}. For example,
19400
474c8240 19401@smallexample
c906108c 19402print x=4
474c8240 19403@end smallexample
c906108c
SS
19404
19405@noindent
19406stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19407value of the assignment expression (which is 4).
c906108c
SS
19408@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19409information on operators in supported languages.
c906108c
SS
19410
19411@kindex set variable
19412@cindex variables, setting
19413If you are not interested in seeing the value of the assignment, use the
19414@code{set} command instead of the @code{print} command. @code{set} is
19415really the same as @code{print} except that the expression's value is
19416not printed and is not put in the value history (@pxref{Value History,
79a6e687 19417,Value History}). The expression is evaluated only for its effects.
c906108c 19418
c906108c
SS
19419If the beginning of the argument string of the @code{set} command
19420appears identical to a @code{set} subcommand, use the @code{set
19421variable} command instead of just @code{set}. This command is identical
19422to @code{set} except for its lack of subcommands. For example, if your
19423program has a variable @code{width}, you get an error if you try to set
19424a new value with just @samp{set width=13}, because @value{GDBN} has the
19425command @code{set width}:
19426
474c8240 19427@smallexample
c906108c
SS
19428(@value{GDBP}) whatis width
19429type = double
19430(@value{GDBP}) p width
19431$4 = 13
19432(@value{GDBP}) set width=47
19433Invalid syntax in expression.
474c8240 19434@end smallexample
c906108c
SS
19435
19436@noindent
19437The invalid expression, of course, is @samp{=47}. In
19438order to actually set the program's variable @code{width}, use
19439
474c8240 19440@smallexample
c906108c 19441(@value{GDBP}) set var width=47
474c8240 19442@end smallexample
53a5351d 19443
c906108c
SS
19444Because the @code{set} command has many subcommands that can conflict
19445with the names of program variables, it is a good idea to use the
19446@code{set variable} command instead of just @code{set}. For example, if
19447your program has a variable @code{g}, you run into problems if you try
19448to set a new value with just @samp{set g=4}, because @value{GDBN} has
19449the command @code{set gnutarget}, abbreviated @code{set g}:
19450
474c8240 19451@smallexample
c906108c
SS
19452@group
19453(@value{GDBP}) whatis g
19454type = double
19455(@value{GDBP}) p g
19456$1 = 1
19457(@value{GDBP}) set g=4
2df3850c 19458(@value{GDBP}) p g
c906108c
SS
19459$2 = 1
19460(@value{GDBP}) r
19461The program being debugged has been started already.
19462Start it from the beginning? (y or n) y
19463Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19464"/home/smith/cc_progs/a.out": can't open to read symbols:
19465 Invalid bfd target.
c906108c
SS
19466(@value{GDBP}) show g
19467The current BFD target is "=4".
19468@end group
474c8240 19469@end smallexample
c906108c
SS
19470
19471@noindent
19472The program variable @code{g} did not change, and you silently set the
19473@code{gnutarget} to an invalid value. In order to set the variable
19474@code{g}, use
19475
474c8240 19476@smallexample
c906108c 19477(@value{GDBP}) set var g=4
474c8240 19478@end smallexample
c906108c
SS
19479
19480@value{GDBN} allows more implicit conversions in assignments than C; you can
19481freely store an integer value into a pointer variable or vice versa,
19482and you can convert any structure to any other structure that is the
19483same length or shorter.
19484@comment FIXME: how do structs align/pad in these conversions?
19485@comment /doc@cygnus.com 18dec1990
19486
19487To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19488construct to generate a value of specified type at a specified address
19489(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19490to memory location @code{0x83040} as an integer (which implies a certain size
19491and representation in memory), and
19492
474c8240 19493@smallexample
c906108c 19494set @{int@}0x83040 = 4
474c8240 19495@end smallexample
c906108c
SS
19496
19497@noindent
19498stores the value 4 into that memory location.
19499
6d2ebf8b 19500@node Jumping
79a6e687 19501@section Continuing at a Different Address
c906108c
SS
19502
19503Ordinarily, when you continue your program, you do so at the place where
19504it stopped, with the @code{continue} command. You can instead continue at
19505an address of your own choosing, with the following commands:
19506
19507@table @code
19508@kindex jump
c1d780c2 19509@kindex j @r{(@code{jump})}
629500fa 19510@item jump @var{location}
c1d780c2 19511@itemx j @var{location}
629500fa
KS
19512Resume execution at @var{location}. Execution stops again immediately
19513if there is a breakpoint there. @xref{Specify Location}, for a description
19514of the different forms of @var{location}. It is common
2a25a5ba
EZ
19515practice to use the @code{tbreak} command in conjunction with
19516@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19517
19518The @code{jump} command does not change the current stack frame, or
19519the stack pointer, or the contents of any memory location or any
629500fa 19520register other than the program counter. If @var{location} is in
c906108c
SS
19521a different function from the one currently executing, the results may
19522be bizarre if the two functions expect different patterns of arguments or
19523of local variables. For this reason, the @code{jump} command requests
19524confirmation if the specified line is not in the function currently
19525executing. However, even bizarre results are predictable if you are
19526well acquainted with the machine-language code of your program.
c906108c
SS
19527@end table
19528
53a5351d
JM
19529On many systems, you can get much the same effect as the @code{jump}
19530command by storing a new value into the register @code{$pc}. The
19531difference is that this does not start your program running; it only
19532changes the address of where it @emph{will} run when you continue. For
19533example,
c906108c 19534
474c8240 19535@smallexample
c906108c 19536set $pc = 0x485
474c8240 19537@end smallexample
c906108c
SS
19538
19539@noindent
19540makes the next @code{continue} command or stepping command execute at
19541address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19542@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19543
19544The most common occasion to use the @code{jump} command is to back
19545up---perhaps with more breakpoints set---over a portion of a program
19546that has already executed, in order to examine its execution in more
19547detail.
19548
c906108c 19549@c @group
6d2ebf8b 19550@node Signaling
79a6e687 19551@section Giving your Program a Signal
9c16f35a 19552@cindex deliver a signal to a program
c906108c
SS
19553
19554@table @code
19555@kindex signal
19556@item signal @var{signal}
70509625 19557Resume execution where your program is stopped, but immediately give it the
697aa1b7 19558signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19559signal. For example, on many systems @code{signal 2} and @code{signal
19560SIGINT} are both ways of sending an interrupt signal.
19561
19562Alternatively, if @var{signal} is zero, continue execution without
19563giving a signal. This is useful when your program stopped on account of
ae606bee 19564a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19565@code{continue} command; @samp{signal 0} causes it to resume without a
19566signal.
19567
70509625
PA
19568@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19569delivered to the currently selected thread, not the thread that last
19570reported a stop. This includes the situation where a thread was
19571stopped due to a signal. So if you want to continue execution
19572suppressing the signal that stopped a thread, you should select that
19573same thread before issuing the @samp{signal 0} command. If you issue
19574the @samp{signal 0} command with another thread as the selected one,
19575@value{GDBN} detects that and asks for confirmation.
19576
c906108c
SS
19577Invoking the @code{signal} command is not the same as invoking the
19578@code{kill} utility from the shell. Sending a signal with @code{kill}
19579causes @value{GDBN} to decide what to do with the signal depending on
19580the signal handling tables (@pxref{Signals}). The @code{signal} command
19581passes the signal directly to your program.
19582
81219e53
DE
19583@code{signal} does not repeat when you press @key{RET} a second time
19584after executing the command.
19585
19586@kindex queue-signal
19587@item queue-signal @var{signal}
19588Queue @var{signal} to be delivered immediately to the current thread
19589when execution of the thread resumes. The @var{signal} can be the name or
19590the number of a signal. For example, on many systems @code{signal 2} and
19591@code{signal SIGINT} are both ways of sending an interrupt signal.
19592The handling of the signal must be set to pass the signal to the program,
19593otherwise @value{GDBN} will report an error.
19594You can control the handling of signals from @value{GDBN} with the
19595@code{handle} command (@pxref{Signals}).
19596
19597Alternatively, if @var{signal} is zero, any currently queued signal
19598for the current thread is discarded and when execution resumes no signal
19599will be delivered. This is useful when your program stopped on account
19600of a signal and would ordinarily see the signal when resumed with the
19601@code{continue} command.
19602
19603This command differs from the @code{signal} command in that the signal
19604is just queued, execution is not resumed. And @code{queue-signal} cannot
19605be used to pass a signal whose handling state has been set to @code{nopass}
19606(@pxref{Signals}).
19607@end table
19608@c @end group
c906108c 19609
e5f8a7cc
PA
19610@xref{stepping into signal handlers}, for information on how stepping
19611commands behave when the thread has a signal queued.
19612
6d2ebf8b 19613@node Returning
79a6e687 19614@section Returning from a Function
c906108c
SS
19615
19616@table @code
19617@cindex returning from a function
19618@kindex return
19619@item return
19620@itemx return @var{expression}
19621You can cancel execution of a function call with the @code{return}
19622command. If you give an
19623@var{expression} argument, its value is used as the function's return
19624value.
19625@end table
19626
19627When you use @code{return}, @value{GDBN} discards the selected stack frame
19628(and all frames within it). You can think of this as making the
19629discarded frame return prematurely. If you wish to specify a value to
19630be returned, give that value as the argument to @code{return}.
19631
19632This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19633Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19634innermost remaining frame. That frame becomes selected. The
19635specified value is stored in the registers used for returning values
19636of functions.
19637
19638The @code{return} command does not resume execution; it leaves the
19639program stopped in the state that would exist if the function had just
19640returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19641and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19642selected stack frame returns naturally.
19643
61ff14c6
JK
19644@value{GDBN} needs to know how the @var{expression} argument should be set for
19645the inferior. The concrete registers assignment depends on the OS ABI and the
19646type being returned by the selected stack frame. For example it is common for
19647OS ABI to return floating point values in FPU registers while integer values in
19648CPU registers. Still some ABIs return even floating point values in CPU
19649registers. Larger integer widths (such as @code{long long int}) also have
19650specific placement rules. @value{GDBN} already knows the OS ABI from its
19651current target so it needs to find out also the type being returned to make the
19652assignment into the right register(s).
19653
19654Normally, the selected stack frame has debug info. @value{GDBN} will always
19655use the debug info instead of the implicit type of @var{expression} when the
19656debug info is available. For example, if you type @kbd{return -1}, and the
19657function in the current stack frame is declared to return a @code{long long
19658int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19659into a @code{long long int}:
19660
19661@smallexample
19662Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1966329 return 31;
19664(@value{GDBP}) return -1
19665Make func return now? (y or n) y
19666#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1966743 printf ("result=%lld\n", func ());
19668(@value{GDBP})
19669@end smallexample
19670
19671However, if the selected stack frame does not have a debug info, e.g., if the
19672function was compiled without debug info, @value{GDBN} has to find out the type
19673to return from user. Specifying a different type by mistake may set the value
19674in different inferior registers than the caller code expects. For example,
19675typing @kbd{return -1} with its implicit type @code{int} would set only a part
19676of a @code{long long int} result for a debug info less function (on 32-bit
19677architectures). Therefore the user is required to specify the return type by
19678an appropriate cast explicitly:
19679
19680@smallexample
19681Breakpoint 2, 0x0040050b in func ()
19682(@value{GDBP}) return -1
19683Return value type not available for selected stack frame.
19684Please use an explicit cast of the value to return.
19685(@value{GDBP}) return (long long int) -1
19686Make selected stack frame return now? (y or n) y
19687#0 0x00400526 in main ()
19688(@value{GDBP})
19689@end smallexample
19690
6d2ebf8b 19691@node Calling
79a6e687 19692@section Calling Program Functions
c906108c 19693
f8568604 19694@table @code
c906108c 19695@cindex calling functions
f8568604
EZ
19696@cindex inferior functions, calling
19697@item print @var{expr}
d3e8051b 19698Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19699The expression may include calls to functions in the program being
f8568604
EZ
19700debugged.
19701
c906108c 19702@kindex call
c906108c
SS
19703@item call @var{expr}
19704Evaluate the expression @var{expr} without displaying @code{void}
19705returned values.
c906108c
SS
19706
19707You can use this variant of the @code{print} command if you want to
f8568604
EZ
19708execute a function from your program that does not return anything
19709(a.k.a.@: @dfn{a void function}), but without cluttering the output
19710with @code{void} returned values that @value{GDBN} will otherwise
19711print. If the result is not void, it is printed and saved in the
19712value history.
19713@end table
19714
9c16f35a
EZ
19715It is possible for the function you call via the @code{print} or
19716@code{call} command to generate a signal (e.g., if there's a bug in
19717the function, or if you passed it incorrect arguments). What happens
19718in that case is controlled by the @code{set unwindonsignal} command.
19719
7cd1089b
PM
19720Similarly, with a C@t{++} program it is possible for the function you
19721call via the @code{print} or @code{call} command to generate an
19722exception that is not handled due to the constraints of the dummy
19723frame. In this case, any exception that is raised in the frame, but has
19724an out-of-frame exception handler will not be found. GDB builds a
19725dummy-frame for the inferior function call, and the unwinder cannot
19726seek for exception handlers outside of this dummy-frame. What happens
19727in that case is controlled by the
19728@code{set unwind-on-terminating-exception} command.
19729
9c16f35a
EZ
19730@table @code
19731@item set unwindonsignal
19732@kindex set unwindonsignal
19733@cindex unwind stack in called functions
19734@cindex call dummy stack unwinding
19735Set unwinding of the stack if a signal is received while in a function
19736that @value{GDBN} called in the program being debugged. If set to on,
19737@value{GDBN} unwinds the stack it created for the call and restores
19738the context to what it was before the call. If set to off (the
19739default), @value{GDBN} stops in the frame where the signal was
19740received.
19741
19742@item show unwindonsignal
19743@kindex show unwindonsignal
19744Show the current setting of stack unwinding in the functions called by
19745@value{GDBN}.
7cd1089b
PM
19746
19747@item set unwind-on-terminating-exception
19748@kindex set unwind-on-terminating-exception
19749@cindex unwind stack in called functions with unhandled exceptions
19750@cindex call dummy stack unwinding on unhandled exception.
19751Set unwinding of the stack if a C@t{++} exception is raised, but left
19752unhandled while in a function that @value{GDBN} called in the program being
19753debugged. If set to on (the default), @value{GDBN} unwinds the stack
19754it created for the call and restores the context to what it was before
19755the call. If set to off, @value{GDBN} the exception is delivered to
19756the default C@t{++} exception handler and the inferior terminated.
19757
19758@item show unwind-on-terminating-exception
19759@kindex show unwind-on-terminating-exception
19760Show the current setting of stack unwinding in the functions called by
19761@value{GDBN}.
19762
136afab8
PW
19763@item set may-call-functions
19764@kindex set may-call-functions
19765@cindex disabling calling functions in the program
19766@cindex calling functions in the program, disabling
19767Set permission to call functions in the program.
19768This controls whether @value{GDBN} will attempt to call functions in
19769the program, such as with expressions in the @code{print} command. It
19770defaults to @code{on}.
19771
19772To call a function in the program, @value{GDBN} has to temporarily
19773modify the state of the inferior. This has potentially undesired side
19774effects. Also, having @value{GDBN} call nested functions is likely to
19775be erroneous and may even crash the program being debugged. You can
19776avoid such hazards by forbidding @value{GDBN} from calling functions
19777in the program being debugged. If calling functions in the program
19778is forbidden, GDB will throw an error when a command (such as printing
19779an expression) starts a function call in the program.
19780
19781@item show may-call-functions
19782@kindex show may-call-functions
19783Show permission to call functions in the program.
19784
9c16f35a
EZ
19785@end table
19786
d69cf9b2
PA
19787@subsection Calling functions with no debug info
19788
19789@cindex no debug info functions
19790Sometimes, a function you wish to call is missing debug information.
19791In such case, @value{GDBN} does not know the type of the function,
19792including the types of the function's parameters. To avoid calling
19793the inferior function incorrectly, which could result in the called
19794function functioning erroneously and even crash, @value{GDBN} refuses
19795to call the function unless you tell it the type of the function.
19796
19797For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19798to do that. The simplest is to cast the call to the function's
19799declared return type. For example:
19800
19801@smallexample
19802(@value{GDBP}) p getenv ("PATH")
19803'getenv' has unknown return type; cast the call to its declared return type
19804(@value{GDBP}) p (char *) getenv ("PATH")
19805$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19806@end smallexample
19807
19808Casting the return type of a no-debug function is equivalent to
19809casting the function to a pointer to a prototyped function that has a
19810prototype that matches the types of the passed-in arguments, and
19811calling that. I.e., the call above is equivalent to:
19812
19813@smallexample
19814(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19815@end smallexample
19816
19817@noindent
19818and given this prototyped C or C++ function with float parameters:
19819
19820@smallexample
19821float multiply (float v1, float v2) @{ return v1 * v2; @}
19822@end smallexample
19823
19824@noindent
19825these calls are equivalent:
19826
19827@smallexample
19828(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19829(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19830@end smallexample
19831
19832If the function you wish to call is declared as unprototyped (i.e.@:
19833old K&R style), you must use the cast-to-function-pointer syntax, so
19834that @value{GDBN} knows that it needs to apply default argument
19835promotions (promote float arguments to double). @xref{ABI, float
19836promotion}. For example, given this unprototyped C function with
19837float parameters, and no debug info:
19838
19839@smallexample
19840float
19841multiply_noproto (v1, v2)
19842 float v1, v2;
19843@{
19844 return v1 * v2;
19845@}
19846@end smallexample
19847
19848@noindent
19849you call it like this:
19850
19851@smallexample
19852 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19853@end smallexample
c906108c 19854
6d2ebf8b 19855@node Patching
79a6e687 19856@section Patching Programs
7a292a7a 19857
c906108c
SS
19858@cindex patching binaries
19859@cindex writing into executables
c906108c 19860@cindex writing into corefiles
c906108c 19861
7a292a7a
SS
19862By default, @value{GDBN} opens the file containing your program's
19863executable code (or the corefile) read-only. This prevents accidental
19864alterations to machine code; but it also prevents you from intentionally
19865patching your program's binary.
c906108c
SS
19866
19867If you'd like to be able to patch the binary, you can specify that
19868explicitly with the @code{set write} command. For example, you might
19869want to turn on internal debugging flags, or even to make emergency
19870repairs.
19871
19872@table @code
19873@kindex set write
19874@item set write on
19875@itemx set write off
7a292a7a 19876If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 19877core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
19878off} (the default), @value{GDBN} opens them read-only.
19879
19880If you have already loaded a file, you must load it again (using the
7a292a7a
SS
19881@code{exec-file} or @code{core-file} command) after changing @code{set
19882write}, for your new setting to take effect.
c906108c
SS
19883
19884@item show write
19885@kindex show write
7a292a7a
SS
19886Display whether executable files and core files are opened for writing
19887as well as reading.
c906108c
SS
19888@end table
19889
bb2ec1b3
TT
19890@node Compiling and Injecting Code
19891@section Compiling and injecting code in @value{GDBN}
19892@cindex injecting code
19893@cindex writing into executables
19894@cindex compiling code
19895
19896@value{GDBN} supports on-demand compilation and code injection into
19897programs running under @value{GDBN}. GCC 5.0 or higher built with
19898@file{libcc1.so} must be installed for this functionality to be enabled.
19899This functionality is implemented with the following commands.
19900
19901@table @code
19902@kindex compile code
19903@item compile code @var{source-code}
19904@itemx compile code -raw @var{--} @var{source-code}
19905Compile @var{source-code} with the compiler language found as the current
19906language in @value{GDBN} (@pxref{Languages}). If compilation and
19907injection is not supported with the current language specified in
19908@value{GDBN}, or the compiler does not support this feature, an error
19909message will be printed. If @var{source-code} compiles and links
19910successfully, @value{GDBN} will load the object-code emitted,
19911and execute it within the context of the currently selected inferior.
19912It is important to note that the compiled code is executed immediately.
19913After execution, the compiled code is removed from @value{GDBN} and any
19914new types or variables you have defined will be deleted.
19915
19916The command allows you to specify @var{source-code} in two ways.
19917The simplest method is to provide a single line of code to the command.
19918E.g.:
19919
19920@smallexample
19921compile code printf ("hello world\n");
19922@end smallexample
19923
19924If you specify options on the command line as well as source code, they
19925may conflict. The @samp{--} delimiter can be used to separate options
19926from actual source code. E.g.:
19927
19928@smallexample
19929compile code -r -- printf ("hello world\n");
19930@end smallexample
19931
19932Alternatively you can enter source code as multiple lines of text. To
19933enter this mode, invoke the @samp{compile code} command without any text
19934following the command. This will start the multiple-line editor and
19935allow you to type as many lines of source code as required. When you
19936have completed typing, enter @samp{end} on its own line to exit the
19937editor.
19938
19939@smallexample
19940compile code
19941>printf ("hello\n");
19942>printf ("world\n");
19943>end
19944@end smallexample
19945
19946Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19947provided @var{source-code} in a callable scope. In this case, you must
19948specify the entry point of the code by defining a function named
19949@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19950inferior. Using @samp{-raw} option may be needed for example when
19951@var{source-code} requires @samp{#include} lines which may conflict with
19952inferior symbols otherwise.
19953
19954@kindex compile file
19955@item compile file @var{filename}
19956@itemx compile file -raw @var{filename}
19957Like @code{compile code}, but take the source code from @var{filename}.
19958
19959@smallexample
19960compile file /home/user/example.c
19961@end smallexample
19962@end table
19963
36de76f9 19964@table @code
3345721a
PA
19965@item compile print [[@var{options}] --] @var{expr}
19966@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
19967Compile and execute @var{expr} with the compiler language found as the
19968current language in @value{GDBN} (@pxref{Languages}). By default the
19969value of @var{expr} is printed in a format appropriate to its data type;
19970you can choose a different format by specifying @samp{/@var{f}}, where
19971@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
19972Formats}. The @code{compile print} command accepts the same options
19973as the @code{print} command; see @ref{print options}.
36de76f9 19974
3345721a
PA
19975@item compile print [[@var{options}] --]
19976@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
19977@cindex reprint the last value
19978Alternatively you can enter the expression (source code producing it) as
19979multiple lines of text. To enter this mode, invoke the @samp{compile print}
19980command without any text following the command. This will start the
19981multiple-line editor.
19982@end table
19983
e7a8570f
JK
19984@noindent
19985The process of compiling and injecting the code can be inspected using:
19986
19987@table @code
19988@anchor{set debug compile}
19989@item set debug compile
19990@cindex compile command debugging info
19991Turns on or off display of @value{GDBN} process of compiling and
19992injecting the code. The default is off.
19993
19994@item show debug compile
19995Displays the current state of displaying @value{GDBN} process of
19996compiling and injecting the code.
078a0207
KS
19997
19998@anchor{set debug compile-cplus-types}
19999@item set debug compile-cplus-types
20000@cindex compile C@t{++} type conversion
20001Turns on or off the display of C@t{++} type conversion debugging information.
20002The default is off.
20003
20004@item show debug compile-cplus-types
20005Displays the current state of displaying debugging information for
20006C@t{++} type conversion.
e7a8570f
JK
20007@end table
20008
20009@subsection Compilation options for the @code{compile} command
20010
20011@value{GDBN} needs to specify the right compilation options for the code
20012to be injected, in part to make its ABI compatible with the inferior
20013and in part to make the injected code compatible with @value{GDBN}'s
20014injecting process.
20015
20016@noindent
20017The options used, in increasing precedence:
20018
20019@table @asis
20020@item target architecture and OS options (@code{gdbarch})
20021These options depend on target processor type and target operating
20022system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20023(@code{-m64}) compilation option.
20024
20025@item compilation options recorded in the target
20026@value{NGCC} (since version 4.7) stores the options used for compilation
20027into @code{DW_AT_producer} part of DWARF debugging information according
20028to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20029explicitly specify @code{-g} during inferior compilation otherwise
20030@value{NGCC} produces no DWARF. This feature is only relevant for
20031platforms where @code{-g} produces DWARF by default, otherwise one may
20032try to enforce DWARF by using @code{-gdwarf-4}.
20033
20034@item compilation options set by @code{set compile-args}
20035@end table
20036
20037@noindent
20038You can override compilation options using the following command:
20039
20040@table @code
20041@item set compile-args
20042@cindex compile command options override
20043Set compilation options used for compiling and injecting code with the
20044@code{compile} commands. These options override any conflicting ones
20045from the target architecture and/or options stored during inferior
20046compilation.
20047
20048@item show compile-args
20049Displays the current state of compilation options override.
20050This does not show all the options actually used during compilation,
20051use @ref{set debug compile} for that.
20052@end table
20053
bb2ec1b3
TT
20054@subsection Caveats when using the @code{compile} command
20055
20056There are a few caveats to keep in mind when using the @code{compile}
20057command. As the caveats are different per language, the table below
20058highlights specific issues on a per language basis.
20059
20060@table @asis
20061@item C code examples and caveats
20062When the language in @value{GDBN} is set to @samp{C}, the compiler will
20063attempt to compile the source code with a @samp{C} compiler. The source
20064code provided to the @code{compile} command will have much the same
20065access to variables and types as it normally would if it were part of
20066the program currently being debugged in @value{GDBN}.
20067
20068Below is a sample program that forms the basis of the examples that
20069follow. This program has been compiled and loaded into @value{GDBN},
20070much like any other normal debugging session.
20071
20072@smallexample
20073void function1 (void)
20074@{
20075 int i = 42;
20076 printf ("function 1\n");
20077@}
20078
20079void function2 (void)
20080@{
20081 int j = 12;
20082 function1 ();
20083@}
20084
20085int main(void)
20086@{
20087 int k = 6;
20088 int *p;
20089 function2 ();
20090 return 0;
20091@}
20092@end smallexample
20093
20094For the purposes of the examples in this section, the program above has
20095been compiled, loaded into @value{GDBN}, stopped at the function
20096@code{main}, and @value{GDBN} is awaiting input from the user.
20097
20098To access variables and types for any program in @value{GDBN}, the
20099program must be compiled and packaged with debug information. The
20100@code{compile} command is not an exception to this rule. Without debug
20101information, you can still use the @code{compile} command, but you will
20102be very limited in what variables and types you can access.
20103
20104So with that in mind, the example above has been compiled with debug
20105information enabled. The @code{compile} command will have access to
20106all variables and types (except those that may have been optimized
20107out). Currently, as @value{GDBN} has stopped the program in the
20108@code{main} function, the @code{compile} command would have access to
20109the variable @code{k}. You could invoke the @code{compile} command
20110and type some source code to set the value of @code{k}. You can also
20111read it, or do anything with that variable you would normally do in
20112@code{C}. Be aware that changes to inferior variables in the
20113@code{compile} command are persistent. In the following example:
20114
20115@smallexample
20116compile code k = 3;
20117@end smallexample
20118
20119@noindent
20120the variable @code{k} is now 3. It will retain that value until
20121something else in the example program changes it, or another
20122@code{compile} command changes it.
20123
20124Normal scope and access rules apply to source code compiled and
20125injected by the @code{compile} command. In the example, the variables
20126@code{j} and @code{k} are not accessible yet, because the program is
20127currently stopped in the @code{main} function, where these variables
20128are not in scope. Therefore, the following command
20129
20130@smallexample
20131compile code j = 3;
20132@end smallexample
20133
20134@noindent
20135will result in a compilation error message.
20136
20137Once the program is continued, execution will bring these variables in
20138scope, and they will become accessible; then the code you specify via
20139the @code{compile} command will be able to access them.
20140
20141You can create variables and types with the @code{compile} command as
20142part of your source code. Variables and types that are created as part
20143of the @code{compile} command are not visible to the rest of the program for
20144the duration of its run. This example is valid:
20145
20146@smallexample
20147compile code int ff = 5; printf ("ff is %d\n", ff);
20148@end smallexample
20149
20150However, if you were to type the following into @value{GDBN} after that
20151command has completed:
20152
20153@smallexample
20154compile code printf ("ff is %d\n'', ff);
20155@end smallexample
20156
20157@noindent
20158a compiler error would be raised as the variable @code{ff} no longer
20159exists. Object code generated and injected by the @code{compile}
20160command is removed when its execution ends. Caution is advised
20161when assigning to program variables values of variables created by the
20162code submitted to the @code{compile} command. This example is valid:
20163
20164@smallexample
20165compile code int ff = 5; k = ff;
20166@end smallexample
20167
20168The value of the variable @code{ff} is assigned to @code{k}. The variable
20169@code{k} does not require the existence of @code{ff} to maintain the value
20170it has been assigned. However, pointers require particular care in
20171assignment. If the source code compiled with the @code{compile} command
20172changed the address of a pointer in the example program, perhaps to a
20173variable created in the @code{compile} command, that pointer would point
20174to an invalid location when the command exits. The following example
20175would likely cause issues with your debugged program:
20176
20177@smallexample
20178compile code int ff = 5; p = &ff;
20179@end smallexample
20180
20181In this example, @code{p} would point to @code{ff} when the
20182@code{compile} command is executing the source code provided to it.
20183However, as variables in the (example) program persist with their
20184assigned values, the variable @code{p} would point to an invalid
20185location when the command exists. A general rule should be followed
20186in that you should either assign @code{NULL} to any assigned pointers,
20187or restore a valid location to the pointer before the command exits.
20188
20189Similar caution must be exercised with any structs, unions, and typedefs
20190defined in @code{compile} command. Types defined in the @code{compile}
20191command will no longer be available in the next @code{compile} command.
20192Therefore, if you cast a variable to a type defined in the
20193@code{compile} command, care must be taken to ensure that any future
20194need to resolve the type can be achieved.
20195
20196@smallexample
20197(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20198(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20199gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20200Compilation failed.
20201(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2020242
20203@end smallexample
20204
20205Variables that have been optimized away by the compiler are not
20206accessible to the code submitted to the @code{compile} command.
20207Access to those variables will generate a compiler error which @value{GDBN}
20208will print to the console.
20209@end table
20210
e7a8570f
JK
20211@subsection Compiler search for the @code{compile} command
20212
6e41ddec
JK
20213@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20214which may not be obvious for remote targets of different architecture
20215than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20216@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20217target architecture and operating system. This search can be overriden
20218by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20219taken from shell that executed @value{GDBN}, it is not the value set by
20220@value{GDBN} command @code{set environment}). @xref{Environment}.
20221
e7a8570f
JK
20222
20223Specifically @code{PATH} is searched for binaries matching regular expression
20224@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20225debugged. @var{arch} is processor name --- multiarch is supported, so for
20226example both @code{i386} and @code{x86_64} targets look for pattern
20227@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20228for pattern @code{s390x?}. @var{os} is currently supported only for
20229pattern @code{linux(-gnu)?}.
20230
6e41ddec
JK
20231On Posix hosts the compiler driver @value{GDBN} needs to find also
20232shared library @file{libcc1.so} from the compiler. It is searched in
20233default shared library search path (overridable with usual environment
20234variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20235compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20236according to the installation of the found compiler --- as possibly
20237specified by the @code{set compile-gcc} command.
20238
20239@table @code
20240@item set compile-gcc
20241@cindex compile command driver filename override
20242Set compilation command used for compiling and injecting code with the
20243@code{compile} commands. If this option is not set (it is set to
20244an empty string), the search described above will occur --- that is the
20245default.
20246
20247@item show compile-gcc
20248Displays the current compile command @value{NGCC} driver filename.
20249If set, it is the main command @command{gcc}, found usually for example
20250under name @file{x86_64-linux-gnu-gcc}.
20251@end table
20252
6d2ebf8b 20253@node GDB Files
c906108c
SS
20254@chapter @value{GDBN} Files
20255
7a292a7a
SS
20256@value{GDBN} needs to know the file name of the program to be debugged,
20257both in order to read its symbol table and in order to start your
20258program. To debug a core dump of a previous run, you must also tell
20259@value{GDBN} the name of the core dump file.
c906108c
SS
20260
20261@menu
20262* Files:: Commands to specify files
2b4bf6af 20263* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20264* Separate Debug Files:: Debugging information in separate files
608e2dbb 20265* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20266* Index Files:: Index files speed up GDB
c906108c 20267* Symbol Errors:: Errors reading symbol files
b14b1491 20268* Data Files:: GDB data files
c906108c
SS
20269@end menu
20270
6d2ebf8b 20271@node Files
79a6e687 20272@section Commands to Specify Files
c906108c 20273
7a292a7a 20274@cindex symbol table
c906108c 20275@cindex core dump file
7a292a7a
SS
20276
20277You may want to specify executable and core dump file names. The usual
20278way to do this is at start-up time, using the arguments to
20279@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20280Out of @value{GDBN}}).
c906108c
SS
20281
20282Occasionally it is necessary to change to a different file during a
397ca115
EZ
20283@value{GDBN} session. Or you may run @value{GDBN} and forget to
20284specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20285via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20286Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20287new files are useful.
c906108c
SS
20288
20289@table @code
20290@cindex executable file
20291@kindex file
20292@item file @var{filename}
20293Use @var{filename} as the program to be debugged. It is read for its
20294symbols and for the contents of pure memory. It is also the program
20295executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20296directory and the file is not found in the @value{GDBN} working directory,
20297@value{GDBN} uses the environment variable @code{PATH} as a list of
20298directories to search, just as the shell does when looking for a program
20299to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20300and your program, using the @code{path} command.
20301
fc8be69e
EZ
20302@cindex unlinked object files
20303@cindex patching object files
20304You can load unlinked object @file{.o} files into @value{GDBN} using
20305the @code{file} command. You will not be able to ``run'' an object
20306file, but you can disassemble functions and inspect variables. Also,
20307if the underlying BFD functionality supports it, you could use
20308@kbd{gdb -write} to patch object files using this technique. Note
20309that @value{GDBN} can neither interpret nor modify relocations in this
20310case, so branches and some initialized variables will appear to go to
20311the wrong place. But this feature is still handy from time to time.
20312
c906108c
SS
20313@item file
20314@code{file} with no argument makes @value{GDBN} discard any information it
20315has on both executable file and the symbol table.
20316
20317@kindex exec-file
20318@item exec-file @r{[} @var{filename} @r{]}
20319Specify that the program to be run (but not the symbol table) is found
20320in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20321if necessary to locate your program. Omitting @var{filename} means to
20322discard information on the executable file.
20323
20324@kindex symbol-file
d4d429d5 20325@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20326Read symbol table information from file @var{filename}. @code{PATH} is
20327searched when necessary. Use the @code{file} command to get both symbol
20328table and program to run from the same file.
20329
d4d429d5
PT
20330If an optional @var{offset} is specified, it is added to the start
20331address of each section in the symbol file. This is useful if the
20332program is relocated at runtime, such as the Linux kernel with kASLR
20333enabled.
20334
c906108c
SS
20335@code{symbol-file} with no argument clears out @value{GDBN} information on your
20336program's symbol table.
20337
ae5a43e0
DJ
20338The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20339some breakpoints and auto-display expressions. This is because they may
20340contain pointers to the internal data recording symbols and data types,
20341which are part of the old symbol table data being discarded inside
20342@value{GDBN}.
c906108c
SS
20343
20344@code{symbol-file} does not repeat if you press @key{RET} again after
20345executing it once.
20346
20347When @value{GDBN} is configured for a particular environment, it
20348understands debugging information in whatever format is the standard
20349generated for that environment; you may use either a @sc{gnu} compiler, or
20350other compilers that adhere to the local conventions.
c906108c 20351Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20352using @code{@value{NGCC}} you can generate debugging information for
c906108c 20353optimized code.
c906108c
SS
20354
20355For most kinds of object files, with the exception of old SVR3 systems
20356using COFF, the @code{symbol-file} command does not normally read the
20357symbol table in full right away. Instead, it scans the symbol table
20358quickly to find which source files and which symbols are present. The
20359details are read later, one source file at a time, as they are needed.
20360
20361The purpose of this two-stage reading strategy is to make @value{GDBN}
20362start up faster. For the most part, it is invisible except for
20363occasional pauses while the symbol table details for a particular source
20364file are being read. (The @code{set verbose} command can turn these
20365pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20366Warnings and Messages}.)
c906108c 20367
c906108c
SS
20368We have not implemented the two-stage strategy for COFF yet. When the
20369symbol table is stored in COFF format, @code{symbol-file} reads the
20370symbol table data in full right away. Note that ``stabs-in-COFF''
20371still does the two-stage strategy, since the debug info is actually
20372in stabs format.
20373
20374@kindex readnow
20375@cindex reading symbols immediately
20376@cindex symbols, reading immediately
6ac33a4e
TT
20377@item symbol-file @r{[} -readnow @r{]} @var{filename}
20378@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20379You can override the @value{GDBN} two-stage strategy for reading symbol
20380tables by using the @samp{-readnow} option with any of the commands that
20381load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20382entire symbol table available.
c906108c 20383
97cbe998
SDJ
20384@cindex @code{-readnever}, option for symbol-file command
20385@cindex never read symbols
20386@cindex symbols, never read
20387@item symbol-file @r{[} -readnever @r{]} @var{filename}
20388@itemx file @r{[} -readnever @r{]} @var{filename}
20389You can instruct @value{GDBN} to never read the symbolic information
20390contained in @var{filename} by using the @samp{-readnever} option.
20391@xref{--readnever}.
20392
c906108c
SS
20393@c FIXME: for now no mention of directories, since this seems to be in
20394@c flux. 13mar1992 status is that in theory GDB would look either in
20395@c current dir or in same dir as myprog; but issues like competing
20396@c GDB's, or clutter in system dirs, mean that in practice right now
20397@c only current dir is used. FFish says maybe a special GDB hierarchy
20398@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20399@c files.
20400
c906108c 20401@kindex core-file
09d4efe1 20402@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20403@itemx core
c906108c
SS
20404Specify the whereabouts of a core dump file to be used as the ``contents
20405of memory''. Traditionally, core files contain only some parts of the
20406address space of the process that generated them; @value{GDBN} can access the
20407executable file itself for other parts.
20408
20409@code{core-file} with no argument specifies that no core file is
20410to be used.
20411
20412Note that the core file is ignored when your program is actually running
7a292a7a
SS
20413under @value{GDBN}. So, if you have been running your program and you
20414wish to debug a core file instead, you must kill the subprocess in which
20415the program is running. To do this, use the @code{kill} command
79a6e687 20416(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20417
c906108c
SS
20418@kindex add-symbol-file
20419@cindex dynamic linking
291f9a96 20420@item add-symbol-file @var{filename} @r{[} -readnow @r{|} -readnever @r{]} @r{[} -o @var{offset} @r{]} @r{[} @var{textaddress} @r{]} @r{[} -s @var{section} @var{address} @dots{} @r{]}
96a2c332
SS
20421The @code{add-symbol-file} command reads additional symbol table
20422information from the file @var{filename}. You would use this command
20423when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20424into the program that is running. The @var{textaddress} parameter gives
20425the memory address at which the file's text section has been loaded.
20426You can additionally specify the base address of other sections using
20427an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20428If a section is omitted, @value{GDBN} will use its default addresses
20429as found in @var{filename}. Any @var{address} or @var{textaddress}
20430can be given as an expression.
c906108c 20431
291f9a96
PT
20432If an optional @var{offset} is specified, it is added to the start
20433address of each section, except those for which the address was
20434specified explicitly.
20435
c906108c
SS
20436The symbol table of the file @var{filename} is added to the symbol table
20437originally read with the @code{symbol-file} command. You can use the
96a2c332 20438@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20439thus read is kept in addition to the old.
20440
20441Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20442
17d9d558
JB
20443@cindex relocatable object files, reading symbols from
20444@cindex object files, relocatable, reading symbols from
20445@cindex reading symbols from relocatable object files
20446@cindex symbols, reading from relocatable object files
20447@cindex @file{.o} files, reading symbols from
20448Although @var{filename} is typically a shared library file, an
20449executable file, or some other object file which has been fully
20450relocated for loading into a process, you can also load symbolic
20451information from relocatable @file{.o} files, as long as:
20452
20453@itemize @bullet
20454@item
20455the file's symbolic information refers only to linker symbols defined in
20456that file, not to symbols defined by other object files,
20457@item
20458every section the file's symbolic information refers to has actually
20459been loaded into the inferior, as it appears in the file, and
20460@item
20461you can determine the address at which every section was loaded, and
20462provide these to the @code{add-symbol-file} command.
20463@end itemize
20464
20465@noindent
20466Some embedded operating systems, like Sun Chorus and VxWorks, can load
20467relocatable files into an already running program; such systems
20468typically make the requirements above easy to meet. However, it's
20469important to recognize that many native systems use complex link
49efadf5 20470procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20471assembly, for example) that make the requirements difficult to meet. In
20472general, one cannot assume that using @code{add-symbol-file} to read a
20473relocatable object file's symbolic information will have the same effect
20474as linking the relocatable object file into the program in the normal
20475way.
20476
c906108c
SS
20477@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20478
98297bf6
NB
20479@kindex remove-symbol-file
20480@item remove-symbol-file @var{filename}
20481@item remove-symbol-file -a @var{address}
20482Remove a symbol file added via the @code{add-symbol-file} command. The
20483file to remove can be identified by its @var{filename} or by an @var{address}
20484that lies within the boundaries of this symbol file in memory. Example:
20485
20486@smallexample
20487(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20488add symbol table from file "/home/user/gdb/mylib.so" at
20489 .text_addr = 0x7ffff7ff9480
20490(y or n) y
0bab6cf1 20491Reading symbols from /home/user/gdb/mylib.so...
98297bf6
NB
20492(gdb) remove-symbol-file -a 0x7ffff7ff9480
20493Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20494(gdb)
20495@end smallexample
20496
20497
20498@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20499
c45da7e6
EZ
20500@kindex add-symbol-file-from-memory
20501@cindex @code{syscall DSO}
20502@cindex load symbols from memory
20503@item add-symbol-file-from-memory @var{address}
20504Load symbols from the given @var{address} in a dynamically loaded
20505object file whose image is mapped directly into the inferior's memory.
20506For example, the Linux kernel maps a @code{syscall DSO} into each
20507process's address space; this DSO provides kernel-specific code for
20508some system calls. The argument can be any expression whose
20509evaluation yields the address of the file's shared object file header.
20510For this command to work, you must have used @code{symbol-file} or
20511@code{exec-file} commands in advance.
20512
c906108c 20513@kindex section
09d4efe1
EZ
20514@item section @var{section} @var{addr}
20515The @code{section} command changes the base address of the named
20516@var{section} of the exec file to @var{addr}. This can be used if the
20517exec file does not contain section addresses, (such as in the
20518@code{a.out} format), or when the addresses specified in the file
20519itself are wrong. Each section must be changed separately. The
20520@code{info files} command, described below, lists all the sections and
20521their addresses.
c906108c
SS
20522
20523@kindex info files
20524@kindex info target
20525@item info files
20526@itemx info target
7a292a7a
SS
20527@code{info files} and @code{info target} are synonymous; both print the
20528current target (@pxref{Targets, ,Specifying a Debugging Target}),
20529including the names of the executable and core dump files currently in
20530use by @value{GDBN}, and the files from which symbols were loaded. The
20531command @code{help target} lists all possible targets rather than
20532current ones.
20533
fe95c787
MS
20534@kindex maint info sections
20535@item maint info sections
20536Another command that can give you extra information about program sections
20537is @code{maint info sections}. In addition to the section information
20538displayed by @code{info files}, this command displays the flags and file
20539offset of each section in the executable and core dump files. In addition,
20540@code{maint info sections} provides the following command options (which
20541may be arbitrarily combined):
20542
20543@table @code
20544@item ALLOBJ
20545Display sections for all loaded object files, including shared libraries.
20546@item @var{sections}
6600abed 20547Display info only for named @var{sections}.
fe95c787
MS
20548@item @var{section-flags}
20549Display info only for sections for which @var{section-flags} are true.
20550The section flags that @value{GDBN} currently knows about are:
20551@table @code
20552@item ALLOC
20553Section will have space allocated in the process when loaded.
20554Set for all sections except those containing debug information.
20555@item LOAD
20556Section will be loaded from the file into the child process memory.
20557Set for pre-initialized code and data, clear for @code{.bss} sections.
20558@item RELOC
20559Section needs to be relocated before loading.
20560@item READONLY
20561Section cannot be modified by the child process.
20562@item CODE
20563Section contains executable code only.
6600abed 20564@item DATA
fe95c787
MS
20565Section contains data only (no executable code).
20566@item ROM
20567Section will reside in ROM.
20568@item CONSTRUCTOR
20569Section contains data for constructor/destructor lists.
20570@item HAS_CONTENTS
20571Section is not empty.
20572@item NEVER_LOAD
20573An instruction to the linker to not output the section.
20574@item COFF_SHARED_LIBRARY
20575A notification to the linker that the section contains
20576COFF shared library information.
20577@item IS_COMMON
20578Section contains common symbols.
20579@end table
20580@end table
6763aef9 20581@kindex set trust-readonly-sections
9c16f35a 20582@cindex read-only sections
6763aef9
MS
20583@item set trust-readonly-sections on
20584Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20585really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20586In that case, @value{GDBN} can fetch values from these sections
20587out of the object file, rather than from the target program.
20588For some targets (notably embedded ones), this can be a significant
20589enhancement to debugging performance.
20590
20591The default is off.
20592
20593@item set trust-readonly-sections off
15110bc3 20594Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20595the contents of the section might change while the program is running,
20596and must therefore be fetched from the target when needed.
9c16f35a
EZ
20597
20598@item show trust-readonly-sections
20599Show the current setting of trusting readonly sections.
c906108c
SS
20600@end table
20601
20602All file-specifying commands allow both absolute and relative file names
20603as arguments. @value{GDBN} always converts the file name to an absolute file
20604name and remembers it that way.
20605
c906108c 20606@cindex shared libraries
9cceb671 20607@anchor{Shared Libraries}
b1236ac3
PA
20608@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20609Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20610DSBT (TIC6X) shared libraries.
53a5351d 20611
9cceb671
DJ
20612On MS-Windows @value{GDBN} must be linked with the Expat library to support
20613shared libraries. @xref{Expat}.
20614
c906108c
SS
20615@value{GDBN} automatically loads symbol definitions from shared libraries
20616when you use the @code{run} command, or when you examine a core file.
20617(Before you issue the @code{run} command, @value{GDBN} does not understand
20618references to a function in a shared library, however---unless you are
20619debugging a core file).
53a5351d 20620
c906108c
SS
20621@c FIXME: some @value{GDBN} release may permit some refs to undef
20622@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20623@c FIXME...lib; check this from time to time when updating manual
20624
b7209cb4
FF
20625There are times, however, when you may wish to not automatically load
20626symbol definitions from shared libraries, such as when they are
20627particularly large or there are many of them.
20628
20629To control the automatic loading of shared library symbols, use the
20630commands:
20631
20632@table @code
20633@kindex set auto-solib-add
20634@item set auto-solib-add @var{mode}
20635If @var{mode} is @code{on}, symbols from all shared object libraries
20636will be loaded automatically when the inferior begins execution, you
20637attach to an independently started inferior, or when the dynamic linker
20638informs @value{GDBN} that a new library has been loaded. If @var{mode}
20639is @code{off}, symbols must be loaded manually, using the
20640@code{sharedlibrary} command. The default value is @code{on}.
20641
dcaf7c2c
EZ
20642@cindex memory used for symbol tables
20643If your program uses lots of shared libraries with debug info that
20644takes large amounts of memory, you can decrease the @value{GDBN}
20645memory footprint by preventing it from automatically loading the
20646symbols from shared libraries. To that end, type @kbd{set
20647auto-solib-add off} before running the inferior, then load each
20648library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20649@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20650the libraries whose symbols you want to be loaded.
20651
b7209cb4
FF
20652@kindex show auto-solib-add
20653@item show auto-solib-add
20654Display the current autoloading mode.
20655@end table
20656
c45da7e6 20657@cindex load shared library
b7209cb4
FF
20658To explicitly load shared library symbols, use the @code{sharedlibrary}
20659command:
20660
c906108c
SS
20661@table @code
20662@kindex info sharedlibrary
20663@kindex info share
55333a84
DE
20664@item info share @var{regex}
20665@itemx info sharedlibrary @var{regex}
20666Print the names of the shared libraries which are currently loaded
20667that match @var{regex}. If @var{regex} is omitted then print
20668all shared libraries that are loaded.
c906108c 20669
b30a0bc3
JB
20670@kindex info dll
20671@item info dll @var{regex}
20672This is an alias of @code{info sharedlibrary}.
20673
c906108c
SS
20674@kindex sharedlibrary
20675@kindex share
20676@item sharedlibrary @var{regex}
20677@itemx share @var{regex}
c906108c
SS
20678Load shared object library symbols for files matching a
20679Unix regular expression.
20680As with files loaded automatically, it only loads shared libraries
20681required by your program for a core file or after typing @code{run}. If
20682@var{regex} is omitted all shared libraries required by your program are
20683loaded.
c45da7e6
EZ
20684
20685@item nosharedlibrary
20686@kindex nosharedlibrary
20687@cindex unload symbols from shared libraries
20688Unload all shared object library symbols. This discards all symbols
20689that have been loaded from all shared libraries. Symbols from shared
20690libraries that were loaded by explicit user requests are not
20691discarded.
c906108c
SS
20692@end table
20693
721c2651 20694Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20695when any of shared library events happen. The best way to do this is
20696to use @code{catch load} and @code{catch unload} (@pxref{Set
20697Catchpoints}).
20698
09f2921c 20699@value{GDBN} also supports the @code{set stop-on-solib-events}
edcc5120
TT
20700command for this. This command exists for historical reasons. It is
20701less useful than setting a catchpoint, because it does not allow for
20702conditions or commands as a catchpoint does.
721c2651
EZ
20703
20704@table @code
20705@item set stop-on-solib-events
20706@kindex set stop-on-solib-events
20707This command controls whether @value{GDBN} should give you control
20708when the dynamic linker notifies it about some shared library event.
20709The most common event of interest is loading or unloading of a new
20710shared library.
20711
20712@item show stop-on-solib-events
20713@kindex show stop-on-solib-events
20714Show whether @value{GDBN} stops and gives you control when shared
20715library events happen.
20716@end table
20717
f5ebfba0 20718Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20719configurations. @value{GDBN} needs to have access to the target's libraries;
20720this can be accomplished either by providing copies of the libraries
20721on the host system, or by asking @value{GDBN} to automatically retrieve the
20722libraries from the target. If copies of the target libraries are
20723provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20724copies on the target can be stripped as long as the copies on the host are
20725not.
20726
59b7b46f
EZ
20727@cindex where to look for shared libraries
20728For remote debugging, you need to tell @value{GDBN} where the target
20729libraries are, so that it can load the correct copies---otherwise, it
20730may try to load the host's libraries. @value{GDBN} has two variables
20731to specify the search directories for target libraries.
f5ebfba0
DJ
20732
20733@table @code
a9a5a3d1 20734@cindex prefix for executable and shared library file names
f822c95b 20735@cindex system root, alternate
f5ebfba0 20736@kindex set solib-absolute-prefix
f822c95b
DJ
20737@kindex set sysroot
20738@item set sysroot @var{path}
20739Use @var{path} as the system root for the program being debugged. Any
20740absolute shared library paths will be prefixed with @var{path}; many
20741runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20742target program's memory. When starting processes remotely, and when
20743attaching to already-running processes (local or remote), their
20744executable filenames will be prefixed with @var{path} if reported to
20745@value{GDBN} as absolute by the operating system. If you use
20746@code{set sysroot} to find executables and shared libraries, they need
20747to be laid out in the same way that they are on the target, with
20748e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20749@var{path}.
f822c95b 20750
599bd15c
GB
20751If @var{path} starts with the sequence @file{target:} and the target
20752system is remote then @value{GDBN} will retrieve the target binaries
20753from the remote system. This is only supported when using a remote
20754target that supports the @code{remote get} command (@pxref{File
20755Transfer,,Sending files to a remote system}). The part of @var{path}
20756following the initial @file{target:} (if present) is used as system
20757root prefix on the remote file system. If @var{path} starts with the
20758sequence @file{remote:} this is converted to the sequence
20759@file{target:} by @code{set sysroot}@footnote{Historically the
20760functionality to retrieve binaries from the remote system was
20761provided by prefixing @var{path} with @file{remote:}}. If you want
20762to specify a local system root using a directory that happens to be
20763named @file{target:} or @file{remote:}, you need to use some
20764equivalent variant of the name like @file{./target:}.
f1838a98 20765
ab38a727
PA
20766For targets with an MS-DOS based filesystem, such as MS-Windows and
20767SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20768absolute file name with @var{path}. But first, on Unix hosts,
20769@value{GDBN} converts all backslash directory separators into forward
20770slashes, because the backslash is not a directory separator on Unix:
20771
20772@smallexample
20773 c:\foo\bar.dll @result{} c:/foo/bar.dll
20774@end smallexample
20775
20776Then, @value{GDBN} attempts prefixing the target file name with
20777@var{path}, and looks for the resulting file name in the host file
20778system:
20779
20780@smallexample
20781 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20782@end smallexample
20783
a9a5a3d1 20784If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20785the @samp{:} character from the drive spec, both for convenience, and,
20786for the case of the host file system not supporting file names with
20787colons:
20788
20789@smallexample
20790 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20791@end smallexample
20792
20793This makes it possible to have a system root that mirrors a target
20794with more than one drive. E.g., you may want to setup your local
20795copies of the target system shared libraries like so (note @samp{c} vs
20796@samp{z}):
20797
20798@smallexample
20799 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20800 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20801 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20802@end smallexample
20803
20804@noindent
20805and point the system root at @file{/path/to/sysroot}, so that
20806@value{GDBN} can find the correct copies of both
20807@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20808
a9a5a3d1 20809If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20810removing the whole drive spec from the target file name:
20811
20812@smallexample
20813 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20814@end smallexample
20815
20816This last lookup makes it possible to not care about the drive name,
20817if you don't want or need to.
20818
f822c95b
DJ
20819The @code{set solib-absolute-prefix} command is an alias for @code{set
20820sysroot}.
20821
20822@cindex default system root
59b7b46f 20823@cindex @samp{--with-sysroot}
f822c95b
DJ
20824You can set the default system root by using the configure-time
20825@samp{--with-sysroot} option. If the system root is inside
20826@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20827@samp{--exec-prefix}), then the default system root will be updated
20828automatically if the installed @value{GDBN} is moved to a new
20829location.
20830
20831@kindex show sysroot
20832@item show sysroot
a9a5a3d1 20833Display the current executable and shared library prefix.
f5ebfba0
DJ
20834
20835@kindex set solib-search-path
20836@item set solib-search-path @var{path}
f822c95b
DJ
20837If this variable is set, @var{path} is a colon-separated list of
20838directories to search for shared libraries. @samp{solib-search-path}
20839is used after @samp{sysroot} fails to locate the library, or if the
20840path to the library is relative instead of absolute. If you want to
20841use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20842@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20843finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20844it to a nonexistent directory may interfere with automatic loading
f822c95b 20845of shared library symbols.
f5ebfba0
DJ
20846
20847@kindex show solib-search-path
20848@item show solib-search-path
20849Display the current shared library search path.
ab38a727
PA
20850
20851@cindex DOS file-name semantics of file names.
20852@kindex set target-file-system-kind (unix|dos-based|auto)
20853@kindex show target-file-system-kind
20854@item set target-file-system-kind @var{kind}
20855Set assumed file system kind for target reported file names.
20856
20857Shared library file names as reported by the target system may not
20858make sense as is on the system @value{GDBN} is running on. For
20859example, when remote debugging a target that has MS-DOS based file
20860system semantics, from a Unix host, the target may be reporting to
20861@value{GDBN} a list of loaded shared libraries with file names such as
20862@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20863drive letters, so the @samp{c:\} prefix is not normally understood as
20864indicating an absolute file name, and neither is the backslash
20865normally considered a directory separator character. In that case,
20866the native file system would interpret this whole absolute file name
20867as a relative file name with no directory components. This would make
20868it impossible to point @value{GDBN} at a copy of the remote target's
20869shared libraries on the host using @code{set sysroot}, and impractical
20870with @code{set solib-search-path}. Setting
20871@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20872to interpret such file names similarly to how the target would, and to
20873map them to file names valid on @value{GDBN}'s native file system
20874semantics. The value of @var{kind} can be @code{"auto"}, in addition
20875to one of the supported file system kinds. In that case, @value{GDBN}
20876tries to determine the appropriate file system variant based on the
20877current target's operating system (@pxref{ABI, ,Configuring the
20878Current ABI}). The supported file system settings are:
20879
20880@table @code
20881@item unix
20882Instruct @value{GDBN} to assume the target file system is of Unix
20883kind. Only file names starting the forward slash (@samp{/}) character
20884are considered absolute, and the directory separator character is also
20885the forward slash.
20886
20887@item dos-based
20888Instruct @value{GDBN} to assume the target file system is DOS based.
20889File names starting with either a forward slash, or a drive letter
20890followed by a colon (e.g., @samp{c:}), are considered absolute, and
20891both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20892considered directory separators.
20893
20894@item auto
20895Instruct @value{GDBN} to use the file system kind associated with the
20896target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20897This is the default.
20898@end table
f5ebfba0
DJ
20899@end table
20900
c011a4f4
DE
20901@cindex file name canonicalization
20902@cindex base name differences
20903When processing file names provided by the user, @value{GDBN}
20904frequently needs to compare them to the file names recorded in the
20905program's debug info. Normally, @value{GDBN} compares just the
20906@dfn{base names} of the files as strings, which is reasonably fast
20907even for very large programs. (The base name of a file is the last
20908portion of its name, after stripping all the leading directories.)
20909This shortcut in comparison is based upon the assumption that files
20910cannot have more than one base name. This is usually true, but
20911references to files that use symlinks or similar filesystem
20912facilities violate that assumption. If your program records files
20913using such facilities, or if you provide file names to @value{GDBN}
20914using symlinks etc., you can set @code{basenames-may-differ} to
20915@code{true} to instruct @value{GDBN} to completely canonicalize each
20916pair of file names it needs to compare. This will make file-name
20917comparisons accurate, but at a price of a significant slowdown.
20918
20919@table @code
20920@item set basenames-may-differ
20921@kindex set basenames-may-differ
20922Set whether a source file may have multiple base names.
20923
20924@item show basenames-may-differ
20925@kindex show basenames-may-differ
20926Show whether a source file may have multiple base names.
20927@end table
5b5d99cf 20928
18989b3c
AB
20929@node File Caching
20930@section File Caching
20931@cindex caching of opened files
20932@cindex caching of bfd objects
20933
20934To speed up file loading, and reduce memory usage, @value{GDBN} will
20935reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20936BFD, bfd, The Binary File Descriptor Library}. The following commands
20937allow visibility and control of the caching behavior.
20938
20939@table @code
20940@kindex maint info bfds
20941@item maint info bfds
20942This prints information about each @code{bfd} object that is known to
20943@value{GDBN}.
20944
20945@kindex maint set bfd-sharing
20946@kindex maint show bfd-sharing
20947@kindex bfd caching
20948@item maint set bfd-sharing
20949@item maint show bfd-sharing
20950Control whether @code{bfd} objects can be shared. When sharing is
20951enabled @value{GDBN} reuses already open @code{bfd} objects rather
20952than reopening the same file. Turning sharing off does not cause
20953already shared @code{bfd} objects to be unshared, but all future files
20954that are opened will create a new @code{bfd} object. Similarly,
20955re-enabling sharing does not cause multiple existing @code{bfd}
20956objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
20957
20958@kindex set debug bfd-cache @var{level}
20959@kindex bfd caching
20960@item set debug bfd-cache @var{level}
20961Turns on debugging of the bfd cache, setting the level to @var{level}.
20962
20963@kindex show debug bfd-cache
20964@kindex bfd caching
20965@item show debug bfd-cache
20966Show the current debugging level of the bfd cache.
18989b3c
AB
20967@end table
20968
5b5d99cf
JB
20969@node Separate Debug Files
20970@section Debugging Information in Separate Files
20971@cindex separate debugging information files
20972@cindex debugging information in separate files
20973@cindex @file{.debug} subdirectories
20974@cindex debugging information directory, global
f307c045 20975@cindex global debugging information directories
c7e83d54
EZ
20976@cindex build ID, and separate debugging files
20977@cindex @file{.build-id} directory
5b5d99cf
JB
20978
20979@value{GDBN} allows you to put a program's debugging information in a
20980file separate from the executable itself, in a way that allows
20981@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
20982Since debugging information can be very large---sometimes larger
20983than the executable code itself---some systems distribute debugging
5b5d99cf
JB
20984information for their executables in separate files, which users can
20985install only when they need to debug a problem.
20986
c7e83d54
EZ
20987@value{GDBN} supports two ways of specifying the separate debug info
20988file:
5b5d99cf
JB
20989
20990@itemize @bullet
20991@item
c7e83d54
EZ
20992The executable contains a @dfn{debug link} that specifies the name of
20993the separate debug info file. The separate debug file's name is
20994usually @file{@var{executable}.debug}, where @var{executable} is the
20995name of the corresponding executable file without leading directories
20996(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
20997debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20998checksum for the debug file, which @value{GDBN} uses to validate that
20999the executable and the debug file came from the same build.
c7e83d54
EZ
21000
21001@item
98c59b52 21002@anchor{build ID}
7e27a47a 21003The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 21004also present in the corresponding debug info file. (This is supported
c74f7d1c 21005only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
21006for binary files and the @sc{gnu} Binutils.) For more details about
21007this feature, see the description of the @option{--build-id}
f5a476a7 21008command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
21009The GNU Linker}. The debug info file's name is not specified
21010explicitly by the build ID, but can be computed from the build ID, see
21011below.
d3750b24
JK
21012@end itemize
21013
c7e83d54
EZ
21014Depending on the way the debug info file is specified, @value{GDBN}
21015uses two different methods of looking for the debug file:
d3750b24
JK
21016
21017@itemize @bullet
21018@item
c7e83d54
EZ
21019For the ``debug link'' method, @value{GDBN} looks up the named file in
21020the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
21021directory named @file{.debug}, and finally under each one of the
21022global debug directories, in a subdirectory whose name is identical to
21023the leading directories of the executable's absolute file name. (On
21024MS-Windows/MS-DOS, the drive letter of the executable's leading
21025directories is converted to a one-letter subdirectory, i.e.@:
21026@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21027filesystems disallow colons in file names.)
c7e83d54
EZ
21028
21029@item
83f83d7f 21030For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
21031@file{.build-id} subdirectory of each one of the global debug directories for
21032a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
21033first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21034are the rest of the bit string. (Real build ID strings are 32 or more
21035hex characters, not 10.)
c7e83d54
EZ
21036@end itemize
21037
21038So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
21039@file{/usr/bin/ls}, which has a debug link that specifies the
21040file @file{ls.debug}, and a build ID whose value in hex is
f307c045 21041@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
21042@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21043debug information files, in the indicated order:
21044
21045@itemize @minus
21046@item
21047@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 21048@item
c7e83d54 21049@file{/usr/bin/ls.debug}
5b5d99cf 21050@item
c7e83d54 21051@file{/usr/bin/.debug/ls.debug}
5b5d99cf 21052@item
c7e83d54 21053@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 21054@end itemize
5b5d99cf 21055
1564a261
JK
21056@anchor{debug-file-directory}
21057Global debugging info directories default to what is set by @value{GDBN}
21058configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21059you can also set the global debugging info directories, and view the list
21060@value{GDBN} is currently using.
5b5d99cf
JB
21061
21062@table @code
21063
21064@kindex set debug-file-directory
24ddea62
JK
21065@item set debug-file-directory @var{directories}
21066Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
21067information files to @var{directory}. Multiple path components can be set
21068concatenating them by a path separator.
5b5d99cf
JB
21069
21070@kindex show debug-file-directory
21071@item show debug-file-directory
24ddea62 21072Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
21073information files.
21074
21075@end table
21076
21077@cindex @code{.gnu_debuglink} sections
c7e83d54 21078@cindex debug link sections
5b5d99cf
JB
21079A debug link is a special section of the executable file named
21080@code{.gnu_debuglink}. The section must contain:
21081
21082@itemize
21083@item
21084A filename, with any leading directory components removed, followed by
21085a zero byte,
21086@item
21087zero to three bytes of padding, as needed to reach the next four-byte
21088boundary within the section, and
21089@item
21090a four-byte CRC checksum, stored in the same endianness used for the
21091executable file itself. The checksum is computed on the debugging
21092information file's full contents by the function given below, passing
21093zero as the @var{crc} argument.
21094@end itemize
21095
21096Any executable file format can carry a debug link, as long as it can
21097contain a section named @code{.gnu_debuglink} with the contents
21098described above.
21099
d3750b24 21100@cindex @code{.note.gnu.build-id} sections
c7e83d54 21101@cindex build ID sections
7e27a47a
EZ
21102The build ID is a special section in the executable file (and in other
21103ELF binary files that @value{GDBN} may consider). This section is
21104often named @code{.note.gnu.build-id}, but that name is not mandatory.
21105It contains unique identification for the built files---the ID remains
21106the same across multiple builds of the same build tree. The default
21107algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21108content for the build ID string. The same section with an identical
21109value is present in the original built binary with symbols, in its
21110stripped variant, and in the separate debugging information file.
d3750b24 21111
5b5d99cf
JB
21112The debugging information file itself should be an ordinary
21113executable, containing a full set of linker symbols, sections, and
21114debugging information. The sections of the debugging information file
c7e83d54
EZ
21115should have the same names, addresses, and sizes as the original file,
21116but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
21117in an ordinary executable.
21118
7e27a47a 21119The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
21120@samp{objcopy} utility that can produce
21121the separated executable / debugging information file pairs using the
21122following commands:
21123
21124@smallexample
21125@kbd{objcopy --only-keep-debug foo foo.debug}
21126@kbd{strip -g foo}
c7e83d54
EZ
21127@end smallexample
21128
21129@noindent
21130These commands remove the debugging
83f83d7f
JK
21131information from the executable file @file{foo} and place it in the file
21132@file{foo.debug}. You can use the first, second or both methods to link the
21133two files:
21134
21135@itemize @bullet
21136@item
21137The debug link method needs the following additional command to also leave
21138behind a debug link in @file{foo}:
21139
21140@smallexample
21141@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21142@end smallexample
21143
21144Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 21145a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
21146foo.debug} has the same functionality as the two @code{objcopy} commands and
21147the @code{ln -s} command above, together.
21148
21149@item
21150Build ID gets embedded into the main executable using @code{ld --build-id} or
21151the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21152compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21153utilities (Binutils) package since version 2.18.
83f83d7f
JK
21154@end itemize
21155
21156@noindent
d3750b24 21157
99e008fe
EZ
21158@cindex CRC algorithm definition
21159The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21160IEEE 802.3 using the polynomial:
21161
21162@c TexInfo requires naked braces for multi-digit exponents for Tex
21163@c output, but this causes HTML output to barf. HTML has to be set using
21164@c raw commands. So we end up having to specify this equation in 2
21165@c different ways!
21166@ifhtml
21167@display
21168@html
21169 <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>
21170 + <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
21171@end html
21172@end display
21173@end ifhtml
21174@ifnothtml
21175@display
21176 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21177 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21178@end display
21179@end ifnothtml
21180
21181The function is computed byte at a time, taking the least
21182significant bit of each byte first. The initial pattern
21183@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21184the final result is inverted to ensure trailing zeros also affect the
21185CRC.
21186
21187@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21188@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21189However in the case of the Remote Serial Protocol, the CRC is computed
21190@emph{most} significant bit first, and the result is not inverted, so
21191trailing zeros have no effect on the CRC value.
99e008fe
EZ
21192
21193To complete the description, we show below the code of the function
21194which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21195initially supplied @code{crc} argument means that an initial call to
21196this function passing in zero will start computing the CRC using
21197@code{0xffffffff}.
5b5d99cf 21198
4644b6e3 21199@kindex gnu_debuglink_crc32
5b5d99cf
JB
21200@smallexample
21201unsigned long
21202gnu_debuglink_crc32 (unsigned long crc,
21203 unsigned char *buf, size_t len)
21204@{
21205 static const unsigned long crc32_table[256] =
21206 @{
21207 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21208 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21209 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21210 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21211 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21212 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21213 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21214 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21215 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21216 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21217 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21218 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21219 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21220 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21221 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21222 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21223 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21224 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21225 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21226 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21227 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21228 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21229 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21230 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21231 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21232 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21233 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21234 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21235 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21236 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21237 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21238 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21239 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21240 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21241 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21242 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21243 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21244 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21245 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21246 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21247 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21248 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21249 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21250 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21251 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21252 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21253 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21254 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21255 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21256 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21257 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21258 0x2d02ef8d
21259 @};
21260 unsigned char *end;
21261
21262 crc = ~crc & 0xffffffff;
21263 for (end = buf + len; buf < end; ++buf)
21264 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21265 return ~crc & 0xffffffff;
5b5d99cf
JB
21266@}
21267@end smallexample
21268
c7e83d54
EZ
21269@noindent
21270This computation does not apply to the ``build ID'' method.
21271
608e2dbb
TT
21272@node MiniDebugInfo
21273@section Debugging information in a special section
21274@cindex separate debug sections
21275@cindex @samp{.gnu_debugdata} section
21276
21277Some systems ship pre-built executables and libraries that have a
21278special @samp{.gnu_debugdata} section. This feature is called
21279@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21280is used to supply extra symbols for backtraces.
21281
21282The intent of this section is to provide extra minimal debugging
21283information for use in simple backtraces. It is not intended to be a
21284replacement for full separate debugging information (@pxref{Separate
21285Debug Files}). The example below shows the intended use; however,
21286@value{GDBN} does not currently put restrictions on what sort of
21287debugging information might be included in the section.
21288
21289@value{GDBN} has support for this extension. If the section exists,
21290then it is used provided that no other source of debugging information
21291can be found, and that @value{GDBN} was configured with LZMA support.
21292
21293This section can be easily created using @command{objcopy} and other
21294standard utilities:
21295
21296@smallexample
21297# Extract the dynamic symbols from the main binary, there is no need
5423b017 21298# to also have these in the normal symbol table.
608e2dbb
TT
21299nm -D @var{binary} --format=posix --defined-only \
21300 | awk '@{ print $1 @}' | sort > dynsyms
21301
5423b017 21302# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21303# (Note that we actually also accept "D" symbols, for the benefit
21304# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21305nm @var{binary} --format=posix --defined-only \
1d236d23 21306 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21307 | sort > funcsyms
21308
21309# Keep all the function symbols not already in the dynamic symbol
21310# table.
21311comm -13 dynsyms funcsyms > keep_symbols
21312
edf9f00c
JK
21313# Separate full debug info into debug binary.
21314objcopy --only-keep-debug @var{binary} debug
21315
608e2dbb
TT
21316# Copy the full debuginfo, keeping only a minimal set of symbols and
21317# removing some unnecessary sections.
21318objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21319 --keep-symbols=keep_symbols debug mini_debuginfo
21320
21321# Drop the full debug info from the original binary.
21322strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21323
21324# Inject the compressed data into the .gnu_debugdata section of the
21325# original binary.
21326xz mini_debuginfo
21327objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21328@end smallexample
5b5d99cf 21329
9291a0cd
TT
21330@node Index Files
21331@section Index Files Speed Up @value{GDBN}
21332@cindex index files
21333@cindex @samp{.gdb_index} section
21334
21335When @value{GDBN} finds a symbol file, it scans the symbols in the
21336file in order to construct an internal symbol table. This lets most
21337@value{GDBN} operations work quickly---at the cost of a delay early
21338on. For large programs, this delay can be quite lengthy, so
21339@value{GDBN} provides a way to build an index, which speeds up
21340startup.
21341
ba643918
SDJ
21342For convenience, @value{GDBN} comes with a program,
21343@command{gdb-add-index}, which can be used to add the index to a
21344symbol file. It takes the symbol file as its only argument:
21345
21346@smallexample
21347$ gdb-add-index symfile
21348@end smallexample
21349
21350@xref{gdb-add-index}.
21351
21352It is also possible to do the work manually. Here is what
21353@command{gdb-add-index} does behind the curtains.
21354
9291a0cd
TT
21355The index is stored as a section in the symbol file. @value{GDBN} can
21356write the index to a file, then you can put it into the symbol file
21357using @command{objcopy}.
21358
21359To create an index file, use the @code{save gdb-index} command:
21360
21361@table @code
437afbb8 21362@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21363@kindex save gdb-index
437afbb8
JK
21364Create index files for all symbol files currently known by
21365@value{GDBN}. For each known @var{symbol-file}, this command by
21366default creates it produces a single file
21367@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21368the @option{-dwarf-5} option, it produces 2 files:
21369@file{@var{symbol-file}.debug_names} and
21370@file{@var{symbol-file}.debug_str}. The files are created in the
21371given @var{directory}.
9291a0cd
TT
21372@end table
21373
21374Once you have created an index file you can merge it into your symbol
21375file, here named @file{symfile}, using @command{objcopy}:
21376
21377@smallexample
21378$ objcopy --add-section .gdb_index=symfile.gdb-index \
21379 --set-section-flags .gdb_index=readonly symfile symfile
21380@end smallexample
21381
437afbb8
JK
21382Or for @code{-dwarf-5}:
21383
21384@smallexample
21385$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21386$ cat symfile.debug_str >>symfile.debug_str.new
21387$ objcopy --add-section .debug_names=symfile.gdb-index \
21388 --set-section-flags .debug_names=readonly \
21389 --update-section .debug_str=symfile.debug_str.new symfile symfile
21390@end smallexample
21391
e615022a
DE
21392@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21393sections that have been deprecated. Usually they are deprecated because
21394they are missing a new feature or have performance issues.
21395To tell @value{GDBN} to use a deprecated index section anyway
21396specify @code{set use-deprecated-index-sections on}.
21397The default is @code{off}.
21398This can speed up startup, but may result in some functionality being lost.
21399@xref{Index Section Format}.
21400
21401@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21402must be done before gdb reads the file. The following will not work:
21403
21404@smallexample
21405$ gdb -ex "set use-deprecated-index-sections on" <program>
21406@end smallexample
21407
21408Instead you must do, for example,
21409
21410@smallexample
21411$ gdb -iex "set use-deprecated-index-sections on" <program>
21412@end smallexample
21413
914592f9 21414Indices only work when using DWARF debugging information, not stabs.
9291a0cd 21415
7d11235d
SM
21416@subsection Automatic symbol index cache
21417
a0a3a1e9 21418@cindex automatic symbol index cache
7d11235d
SM
21419It is possible for @value{GDBN} to automatically save a copy of this index in a
21420cache on disk and retrieve it from there when loading the same binary in the
21421future. This feature can be turned on with @kbd{set index-cache on}. The
21422following commands can be used to tweak the behavior of the index cache.
21423
21424@table @code
21425
a0a3a1e9 21426@kindex set index-cache
7d11235d
SM
21427@item set index-cache on
21428@itemx set index-cache off
21429Enable or disable the use of the symbol index cache.
21430
21431@item set index-cache directory @var{directory}
a0a3a1e9 21432@kindex show index-cache
7d11235d 21433@itemx show index-cache directory
e6cd1dc1
TT
21434Set/show the directory where index files will be saved.
21435
21436The default value for this directory depends on the host platform. On
21437most systems, the index is cached in the @file{gdb} subdirectory of
21438the directory pointed to by the @env{XDG_CACHE_HOME} environment
21439variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21440of your home directory. However, on some systems, the default may
21441differ according to local convention.
7d11235d
SM
21442
21443There is no limit on the disk space used by index cache. It is perfectly safe
21444to delete the content of that directory to free up disk space.
21445
21446@item show index-cache stats
21447Print the number of cache hits and misses since the launch of @value{GDBN}.
21448
21449@end table
21450
6d2ebf8b 21451@node Symbol Errors
79a6e687 21452@section Errors Reading Symbol Files
c906108c
SS
21453
21454While reading a symbol file, @value{GDBN} occasionally encounters problems,
21455such as symbol types it does not recognize, or known bugs in compiler
21456output. By default, @value{GDBN} does not notify you of such problems, since
21457they are relatively common and primarily of interest to people
21458debugging compilers. If you are interested in seeing information
21459about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21460only one message about each such type of problem, no matter how many
21461times the problem occurs; or you can ask @value{GDBN} to print more messages,
21462to see how many times the problems occur, with the @code{set
79a6e687
BW
21463complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21464Messages}).
c906108c
SS
21465
21466The messages currently printed, and their meanings, include:
21467
21468@table @code
21469@item inner block not inside outer block in @var{symbol}
21470
21471The symbol information shows where symbol scopes begin and end
21472(such as at the start of a function or a block of statements). This
21473error indicates that an inner scope block is not fully contained
21474in its outer scope blocks.
21475
21476@value{GDBN} circumvents the problem by treating the inner block as if it had
21477the same scope as the outer block. In the error message, @var{symbol}
21478may be shown as ``@code{(don't know)}'' if the outer block is not a
21479function.
21480
21481@item block at @var{address} out of order
21482
21483The symbol information for symbol scope blocks should occur in
21484order of increasing addresses. This error indicates that it does not
21485do so.
21486
21487@value{GDBN} does not circumvent this problem, and has trouble
21488locating symbols in the source file whose symbols it is reading. (You
21489can often determine what source file is affected by specifying
79a6e687
BW
21490@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21491Messages}.)
c906108c
SS
21492
21493@item bad block start address patched
21494
21495The symbol information for a symbol scope block has a start address
21496smaller than the address of the preceding source line. This is known
21497to occur in the SunOS 4.1.1 (and earlier) C compiler.
21498
21499@value{GDBN} circumvents the problem by treating the symbol scope block as
21500starting on the previous source line.
21501
21502@item bad string table offset in symbol @var{n}
21503
21504@cindex foo
21505Symbol number @var{n} contains a pointer into the string table which is
21506larger than the size of the string table.
21507
21508@value{GDBN} circumvents the problem by considering the symbol to have the
21509name @code{foo}, which may cause other problems if many symbols end up
21510with this name.
21511
21512@item unknown symbol type @code{0x@var{nn}}
21513
7a292a7a
SS
21514The symbol information contains new data types that @value{GDBN} does
21515not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21516uncomprehended information, in hexadecimal.
c906108c 21517
7a292a7a
SS
21518@value{GDBN} circumvents the error by ignoring this symbol information.
21519This usually allows you to debug your program, though certain symbols
c906108c 21520are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21521debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21522on @code{complain}, then go up to the function @code{read_dbx_symtab}
21523and examine @code{*bufp} to see the symbol.
c906108c
SS
21524
21525@item stub type has NULL name
c906108c 21526
7a292a7a 21527@value{GDBN} could not find the full definition for a struct or class.
c906108c 21528
7a292a7a 21529@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21530The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21531information that recent versions of the compiler should have output for
21532it.
c906108c
SS
21533
21534@item info mismatch between compiler and debugger
21535
21536@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21537
c906108c
SS
21538@end table
21539
b14b1491
TT
21540@node Data Files
21541@section GDB Data Files
21542
21543@cindex prefix for data files
21544@value{GDBN} will sometimes read an auxiliary data file. These files
21545are kept in a directory known as the @dfn{data directory}.
21546
21547You can set the data directory's name, and view the name @value{GDBN}
21548is currently using.
21549
21550@table @code
21551@kindex set data-directory
21552@item set data-directory @var{directory}
21553Set the directory which @value{GDBN} searches for auxiliary data files
21554to @var{directory}.
21555
21556@kindex show data-directory
21557@item show data-directory
21558Show the directory @value{GDBN} searches for auxiliary data files.
21559@end table
21560
21561@cindex default data directory
21562@cindex @samp{--with-gdb-datadir}
21563You can set the default data directory by using the configure-time
21564@samp{--with-gdb-datadir} option. If the data directory is inside
21565@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21566@samp{--exec-prefix}), then the default data directory will be updated
21567automatically if the installed @value{GDBN} is moved to a new
21568location.
21569
aae1c79a
DE
21570The data directory may also be specified with the
21571@code{--data-directory} command line option.
21572@xref{Mode Options}.
21573
6d2ebf8b 21574@node Targets
c906108c 21575@chapter Specifying a Debugging Target
7a292a7a 21576
c906108c 21577@cindex debugging target
c906108c 21578A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21579
21580Often, @value{GDBN} runs in the same host environment as your program;
21581in that case, the debugging target is specified as a side effect when
21582you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21583flexibility---for example, running @value{GDBN} on a physically separate
21584host, or controlling a standalone system over a serial port or a
53a5351d
JM
21585realtime system over a TCP/IP connection---you can use the @code{target}
21586command to specify one of the target types configured for @value{GDBN}
79a6e687 21587(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21588
a8f24a35
EZ
21589@cindex target architecture
21590It is possible to build @value{GDBN} for several different @dfn{target
21591architectures}. When @value{GDBN} is built like that, you can choose
21592one of the available architectures with the @kbd{set architecture}
21593command.
21594
21595@table @code
21596@kindex set architecture
21597@kindex show architecture
21598@item set architecture @var{arch}
21599This command sets the current target architecture to @var{arch}. The
21600value of @var{arch} can be @code{"auto"}, in addition to one of the
21601supported architectures.
21602
21603@item show architecture
21604Show the current target architecture.
9c16f35a
EZ
21605
21606@item set processor
21607@itemx processor
21608@kindex set processor
21609@kindex show processor
21610These are alias commands for, respectively, @code{set architecture}
21611and @code{show architecture}.
a8f24a35
EZ
21612@end table
21613
c906108c
SS
21614@menu
21615* Active Targets:: Active targets
21616* Target Commands:: Commands for managing targets
c906108c 21617* Byte Order:: Choosing target byte order
c906108c
SS
21618@end menu
21619
6d2ebf8b 21620@node Active Targets
79a6e687 21621@section Active Targets
7a292a7a 21622
c906108c
SS
21623@cindex stacking targets
21624@cindex active targets
21625@cindex multiple targets
21626
8ea5bce5 21627There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21628recording sessions. Core files belong to the process class, making core file
21629and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21630on multiple active targets, one in each class. This allows you to (for
21631example) start a process and inspect its activity, while still having access to
21632the executable file after the process finishes. Or if you start process
21633recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21634presented a virtual layer of the recording target, while the process target
21635remains stopped at the chronologically last point of the process execution.
21636
21637Use the @code{core-file} and @code{exec-file} commands to select a new core
21638file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21639specify as a target a process that is already running, use the @code{attach}
21640command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21641
6d2ebf8b 21642@node Target Commands
79a6e687 21643@section Commands for Managing Targets
c906108c
SS
21644
21645@table @code
21646@item target @var{type} @var{parameters}
7a292a7a
SS
21647Connects the @value{GDBN} host environment to a target machine or
21648process. A target is typically a protocol for talking to debugging
21649facilities. You use the argument @var{type} to specify the type or
21650protocol of the target machine.
c906108c
SS
21651
21652Further @var{parameters} are interpreted by the target protocol, but
21653typically include things like device names or host names to connect
21654with, process numbers, and baud rates.
c906108c
SS
21655
21656The @code{target} command does not repeat if you press @key{RET} again
21657after executing the command.
21658
21659@kindex help target
21660@item help target
21661Displays the names of all targets available. To display targets
21662currently selected, use either @code{info target} or @code{info files}
79a6e687 21663(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21664
21665@item help target @var{name}
21666Describe a particular target, including any parameters necessary to
21667select it.
21668
21669@kindex set gnutarget
21670@item set gnutarget @var{args}
5d161b24 21671@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21672knows whether it is reading an @dfn{executable},
5d161b24
DB
21673a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21674with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21675with @code{gnutarget} the @code{target} refers to a program, not a machine.
21676
d4f3574e 21677@quotation
c906108c
SS
21678@emph{Warning:} To specify a file format with @code{set gnutarget},
21679you must know the actual BFD name.
d4f3574e 21680@end quotation
c906108c 21681
d4f3574e 21682@noindent
79a6e687 21683@xref{Files, , Commands to Specify Files}.
c906108c 21684
5d161b24 21685@kindex show gnutarget
c906108c
SS
21686@item show gnutarget
21687Use the @code{show gnutarget} command to display what file format
21688@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21689@value{GDBN} will determine the file format for each file automatically,
c4957902 21690and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21691@end table
21692
4644b6e3 21693@cindex common targets
c906108c
SS
21694Here are some common targets (available, or not, depending on the GDB
21695configuration):
c906108c
SS
21696
21697@table @code
4644b6e3 21698@kindex target
c906108c 21699@item target exec @var{program}
4644b6e3 21700@cindex executable file target
c906108c
SS
21701An executable file. @samp{target exec @var{program}} is the same as
21702@samp{exec-file @var{program}}.
21703
c906108c 21704@item target core @var{filename}
4644b6e3 21705@cindex core dump file target
c906108c
SS
21706A core dump file. @samp{target core @var{filename}} is the same as
21707@samp{core-file @var{filename}}.
c906108c 21708
1a10341b 21709@item target remote @var{medium}
4644b6e3 21710@cindex remote target
1a10341b
JB
21711A remote system connected to @value{GDBN} via a serial line or network
21712connection. This command tells @value{GDBN} to use its own remote
21713protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21714
21715For example, if you have a board connected to @file{/dev/ttya} on the
21716machine running @value{GDBN}, you could say:
21717
21718@smallexample
21719target remote /dev/ttya
21720@end smallexample
21721
21722@code{target remote} supports the @code{load} command. This is only
21723useful if you have some other way of getting the stub to the target
21724system, and you can put it somewhere in memory where it won't get
21725clobbered by the download.
c906108c 21726
ee8e71d4 21727@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21728@cindex built-in simulator target
2df3850c 21729Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21730In general,
474c8240 21731@smallexample
104c1213
JM
21732 target sim
21733 load
21734 run
474c8240 21735@end smallexample
d4f3574e 21736@noindent
104c1213 21737works; however, you cannot assume that a specific memory map, device
d4f3574e 21738drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21739provide these. For info about any processor-specific simulator details,
21740see the appropriate section in @ref{Embedded Processors, ,Embedded
21741Processors}.
21742
6a3cb8e8
PA
21743@item target native
21744@cindex native target
21745Setup for local/native process debugging. Useful to make the
21746@code{run} command spawn native processes (likewise @code{attach},
21747etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21748(@pxref{set auto-connect-native-target}).
21749
c906108c
SS
21750@end table
21751
5d161b24 21752Different targets are available on different configurations of @value{GDBN};
c906108c 21753your configuration may have more or fewer targets.
c906108c 21754
721c2651
EZ
21755Many remote targets require you to download the executable's code once
21756you've successfully established a connection. You may wish to control
3d00d119
DJ
21757various aspects of this process.
21758
21759@table @code
721c2651
EZ
21760
21761@item set hash
21762@kindex set hash@r{, for remote monitors}
21763@cindex hash mark while downloading
21764This command controls whether a hash mark @samp{#} is displayed while
21765downloading a file to the remote monitor. If on, a hash mark is
21766displayed after each S-record is successfully downloaded to the
21767monitor.
21768
21769@item show hash
21770@kindex show hash@r{, for remote monitors}
21771Show the current status of displaying the hash mark.
21772
21773@item set debug monitor
21774@kindex set debug monitor
21775@cindex display remote monitor communications
21776Enable or disable display of communications messages between
21777@value{GDBN} and the remote monitor.
21778
21779@item show debug monitor
21780@kindex show debug monitor
21781Show the current status of displaying communications between
21782@value{GDBN} and the remote monitor.
a8f24a35 21783@end table
c906108c
SS
21784
21785@table @code
21786
5cf30ebf
LM
21787@kindex load @var{filename} @var{offset}
21788@item load @var{filename} @var{offset}
8edfe269 21789@anchor{load}
c906108c
SS
21790Depending on what remote debugging facilities are configured into
21791@value{GDBN}, the @code{load} command may be available. Where it exists, it
21792is meant to make @var{filename} (an executable) available for debugging
21793on the remote system---by downloading, or dynamic linking, for example.
21794@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21795the @code{add-symbol-file} command.
21796
21797If your @value{GDBN} does not have a @code{load} command, attempting to
21798execute it gets the error message ``@code{You can't do that when your
21799target is @dots{}}''
c906108c
SS
21800
21801The file is loaded at whatever address is specified in the executable.
21802For some object file formats, you can specify the load address when you
21803link the program; for other formats, like a.out, the object file format
21804specifies a fixed address.
21805@c FIXME! This would be a good place for an xref to the GNU linker doc.
21806
5cf30ebf
LM
21807It is also possible to tell @value{GDBN} to load the executable file at a
21808specific offset described by the optional argument @var{offset}. When
21809@var{offset} is provided, @var{filename} must also be provided.
21810
68437a39
DJ
21811Depending on the remote side capabilities, @value{GDBN} may be able to
21812load programs into flash memory.
21813
c906108c
SS
21814@code{load} does not repeat if you press @key{RET} again after using it.
21815@end table
21816
78cbbba8
LM
21817@table @code
21818
21819@kindex flash-erase
21820@item flash-erase
21821@anchor{flash-erase}
21822
21823Erases all known flash memory regions on the target.
21824
21825@end table
21826
6d2ebf8b 21827@node Byte Order
79a6e687 21828@section Choosing Target Byte Order
7a292a7a 21829
c906108c
SS
21830@cindex choosing target byte order
21831@cindex target byte order
c906108c 21832
eb17f351 21833Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21834offer the ability to run either big-endian or little-endian byte
21835orders. Usually the executable or symbol will include a bit to
21836designate the endian-ness, and you will not need to worry about
21837which to use. However, you may still find it useful to adjust
d4f3574e 21838@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21839
21840@table @code
4644b6e3 21841@kindex set endian
c906108c
SS
21842@item set endian big
21843Instruct @value{GDBN} to assume the target is big-endian.
21844
c906108c
SS
21845@item set endian little
21846Instruct @value{GDBN} to assume the target is little-endian.
21847
c906108c
SS
21848@item set endian auto
21849Instruct @value{GDBN} to use the byte order associated with the
21850executable.
21851
21852@item show endian
21853Display @value{GDBN}'s current idea of the target byte order.
21854
21855@end table
21856
4b2dfa9d
MR
21857If the @code{set endian auto} mode is in effect and no executable has
21858been selected, then the endianness used is the last one chosen either
21859by one of the @code{set endian big} and @code{set endian little}
21860commands or by inferring from the last executable used. If no
21861endianness has been previously chosen, then the default for this mode
21862is inferred from the target @value{GDBN} has been built for, and is
21863@code{little} if the name of the target CPU has an @code{el} suffix
21864and @code{big} otherwise.
21865
c906108c
SS
21866Note that these commands merely adjust interpretation of symbolic
21867data on the host, and that they have absolutely no effect on the
21868target system.
21869
ea35711c
DJ
21870
21871@node Remote Debugging
21872@chapter Debugging Remote Programs
c906108c
SS
21873@cindex remote debugging
21874
21875If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
21876@value{GDBN} in the usual way, it is often useful to use remote debugging.
21877For example, you might use remote debugging on an operating system kernel,
c906108c
SS
21878or on a small system which does not have a general purpose operating system
21879powerful enough to run a full-featured debugger.
21880
21881Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21882to make this work with particular debugging targets. In addition,
5d161b24 21883@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
21884but not specific to any particular target system) which you can use if you
21885write the remote stubs---the code that runs on the remote system to
21886communicate with @value{GDBN}.
21887
21888Other remote targets may be available in your
21889configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21890
6b2f586d 21891@menu
07f31aa6 21892* Connecting:: Connecting to a remote target
a6b151f1 21893* File Transfer:: Sending files to a remote system
6b2f586d 21894* Server:: Using the gdbserver program
79a6e687
BW
21895* Remote Configuration:: Remote configuration
21896* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21897@end menu
21898
07f31aa6 21899@node Connecting
79a6e687 21900@section Connecting to a Remote Target
19d9d4ef
DB
21901@cindex remote debugging, connecting
21902@cindex @code{gdbserver}, connecting
21903@cindex remote debugging, types of connections
21904@cindex @code{gdbserver}, types of connections
21905@cindex @code{gdbserver}, @code{target remote} mode
21906@cindex @code{gdbserver}, @code{target extended-remote} mode
21907
21908This section describes how to connect to a remote target, including the
21909types of connections and their differences, how to set up executable and
21910symbol files on the host and target, and the commands used for
21911connecting to and disconnecting from the remote target.
21912
21913@subsection Types of Remote Connections
21914
21915@value{GDBN} supports two types of remote connections, @code{target remote}
21916mode and @code{target extended-remote} mode. Note that many remote targets
21917support only @code{target remote} mode. There are several major
21918differences between the two types of connections, enumerated here:
21919
21920@table @asis
21921
21922@cindex remote debugging, detach and program exit
21923@item Result of detach or program exit
21924@strong{With target remote mode:} When the debugged program exits or you
21925detach from it, @value{GDBN} disconnects from the target. When using
21926@code{gdbserver}, @code{gdbserver} will exit.
21927
21928@strong{With target extended-remote mode:} When the debugged program exits or
21929you detach from it, @value{GDBN} remains connected to the target, even
21930though no program is running. You can rerun the program, attach to a
21931running program, or use @code{monitor} commands specific to the target.
21932
21933When using @code{gdbserver} in this case, it does not exit unless it was
21934invoked using the @option{--once} option. If the @option{--once} option
21935was not used, you can ask @code{gdbserver} to exit using the
21936@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21937
21938@item Specifying the program to debug
21939For both connection types you use the @code{file} command to specify the
21940program on the host system. If you are using @code{gdbserver} there are
21941some differences in how to specify the location of the program on the
21942target.
21943
21944@strong{With target remote mode:} You must either specify the program to debug
21945on the @code{gdbserver} command line or use the @option{--attach} option
21946(@pxref{Attaching to a program,,Attaching to a Running Program}).
21947
21948@cindex @option{--multi}, @code{gdbserver} option
21949@strong{With target extended-remote mode:} You may specify the program to debug
21950on the @code{gdbserver} command line, or you can load the program or attach
21951to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21952
21953@anchor{--multi Option in Types of Remote Connnections}
21954You can start @code{gdbserver} without supplying an initial command to run
21955or process ID to attach. To do this, use the @option{--multi} command line
21956option. Then you can connect using @code{target extended-remote} and start
21957the program you want to debug (see below for details on using the
21958@code{run} command in this scenario). Note that the conditions under which
21959@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21960(@code{target remote} or @code{target extended-remote}). The
21961@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 21962
19d9d4ef
DB
21963@item The @code{run} command
21964@strong{With target remote mode:} The @code{run} command is not
21965supported. Once a connection has been established, you can use all
21966the usual @value{GDBN} commands to examine and change data. The
21967remote program is already running, so you can use commands like
21968@kbd{step} and @kbd{continue}.
21969
21970@strong{With target extended-remote mode:} The @code{run} command is
21971supported. The @code{run} command uses the value set by
21972@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21973the program to run. Command line arguments are supported, except for
21974wildcard expansion and I/O redirection (@pxref{Arguments}).
21975
21976If you specify the program to debug on the command line, then the
21977@code{run} command is not required to start execution, and you can
21978resume using commands like @kbd{step} and @kbd{continue} as with
21979@code{target remote} mode.
21980
21981@anchor{Attaching in Types of Remote Connections}
21982@item Attaching
21983@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21984not supported. To attach to a running program using @code{gdbserver}, you
21985must use the @option{--attach} option (@pxref{Running gdbserver}).
21986
21987@strong{With target extended-remote mode:} To attach to a running program,
21988you may use the @code{attach} command after the connection has been
21989established. If you are using @code{gdbserver}, you may also invoke
21990@code{gdbserver} using the @option{--attach} option
21991(@pxref{Running gdbserver}).
21992
e47e48f6
PW
21993Some remote targets allow @value{GDBN} to determine the executable file running
21994in the process the debugger is attaching to. In such a case, @value{GDBN}
21995uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21996between the executable file name running in the process and the name of the
21997current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21998
19d9d4ef
DB
21999@end table
22000
22001@anchor{Host and target files}
22002@subsection Host and Target Files
22003@cindex remote debugging, symbol files
22004@cindex symbol files, remote debugging
22005
22006@value{GDBN}, running on the host, needs access to symbol and debugging
22007information for your program running on the target. This requires
22008access to an unstripped copy of your program, and possibly any associated
22009symbol files. Note that this section applies equally to both @code{target
22010remote} mode and @code{target extended-remote} mode.
22011
22012Some remote targets (@pxref{qXfer executable filename read}, and
22013@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22014the same connection used to communicate with @value{GDBN}. With such a
22015target, if the remote program is unstripped, the only command you need is
22016@code{target remote} (or @code{target extended-remote}).
22017
22018If the remote program is stripped, or the target does not support remote
22019program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 22020unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
22021@code{file} command. Use @code{set sysroot} to specify the location (on
22022the host) of target libraries (unless your @value{GDBN} was compiled with
22023the correct sysroot using @code{--with-sysroot}). Alternatively, you
22024may use @code{set solib-search-path} to specify how @value{GDBN} locates
22025target libraries.
22026
22027The symbol file and target libraries must exactly match the executable
22028and libraries on the target, with one exception: the files on the host
22029system should not be stripped, even if the files on the target system
22030are. Mismatched or missing files will lead to confusing results
22031during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22032files may also prevent @code{gdbserver} from debugging multi-threaded
22033programs.
07f31aa6 22034
19d9d4ef
DB
22035@subsection Remote Connection Commands
22036@cindex remote connection commands
c1168a2f
JD
22037@value{GDBN} can communicate with the target over a serial line, a
22038local Unix domain socket, or
86941c27
JB
22039over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22040each case, @value{GDBN} uses the same protocol for debugging your
22041program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
22042@code{target remote} and @code{target extended-remote} commands
22043establish a connection to the target. Both commands accept the same
22044arguments, which indicate the medium to use:
86941c27
JB
22045
22046@table @code
22047
22048@item target remote @var{serial-device}
19d9d4ef 22049@itemx target extended-remote @var{serial-device}
07f31aa6 22050@cindex serial line, @code{target remote}
86941c27
JB
22051Use @var{serial-device} to communicate with the target. For example,
22052to use a serial line connected to the device named @file{/dev/ttyb}:
22053
22054@smallexample
22055target remote /dev/ttyb
22056@end smallexample
22057
07f31aa6 22058If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 22059@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 22060(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 22061@code{target} command.
07f31aa6 22062
c1168a2f
JD
22063@item target remote @var{local-socket}
22064@itemx target extended-remote @var{local-socket}
22065@cindex local socket, @code{target remote}
22066@cindex Unix domain socket
22067Use @var{local-socket} to communicate with the target. For example,
22068to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22069
22070@smallexample
22071target remote /tmp/gdb-socket0
22072@end smallexample
22073
22074Note that this command has the same form as the command to connect
22075to a serial line. @value{GDBN} will automatically determine which
22076kind of file you have specified and will make the appropriate kind
22077of connection.
22078This feature is not available if the host system does not support
22079Unix domain sockets.
22080
86941c27 22081@item target remote @code{@var{host}:@var{port}}
0ca4866a 22082@itemx target remote @code{[@var{host}]:@var{port}}
86941c27 22083@itemx target remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22084@itemx target remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22085@itemx target remote @code{tcp4:@var{host}:@var{port}}
22086@itemx target remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22087@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
19d9d4ef 22088@itemx target extended-remote @code{@var{host}:@var{port}}
0ca4866a 22089@itemx target extended-remote @code{[@var{host}]:@var{port}}
19d9d4ef 22090@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22091@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22092@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22093@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22094@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
86941c27 22095@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 22096Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
22097The @var{host} may be either a host name, a numeric @acronym{IPv4}
22098address, or a numeric @acronym{IPv6} address (with or without the
22099square brackets to separate the address from the port); @var{port}
22100must be a decimal number. The @var{host} could be the target machine
22101itself, if it is directly connected to the net, or it might be a
22102terminal server which in turn has a serial line to the target.
07f31aa6 22103
86941c27
JB
22104For example, to connect to port 2828 on a terminal server named
22105@code{manyfarms}:
07f31aa6
DJ
22106
22107@smallexample
22108target remote manyfarms:2828
22109@end smallexample
22110
c7ab0aef
SDJ
22111To connect to port 2828 on a terminal server whose address is
22112@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22113square bracket syntax:
22114
22115@smallexample
22116target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22117@end smallexample
22118
22119@noindent
22120or explicitly specify the @acronym{IPv6} protocol:
22121
22122@smallexample
22123target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22124@end smallexample
22125
22126This last example may be confusing to the reader, because there is no
22127visible separation between the hostname and the port number.
22128Therefore, we recommend the user to provide @acronym{IPv6} addresses
22129using square brackets for clarity. However, it is important to
22130mention that for @value{GDBN} there is no ambiguity: the number after
22131the last colon is considered to be the port number.
22132
86941c27
JB
22133If your remote target is actually running on the same machine as your
22134debugger session (e.g.@: a simulator for your target running on the
22135same host), you can omit the hostname. For example, to connect to
22136port 1234 on your local machine:
07f31aa6
DJ
22137
22138@smallexample
22139target remote :1234
22140@end smallexample
22141@noindent
22142
22143Note that the colon is still required here.
22144
86941c27 22145@item target remote @code{udp:@var{host}:@var{port}}
0ca4866a 22146@itemx target remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef 22147@itemx target remote @code{udp4:@var{host}:@var{port}}
0ca4866a 22148@itemx target remote @code{udp6:[@var{host}]:@var{port}}
c7ab0aef 22149@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 22150@itemx target extended-remote @code{udp:@var{host}:@var{port}}
0ca4866a 22151@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22152@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22153@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
0ca4866a 22154@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
86941c27
JB
22155@cindex @acronym{UDP} port, @code{target remote}
22156Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22157connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22158
22159@smallexample
22160target remote udp:manyfarms:2828
22161@end smallexample
22162
86941c27
JB
22163When using a @acronym{UDP} connection for remote debugging, you should
22164keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22165can silently drop packets on busy or unreliable networks, which will
22166cause havoc with your debugging session.
22167
66b8c7f6 22168@item target remote | @var{command}
19d9d4ef 22169@itemx target extended-remote | @var{command}
66b8c7f6
JB
22170@cindex pipe, @code{target remote} to
22171Run @var{command} in the background and communicate with it using a
22172pipe. The @var{command} is a shell command, to be parsed and expanded
22173by the system's command shell, @code{/bin/sh}; it should expect remote
22174protocol packets on its standard input, and send replies on its
22175standard output. You could use this to run a stand-alone simulator
22176that speaks the remote debugging protocol, to make net connections
22177using programs like @code{ssh}, or for other similar tricks.
22178
22179If @var{command} closes its standard output (perhaps by exiting),
22180@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22181program has already exited, this will have no effect.)
22182
86941c27 22183@end table
07f31aa6 22184
07f31aa6
DJ
22185@cindex interrupting remote programs
22186@cindex remote programs, interrupting
22187Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22188interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22189program. This may or may not succeed, depending in part on the hardware
22190and the serial drivers the remote system uses. If you type the
22191interrupt character once again, @value{GDBN} displays this prompt:
22192
22193@smallexample
22194Interrupted while waiting for the program.
22195Give up (and stop debugging it)? (y or n)
22196@end smallexample
22197
19d9d4ef
DB
22198In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22199the remote debugging session. (If you decide you want to try again later,
22200you can use @kbd{target remote} again to connect once more.) If you type
22201@kbd{n}, @value{GDBN} goes back to waiting.
22202
22203In @code{target extended-remote} mode, typing @kbd{n} will leave
22204@value{GDBN} connected to the target.
07f31aa6
DJ
22205
22206@table @code
22207@kindex detach (remote)
22208@item detach
22209When you have finished debugging the remote program, you can use the
22210@code{detach} command to release it from @value{GDBN} control.
22211Detaching from the target normally resumes its execution, but the results
22212will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22213command in @code{target remote} mode, @value{GDBN} is free to connect to
22214another target. In @code{target extended-remote} mode, @value{GDBN} is
22215still connected to the target.
07f31aa6
DJ
22216
22217@kindex disconnect
22218@item disconnect
19d9d4ef 22219The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22220the target is generally not resumed. It will wait for @value{GDBN}
22221(this instance or another one) to connect and continue debugging. After
22222the @code{disconnect} command, @value{GDBN} is again free to connect to
22223another target.
09d4efe1
EZ
22224
22225@cindex send command to remote monitor
fad38dfa
EZ
22226@cindex extend @value{GDBN} for remote targets
22227@cindex add new commands for external monitor
09d4efe1
EZ
22228@kindex monitor
22229@item monitor @var{cmd}
fad38dfa
EZ
22230This command allows you to send arbitrary commands directly to the
22231remote monitor. Since @value{GDBN} doesn't care about the commands it
22232sends like this, this command is the way to extend @value{GDBN}---you
22233can add new commands that only the external monitor will understand
22234and implement.
07f31aa6
DJ
22235@end table
22236
a6b151f1
DJ
22237@node File Transfer
22238@section Sending files to a remote system
22239@cindex remote target, file transfer
22240@cindex file transfer
22241@cindex sending files to remote systems
22242
22243Some remote targets offer the ability to transfer files over the same
22244connection used to communicate with @value{GDBN}. This is convenient
22245for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22246running @code{gdbserver} over a network interface. For other targets,
22247e.g.@: embedded devices with only a single serial port, this may be
22248the only way to upload or download files.
22249
22250Not all remote targets support these commands.
22251
22252@table @code
22253@kindex remote put
22254@item remote put @var{hostfile} @var{targetfile}
22255Copy file @var{hostfile} from the host system (the machine running
22256@value{GDBN}) to @var{targetfile} on the target system.
22257
22258@kindex remote get
22259@item remote get @var{targetfile} @var{hostfile}
22260Copy file @var{targetfile} from the target system to @var{hostfile}
22261on the host system.
22262
22263@kindex remote delete
22264@item remote delete @var{targetfile}
22265Delete @var{targetfile} from the target system.
22266
22267@end table
22268
6f05cf9f 22269@node Server
79a6e687 22270@section Using the @code{gdbserver} Program
6f05cf9f
AC
22271
22272@kindex gdbserver
22273@cindex remote connection without stubs
22274@code{gdbserver} is a control program for Unix-like systems, which
22275allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22276@code{target remote} or @code{target extended-remote}---but without
22277linking in the usual debugging stub.
6f05cf9f
AC
22278
22279@code{gdbserver} is not a complete replacement for the debugging stubs,
22280because it requires essentially the same operating-system facilities
22281that @value{GDBN} itself does. In fact, a system that can run
22282@code{gdbserver} to connect to a remote @value{GDBN} could also run
22283@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22284because it is a much smaller program than @value{GDBN} itself. It is
22285also easier to port than all of @value{GDBN}, so you may be able to get
22286started more quickly on a new system by using @code{gdbserver}.
22287Finally, if you develop code for real-time systems, you may find that
22288the tradeoffs involved in real-time operation make it more convenient to
22289do as much development work as possible on another system, for example
22290by cross-compiling. You can use @code{gdbserver} to make a similar
22291choice for debugging.
22292
22293@value{GDBN} and @code{gdbserver} communicate via either a serial line
22294or a TCP connection, using the standard @value{GDBN} remote serial
22295protocol.
22296
2d717e4f
DJ
22297@quotation
22298@emph{Warning:} @code{gdbserver} does not have any built-in security.
22299Do not run @code{gdbserver} connected to any public network; a
22300@value{GDBN} connection to @code{gdbserver} provides access to the
22301target system with the same privileges as the user running
22302@code{gdbserver}.
22303@end quotation
22304
19d9d4ef 22305@anchor{Running gdbserver}
2d717e4f
DJ
22306@subsection Running @code{gdbserver}
22307@cindex arguments, to @code{gdbserver}
d9b1a651 22308@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22309
22310Run @code{gdbserver} on the target system. You need a copy of the
22311program you want to debug, including any libraries it requires.
6f05cf9f
AC
22312@code{gdbserver} does not need your program's symbol table, so you can
22313strip the program if necessary to save space. @value{GDBN} on the host
22314system does all the symbol handling.
22315
22316To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22317the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22318syntax is:
22319
22320@smallexample
22321target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22322@end smallexample
22323
6cf36756
SM
22324@var{comm} is either a device name (to use a serial line), or a TCP
22325hostname and portnumber, or @code{-} or @code{stdio} to use
22326stdin/stdout of @code{gdbserver}.
e0f9f062 22327For example, to debug Emacs with the argument
6f05cf9f
AC
22328@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22329@file{/dev/com1}:
22330
22331@smallexample
22332target> gdbserver /dev/com1 emacs foo.txt
22333@end smallexample
22334
6cf36756
SM
22335@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22336with it.
6f05cf9f
AC
22337
22338To use a TCP connection instead of a serial line:
22339
22340@smallexample
22341target> gdbserver host:2345 emacs foo.txt
22342@end smallexample
22343
22344The only difference from the previous example is the first argument,
22345specifying that you are communicating with the host @value{GDBN} via
22346TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22347expect a TCP connection from machine @samp{host} to local TCP port 2345.
22348(Currently, the @samp{host} part is ignored.) You can choose any number
22349you want for the port number as long as it does not conflict with any
22350TCP ports already in use on the target system (for example, @code{23} is
22351reserved for @code{telnet}).@footnote{If you choose a port number that
22352conflicts with another service, @code{gdbserver} prints an error message
22353and exits.} You must use the same port number with the host @value{GDBN}
22354@code{target remote} command.
22355
6cf36756
SM
22356The @code{stdio} connection is useful when starting @code{gdbserver}
22357with ssh:
e0f9f062
DE
22358
22359@smallexample
6cf36756 22360(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22361@end smallexample
22362
6cf36756
SM
22363The @samp{-T} option to ssh is provided because we don't need a remote pty,
22364and we don't want escape-character handling. Ssh does this by default when
22365a command is provided, the flag is provided to make it explicit.
22366You could elide it if you want to.
e0f9f062 22367
6cf36756
SM
22368Programs started with stdio-connected gdbserver have @file{/dev/null} for
22369@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22370display through a pipe connected to gdbserver.
22371Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22372
19d9d4ef 22373@anchor{Attaching to a program}
2d717e4f 22374@subsubsection Attaching to a Running Program
d9b1a651
EZ
22375@cindex attach to a program, @code{gdbserver}
22376@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22377
56460a61
DJ
22378On some targets, @code{gdbserver} can also attach to running programs.
22379This is accomplished via the @code{--attach} argument. The syntax is:
22380
22381@smallexample
2d717e4f 22382target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22383@end smallexample
22384
19d9d4ef
DB
22385@var{pid} is the process ID of a currently running process. It isn't
22386necessary to point @code{gdbserver} at a binary for the running process.
22387
22388In @code{target extended-remote} mode, you can also attach using the
22389@value{GDBN} attach command
22390(@pxref{Attaching in Types of Remote Connections}).
56460a61 22391
b1fe9455 22392@pindex pidof
b1fe9455
DJ
22393You can debug processes by name instead of process ID if your target has the
22394@code{pidof} utility:
22395
22396@smallexample
2d717e4f 22397target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22398@end smallexample
22399
f822c95b 22400In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22401has multiple threads, most versions of @code{pidof} support the
22402@code{-s} option to only return the first process ID.
22403
03f2bd59
JK
22404@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22405
19d9d4ef
DB
22406This section applies only when @code{gdbserver} is run to listen on a TCP
22407port.
03f2bd59
JK
22408
22409@code{gdbserver} normally terminates after all of its debugged processes have
22410terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22411extended-remote}, @code{gdbserver} stays running even with no processes left.
22412@value{GDBN} normally terminates the spawned debugged process on its exit,
22413which normally also terminates @code{gdbserver} in the @kbd{target remote}
22414mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22415cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22416stays running even in the @kbd{target remote} mode.
22417
22418When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22419Such reconnecting is useful for features like @ref{disconnected tracing}. For
22420completeness, at most one @value{GDBN} can be connected at a time.
22421
22422@cindex @option{--once}, @code{gdbserver} option
22423By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22424subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22425with the @option{--once} option, it will stop listening for any further
22426connection attempts after connecting to the first @value{GDBN} session. This
22427means no further connections to @code{gdbserver} will be possible after the
22428first one. It also means @code{gdbserver} will terminate after the first
22429connection with remote @value{GDBN} has closed, even for unexpectedly closed
22430connections and even in the @kbd{target extended-remote} mode. The
22431@option{--once} option allows reusing the same port number for connecting to
22432multiple instances of @code{gdbserver} running on the same host, since each
22433instance closes its port after the first connection.
2d717e4f 22434
87ce2a04 22435@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22436@subsubsection Other Command-Line Arguments for @code{gdbserver}
22437
19d9d4ef
DB
22438You can use the @option{--multi} option to start @code{gdbserver} without
22439specifying a program to debug or a process to attach to. Then you can
22440attach in @code{target extended-remote} mode and run or attach to a
22441program. For more information,
22442@pxref{--multi Option in Types of Remote Connnections}.
22443
d9b1a651 22444@cindex @option{--debug}, @code{gdbserver} option
62709adf 22445The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22446status information about the debugging process.
22447@cindex @option{--remote-debug}, @code{gdbserver} option
22448The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22449remote protocol debug output.
22450@cindex @option{--debug-file}, @code{gdbserver} option
22451@cindex @code{gdbserver}, send all debug output to a single file
22452The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22453write any debug output to the given @var{filename}. These options are intended
22454for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22455
87ce2a04
DE
22456@cindex @option{--debug-format}, @code{gdbserver} option
22457The @option{--debug-format=option1[,option2,...]} option tells
22458@code{gdbserver} to include additional information in each output.
22459Possible options are:
22460
22461@table @code
22462@item none
22463Turn off all extra information in debugging output.
22464@item all
22465Turn on all extra information in debugging output.
22466@item timestamps
22467Include a timestamp in each line of debugging output.
22468@end table
22469
22470Options are processed in order. Thus, for example, if @option{none}
22471appears last then no additional information is added to debugging output.
22472
d9b1a651 22473@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22474The @option{--wrapper} option specifies a wrapper to launch programs
22475for debugging. The option should be followed by the name of the
22476wrapper, then any command-line arguments to pass to the wrapper, then
22477@kbd{--} indicating the end of the wrapper arguments.
22478
22479@code{gdbserver} runs the specified wrapper program with a combined
22480command line including the wrapper arguments, then the name of the
22481program to debug, then any arguments to the program. The wrapper
22482runs until it executes your program, and then @value{GDBN} gains control.
22483
22484You can use any program that eventually calls @code{execve} with
22485its arguments as a wrapper. Several standard Unix utilities do
22486this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22487with @code{exec "$@@"} will also work.
22488
22489For example, you can use @code{env} to pass an environment variable to
22490the debugged program, without setting the variable in @code{gdbserver}'s
22491environment:
22492
22493@smallexample
22494$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22495@end smallexample
22496
6d580b63
YQ
22497@cindex @option{--selftest}
22498The @option{--selftest} option runs the self tests in @code{gdbserver}:
22499
22500@smallexample
22501$ gdbserver --selftest
22502Ran 2 unit tests, 0 failed
22503@end smallexample
22504
22505These tests are disabled in release.
2d717e4f
DJ
22506@subsection Connecting to @code{gdbserver}
22507
19d9d4ef
DB
22508The basic procedure for connecting to the remote target is:
22509@itemize
2d717e4f 22510
19d9d4ef
DB
22511@item
22512Run @value{GDBN} on the host system.
f822c95b 22513
19d9d4ef
DB
22514@item
22515Make sure you have the necessary symbol files
22516(@pxref{Host and target files}).
22517Load symbols for your application using the @code{file} command before you
22518connect. Use @code{set sysroot} to locate target libraries (unless your
22519@value{GDBN} was compiled with the correct sysroot using
22520@code{--with-sysroot}).
f822c95b 22521
19d9d4ef 22522@item
79a6e687 22523Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22524For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22525the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22526text depends on the host system, but which usually looks something like
2d717e4f 22527@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22528command in @value{GDBN} when using @code{target remote} mode, since the
22529program is already on the target.
22530
22531@end itemize
07f31aa6 22532
19d9d4ef 22533@anchor{Monitor Commands for gdbserver}
79a6e687 22534@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22535@cindex monitor commands, for @code{gdbserver}
22536
22537During a @value{GDBN} session using @code{gdbserver}, you can use the
22538@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22539Here are the available commands.
c74d0ad8
DJ
22540
22541@table @code
22542@item monitor help
22543List the available monitor commands.
22544
22545@item monitor set debug 0
22546@itemx monitor set debug 1
22547Disable or enable general debugging messages.
22548
22549@item monitor set remote-debug 0
22550@itemx monitor set remote-debug 1
22551Disable or enable specific debugging messages associated with the remote
22552protocol (@pxref{Remote Protocol}).
22553
aeb2e706
AH
22554@item monitor set debug-file filename
22555@itemx monitor set debug-file
22556Send any debug output to the given file, or to stderr.
22557
87ce2a04
DE
22558@item monitor set debug-format option1@r{[},option2,...@r{]}
22559Specify additional text to add to debugging messages.
22560Possible options are:
22561
22562@table @code
22563@item none
22564Turn off all extra information in debugging output.
22565@item all
22566Turn on all extra information in debugging output.
22567@item timestamps
22568Include a timestamp in each line of debugging output.
22569@end table
22570
22571Options are processed in order. Thus, for example, if @option{none}
22572appears last then no additional information is added to debugging output.
22573
cdbfd419
PP
22574@item monitor set libthread-db-search-path [PATH]
22575@cindex gdbserver, search path for @code{libthread_db}
22576When this command is issued, @var{path} is a colon-separated list of
22577directories to search for @code{libthread_db} (@pxref{Threads,,set
22578libthread-db-search-path}). If you omit @var{path},
84e578fb 22579@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22580
98a5dd13
DE
22581The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22582not supported in @code{gdbserver}.
22583
2d717e4f
DJ
22584@item monitor exit
22585Tell gdbserver to exit immediately. This command should be followed by
22586@code{disconnect} to close the debugging session. @code{gdbserver} will
22587detach from any attached processes and kill any processes it created.
22588Use @code{monitor exit} to terminate @code{gdbserver} at the end
22589of a multi-process mode debug session.
22590
c74d0ad8
DJ
22591@end table
22592
fa593d66
PA
22593@subsection Tracepoints support in @code{gdbserver}
22594@cindex tracepoints support in @code{gdbserver}
22595
0fb4aa4b
PA
22596On some targets, @code{gdbserver} supports tracepoints, fast
22597tracepoints and static tracepoints.
fa593d66 22598
0fb4aa4b 22599For fast or static tracepoints to work, a special library called the
fa593d66
PA
22600@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22601This library is built and distributed as an integral part of
0fb4aa4b
PA
22602@code{gdbserver}. In addition, support for static tracepoints
22603requires building the in-process agent library with static tracepoints
22604support. At present, the UST (LTTng Userspace Tracer,
22605@url{http://lttng.org/ust}) tracing engine is supported. This support
22606is automatically available if UST development headers are found in the
22607standard include path when @code{gdbserver} is built, or if
22608@code{gdbserver} was explicitly configured using @option{--with-ust}
22609to point at such headers. You can explicitly disable the support
22610using @option{--with-ust=no}.
fa593d66
PA
22611
22612There are several ways to load the in-process agent in your program:
22613
22614@table @code
22615@item Specifying it as dependency at link time
22616
22617You can link your program dynamically with the in-process agent
22618library. On most systems, this is accomplished by adding
22619@code{-linproctrace} to the link command.
22620
22621@item Using the system's preloading mechanisms
22622
22623You can force loading the in-process agent at startup time by using
22624your system's support for preloading shared libraries. Many Unixes
22625support the concept of preloading user defined libraries. In most
22626cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22627in the environment. See also the description of @code{gdbserver}'s
22628@option{--wrapper} command line option.
22629
22630@item Using @value{GDBN} to force loading the agent at run time
22631
22632On some systems, you can force the inferior to load a shared library,
22633by calling a dynamic loader function in the inferior that takes care
22634of dynamically looking up and loading a shared library. On most Unix
22635systems, the function is @code{dlopen}. You'll use the @code{call}
22636command for that. For example:
22637
22638@smallexample
22639(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22640@end smallexample
22641
22642Note that on most Unix systems, for the @code{dlopen} function to be
22643available, the program needs to be linked with @code{-ldl}.
22644@end table
22645
22646On systems that have a userspace dynamic loader, like most Unix
22647systems, when you connect to @code{gdbserver} using @code{target
22648remote}, you'll find that the program is stopped at the dynamic
22649loader's entry point, and no shared library has been loaded in the
22650program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22651case, before being able to use any of the fast or static tracepoints
22652features, you need to let the loader run and load the shared
22653libraries. The simplest way to do that is to run the program to the
22654main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22655@code{gdbserver} like so:
22656
22657@smallexample
22658$ gdbserver :9999 myprogram
22659@end smallexample
22660
22661Start GDB and connect to @code{gdbserver} like so, and run to main:
22662
22663@smallexample
22664$ gdb myprogram
22665(@value{GDBP}) target remote myhost:9999
226660x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22667(@value{GDBP}) b main
22668(@value{GDBP}) continue
22669@end smallexample
22670
22671The in-process tracing agent library should now be loaded into the
22672process; you can confirm it with the @code{info sharedlibrary}
22673command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22674process. You are now ready to install fast tracepoints, list static
22675tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22676tracing.
22677
79a6e687
BW
22678@node Remote Configuration
22679@section Remote Configuration
501eef12 22680
9c16f35a
EZ
22681@kindex set remote
22682@kindex show remote
22683This section documents the configuration options available when
22684debugging remote programs. For the options related to the File I/O
fc320d37 22685extensions of the remote protocol, see @ref{system,
9c16f35a 22686system-call-allowed}.
501eef12
AC
22687
22688@table @code
9c16f35a 22689@item set remoteaddresssize @var{bits}
d3e8051b 22690@cindex address size for remote targets
9c16f35a
EZ
22691@cindex bits in remote address
22692Set the maximum size of address in a memory packet to the specified
22693number of bits. @value{GDBN} will mask off the address bits above
22694that number, when it passes addresses to the remote target. The
22695default value is the number of bits in the target's address.
22696
22697@item show remoteaddresssize
22698Show the current value of remote address size in bits.
22699
0d12017b 22700@item set serial baud @var{n}
9c16f35a
EZ
22701@cindex baud rate for remote targets
22702Set the baud rate for the remote serial I/O to @var{n} baud. The
22703value is used to set the speed of the serial port used for debugging
22704remote targets.
22705
0d12017b 22706@item show serial baud
9c16f35a
EZ
22707Show the current speed of the remote connection.
22708
236af5e3
YG
22709@item set serial parity @var{parity}
22710Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22711@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22712
22713@item show serial parity
22714Show the current parity of the serial port.
22715
9c16f35a
EZ
22716@item set remotebreak
22717@cindex interrupt remote programs
22718@cindex BREAK signal instead of Ctrl-C
9a6253be 22719@anchor{set remotebreak}
9c16f35a 22720If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22721when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22722on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22723character instead. The default is off, since most remote systems
22724expect to see @samp{Ctrl-C} as the interrupt signal.
22725
22726@item show remotebreak
22727Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22728interrupt the remote program.
22729
23776285
MR
22730@item set remoteflow on
22731@itemx set remoteflow off
22732@kindex set remoteflow
22733Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22734on the serial port used to communicate to the remote target.
22735
22736@item show remoteflow
22737@kindex show remoteflow
22738Show the current setting of hardware flow control.
22739
9c16f35a
EZ
22740@item set remotelogbase @var{base}
22741Set the base (a.k.a.@: radix) of logging serial protocol
22742communications to @var{base}. Supported values of @var{base} are:
22743@code{ascii}, @code{octal}, and @code{hex}. The default is
22744@code{ascii}.
22745
22746@item show remotelogbase
22747Show the current setting of the radix for logging remote serial
22748protocol.
22749
22750@item set remotelogfile @var{file}
22751@cindex record serial communications on file
22752Record remote serial communications on the named @var{file}. The
22753default is not to record at all.
22754
2d8b6830 22755@item show remotelogfile
9c16f35a
EZ
22756Show the current setting of the file name on which to record the
22757serial communications.
22758
22759@item set remotetimeout @var{num}
22760@cindex timeout for serial communications
22761@cindex remote timeout
22762Set the timeout limit to wait for the remote target to respond to
22763@var{num} seconds. The default is 2 seconds.
22764
22765@item show remotetimeout
22766Show the current number of seconds to wait for the remote target
22767responses.
22768
22769@cindex limit hardware breakpoints and watchpoints
22770@cindex remote target, limit break- and watchpoints
501eef12
AC
22771@anchor{set remote hardware-watchpoint-limit}
22772@anchor{set remote hardware-breakpoint-limit}
22773@item set remote hardware-watchpoint-limit @var{limit}
22774@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22775Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22776or breakpoints. The @var{limit} can be set to 0 to disable hardware
22777watchpoints or breakpoints, and @code{unlimited} for unlimited
22778watchpoints or breakpoints.
22779
22780@item show remote hardware-watchpoint-limit
22781@itemx show remote hardware-breakpoint-limit
22782Show the current limit for the number of hardware watchpoints or
22783breakpoints that @value{GDBN} can use.
2d717e4f 22784
480a3f21
PW
22785@cindex limit hardware watchpoints length
22786@cindex remote target, limit watchpoints length
22787@anchor{set remote hardware-watchpoint-length-limit}
22788@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22789Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22790length of a remote hardware watchpoint. A @var{limit} of 0 disables
22791hardware watchpoints and @code{unlimited} allows watchpoints of any
22792length.
480a3f21
PW
22793
22794@item show remote hardware-watchpoint-length-limit
22795Show the current limit (in bytes) of the maximum length of
22796a remote hardware watchpoint.
22797
2d717e4f
DJ
22798@item set remote exec-file @var{filename}
22799@itemx show remote exec-file
22800@anchor{set remote exec-file}
22801@cindex executable file, for remote target
22802Select the file used for @code{run} with @code{target
22803extended-remote}. This should be set to a filename valid on the
22804target system. If it is not set, the target will use a default
22805filename (e.g.@: the last program run).
84603566 22806
9a7071a8
JB
22807@item set remote interrupt-sequence
22808@cindex interrupt remote programs
22809@cindex select Ctrl-C, BREAK or BREAK-g
22810Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22811@samp{BREAK-g} as the
22812sequence to the remote target in order to interrupt the execution.
22813@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22814is high level of serial line for some certain time.
22815Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22816It is @code{BREAK} signal followed by character @code{g}.
22817
22818@item show interrupt-sequence
22819Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22820is sent by @value{GDBN} to interrupt the remote program.
22821@code{BREAK-g} is BREAK signal followed by @code{g} and
22822also known as Magic SysRq g.
22823
22824@item set remote interrupt-on-connect
22825@cindex send interrupt-sequence on start
22826Specify whether interrupt-sequence is sent to remote target when
22827@value{GDBN} connects to it. This is mostly needed when you debug
22828Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22829which is known as Magic SysRq g in order to connect @value{GDBN}.
22830
22831@item show interrupt-on-connect
22832Show whether interrupt-sequence is sent
22833to remote target when @value{GDBN} connects to it.
22834
84603566
SL
22835@kindex set tcp
22836@kindex show tcp
22837@item set tcp auto-retry on
22838@cindex auto-retry, for remote TCP target
22839Enable auto-retry for remote TCP connections. This is useful if the remote
22840debugging agent is launched in parallel with @value{GDBN}; there is a race
22841condition because the agent may not become ready to accept the connection
22842before @value{GDBN} attempts to connect. When auto-retry is
22843enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22844to establish the connection using the timeout specified by
22845@code{set tcp connect-timeout}.
22846
22847@item set tcp auto-retry off
22848Do not auto-retry failed TCP connections.
22849
22850@item show tcp auto-retry
22851Show the current auto-retry setting.
22852
22853@item set tcp connect-timeout @var{seconds}
f81d1120 22854@itemx set tcp connect-timeout unlimited
84603566
SL
22855@cindex connection timeout, for remote TCP target
22856@cindex timeout, for remote target connection
22857Set the timeout for establishing a TCP connection to the remote target to
22858@var{seconds}. The timeout affects both polling to retry failed connections
22859(enabled by @code{set tcp auto-retry on}) and waiting for connections
22860that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
22861value. If @var{seconds} is @code{unlimited}, there is no timeout and
22862@value{GDBN} will keep attempting to establish a connection forever,
22863unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
22864
22865@item show tcp connect-timeout
22866Show the current connection timeout setting.
501eef12
AC
22867@end table
22868
427c3a89
DJ
22869@cindex remote packets, enabling and disabling
22870The @value{GDBN} remote protocol autodetects the packets supported by
22871your debugging stub. If you need to override the autodetection, you
22872can use these commands to enable or disable individual packets. Each
22873packet can be set to @samp{on} (the remote target supports this
22874packet), @samp{off} (the remote target does not support this packet),
22875or @samp{auto} (detect remote target support for this packet). They
22876all default to @samp{auto}. For more information about each packet,
22877see @ref{Remote Protocol}.
22878
22879During normal use, you should not have to use any of these commands.
22880If you do, that may be a bug in your remote debugging stub, or a bug
22881in @value{GDBN}. You may want to report the problem to the
22882@value{GDBN} developers.
22883
cfa9d6d9
DJ
22884For each packet @var{name}, the command to enable or disable the
22885packet is @code{set remote @var{name}-packet}. The available settings
22886are:
427c3a89 22887
cfa9d6d9 22888@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
22889@item Command Name
22890@tab Remote Packet
22891@tab Related Features
22892
cfa9d6d9 22893@item @code{fetch-register}
427c3a89
DJ
22894@tab @code{p}
22895@tab @code{info registers}
22896
cfa9d6d9 22897@item @code{set-register}
427c3a89
DJ
22898@tab @code{P}
22899@tab @code{set}
22900
cfa9d6d9 22901@item @code{binary-download}
427c3a89
DJ
22902@tab @code{X}
22903@tab @code{load}, @code{set}
22904
cfa9d6d9 22905@item @code{read-aux-vector}
427c3a89
DJ
22906@tab @code{qXfer:auxv:read}
22907@tab @code{info auxv}
22908
cfa9d6d9 22909@item @code{symbol-lookup}
427c3a89
DJ
22910@tab @code{qSymbol}
22911@tab Detecting multiple threads
22912
2d717e4f
DJ
22913@item @code{attach}
22914@tab @code{vAttach}
22915@tab @code{attach}
22916
cfa9d6d9 22917@item @code{verbose-resume}
427c3a89
DJ
22918@tab @code{vCont}
22919@tab Stepping or resuming multiple threads
22920
2d717e4f
DJ
22921@item @code{run}
22922@tab @code{vRun}
22923@tab @code{run}
22924
cfa9d6d9 22925@item @code{software-breakpoint}
427c3a89
DJ
22926@tab @code{Z0}
22927@tab @code{break}
22928
cfa9d6d9 22929@item @code{hardware-breakpoint}
427c3a89
DJ
22930@tab @code{Z1}
22931@tab @code{hbreak}
22932
cfa9d6d9 22933@item @code{write-watchpoint}
427c3a89
DJ
22934@tab @code{Z2}
22935@tab @code{watch}
22936
cfa9d6d9 22937@item @code{read-watchpoint}
427c3a89
DJ
22938@tab @code{Z3}
22939@tab @code{rwatch}
22940
cfa9d6d9 22941@item @code{access-watchpoint}
427c3a89
DJ
22942@tab @code{Z4}
22943@tab @code{awatch}
22944
c78fa86a
GB
22945@item @code{pid-to-exec-file}
22946@tab @code{qXfer:exec-file:read}
22947@tab @code{attach}, @code{run}
22948
cfa9d6d9
DJ
22949@item @code{target-features}
22950@tab @code{qXfer:features:read}
22951@tab @code{set architecture}
22952
22953@item @code{library-info}
22954@tab @code{qXfer:libraries:read}
22955@tab @code{info sharedlibrary}
22956
22957@item @code{memory-map}
22958@tab @code{qXfer:memory-map:read}
22959@tab @code{info mem}
22960
0fb4aa4b
PA
22961@item @code{read-sdata-object}
22962@tab @code{qXfer:sdata:read}
22963@tab @code{print $_sdata}
22964
4aa995e1
PA
22965@item @code{read-siginfo-object}
22966@tab @code{qXfer:siginfo:read}
22967@tab @code{print $_siginfo}
22968
22969@item @code{write-siginfo-object}
22970@tab @code{qXfer:siginfo:write}
22971@tab @code{set $_siginfo}
22972
dc146f7c
VP
22973@item @code{threads}
22974@tab @code{qXfer:threads:read}
22975@tab @code{info threads}
22976
cfa9d6d9 22977@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
22978@tab @code{qGetTLSAddr}
22979@tab Displaying @code{__thread} variables
22980
711e434b
PM
22981@item @code{get-thread-information-block-address}
22982@tab @code{qGetTIBAddr}
22983@tab Display MS-Windows Thread Information Block.
22984
08388c79
DE
22985@item @code{search-memory}
22986@tab @code{qSearch:memory}
22987@tab @code{find}
22988
427c3a89
DJ
22989@item @code{supported-packets}
22990@tab @code{qSupported}
22991@tab Remote communications parameters
22992
82075af2
JS
22993@item @code{catch-syscalls}
22994@tab @code{QCatchSyscalls}
22995@tab @code{catch syscall}
22996
cfa9d6d9 22997@item @code{pass-signals}
89be2091
DJ
22998@tab @code{QPassSignals}
22999@tab @code{handle @var{signal}}
23000
9b224c5e
PA
23001@item @code{program-signals}
23002@tab @code{QProgramSignals}
23003@tab @code{handle @var{signal}}
23004
a6b151f1
DJ
23005@item @code{hostio-close-packet}
23006@tab @code{vFile:close}
23007@tab @code{remote get}, @code{remote put}
23008
23009@item @code{hostio-open-packet}
23010@tab @code{vFile:open}
23011@tab @code{remote get}, @code{remote put}
23012
23013@item @code{hostio-pread-packet}
23014@tab @code{vFile:pread}
23015@tab @code{remote get}, @code{remote put}
23016
23017@item @code{hostio-pwrite-packet}
23018@tab @code{vFile:pwrite}
23019@tab @code{remote get}, @code{remote put}
23020
23021@item @code{hostio-unlink-packet}
23022@tab @code{vFile:unlink}
23023@tab @code{remote delete}
a6f3e723 23024
b9e7b9c3
UW
23025@item @code{hostio-readlink-packet}
23026@tab @code{vFile:readlink}
23027@tab Host I/O
23028
0a93529c
GB
23029@item @code{hostio-fstat-packet}
23030@tab @code{vFile:fstat}
23031@tab Host I/O
23032
15a201c8
GB
23033@item @code{hostio-setfs-packet}
23034@tab @code{vFile:setfs}
23035@tab Host I/O
23036
a6f3e723
SL
23037@item @code{noack-packet}
23038@tab @code{QStartNoAckMode}
23039@tab Packet acknowledgment
07e059b5
VP
23040
23041@item @code{osdata}
23042@tab @code{qXfer:osdata:read}
23043@tab @code{info os}
0b16c5cf
PA
23044
23045@item @code{query-attached}
23046@tab @code{qAttached}
23047@tab Querying remote process attach state.
b3b9301e 23048
a46c1e42
PA
23049@item @code{trace-buffer-size}
23050@tab @code{QTBuffer:size}
23051@tab @code{set trace-buffer-size}
23052
bd3eecc3
PA
23053@item @code{trace-status}
23054@tab @code{qTStatus}
23055@tab @code{tstatus}
23056
b3b9301e
PA
23057@item @code{traceframe-info}
23058@tab @code{qXfer:traceframe-info:read}
23059@tab Traceframe info
03583c20 23060
1e4d1764
YQ
23061@item @code{install-in-trace}
23062@tab @code{InstallInTrace}
23063@tab Install tracepoint in tracing
23064
03583c20
UW
23065@item @code{disable-randomization}
23066@tab @code{QDisableRandomization}
23067@tab @code{set disable-randomization}
83364271 23068
aefd8b33
SDJ
23069@item @code{startup-with-shell}
23070@tab @code{QStartupWithShell}
23071@tab @code{set startup-with-shell}
23072
0a2dde4a
SDJ
23073@item @code{environment-hex-encoded}
23074@tab @code{QEnvironmentHexEncoded}
23075@tab @code{set environment}
23076
23077@item @code{environment-unset}
23078@tab @code{QEnvironmentUnset}
23079@tab @code{unset environment}
23080
23081@item @code{environment-reset}
23082@tab @code{QEnvironmentReset}
23083@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23084
bc3b087d
SDJ
23085@item @code{set-working-dir}
23086@tab @code{QSetWorkingDir}
23087@tab @code{set cwd}
23088
83364271
LM
23089@item @code{conditional-breakpoints-packet}
23090@tab @code{Z0 and Z1}
23091@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 23092
73b8c1fd
PA
23093@item @code{multiprocess-extensions}
23094@tab @code{multiprocess extensions}
23095@tab Debug multiple processes and remote process PID awareness
23096
f7e6eed5
PA
23097@item @code{swbreak-feature}
23098@tab @code{swbreak stop reason}
23099@tab @code{break}
23100
23101@item @code{hwbreak-feature}
23102@tab @code{hwbreak stop reason}
23103@tab @code{hbreak}
23104
0d71eef5
DB
23105@item @code{fork-event-feature}
23106@tab @code{fork stop reason}
23107@tab @code{fork}
23108
23109@item @code{vfork-event-feature}
23110@tab @code{vfork stop reason}
23111@tab @code{vfork}
23112
b459a59b
DB
23113@item @code{exec-event-feature}
23114@tab @code{exec stop reason}
23115@tab @code{exec}
23116
65706a29
PA
23117@item @code{thread-events}
23118@tab @code{QThreadEvents}
23119@tab Tracking thread lifetime.
23120
f2faf941
PA
23121@item @code{no-resumed-stop-reply}
23122@tab @code{no resumed thread left stop reply}
23123@tab Tracking thread lifetime.
23124
427c3a89
DJ
23125@end multitable
23126
79a6e687
BW
23127@node Remote Stub
23128@section Implementing a Remote Stub
7a292a7a 23129
8e04817f
AC
23130@cindex debugging stub, example
23131@cindex remote stub, example
23132@cindex stub example, remote debugging
23133The stub files provided with @value{GDBN} implement the target side of the
23134communication protocol, and the @value{GDBN} side is implemented in the
23135@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23136these subroutines to communicate, and ignore the details. (If you're
23137implementing your own stub file, you can still ignore the details: start
23138with one of the existing stub files. @file{sparc-stub.c} is the best
23139organized, and therefore the easiest to read.)
23140
104c1213
JM
23141@cindex remote serial debugging, overview
23142To debug a program running on another machine (the debugging
23143@dfn{target} machine), you must first arrange for all the usual
23144prerequisites for the program to run by itself. For example, for a C
23145program, you need:
c906108c 23146
104c1213
JM
23147@enumerate
23148@item
23149A startup routine to set up the C runtime environment; these usually
23150have a name like @file{crt0}. The startup routine may be supplied by
23151your hardware supplier, or you may have to write your own.
96baa820 23152
5d161b24 23153@item
d4f3574e 23154A C subroutine library to support your program's
104c1213 23155subroutine calls, notably managing input and output.
96baa820 23156
104c1213
JM
23157@item
23158A way of getting your program to the other machine---for example, a
23159download program. These are often supplied by the hardware
23160manufacturer, but you may have to write your own from hardware
23161documentation.
23162@end enumerate
96baa820 23163
104c1213
JM
23164The next step is to arrange for your program to use a serial port to
23165communicate with the machine where @value{GDBN} is running (the @dfn{host}
23166machine). In general terms, the scheme looks like this:
96baa820 23167
104c1213
JM
23168@table @emph
23169@item On the host,
23170@value{GDBN} already understands how to use this protocol; when everything
23171else is set up, you can simply use the @samp{target remote} command
23172(@pxref{Targets,,Specifying a Debugging Target}).
23173
23174@item On the target,
23175you must link with your program a few special-purpose subroutines that
23176implement the @value{GDBN} remote serial protocol. The file containing these
23177subroutines is called a @dfn{debugging stub}.
23178
23179On certain remote targets, you can use an auxiliary program
23180@code{gdbserver} instead of linking a stub into your program.
79a6e687 23181@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23182@end table
96baa820 23183
104c1213
JM
23184The debugging stub is specific to the architecture of the remote
23185machine; for example, use @file{sparc-stub.c} to debug programs on
23186@sc{sparc} boards.
96baa820 23187
104c1213
JM
23188@cindex remote serial stub list
23189These working remote stubs are distributed with @value{GDBN}:
96baa820 23190
104c1213
JM
23191@table @code
23192
23193@item i386-stub.c
41afff9a 23194@cindex @file{i386-stub.c}
104c1213
JM
23195@cindex Intel
23196@cindex i386
23197For Intel 386 and compatible architectures.
23198
23199@item m68k-stub.c
41afff9a 23200@cindex @file{m68k-stub.c}
104c1213
JM
23201@cindex Motorola 680x0
23202@cindex m680x0
23203For Motorola 680x0 architectures.
23204
23205@item sh-stub.c
41afff9a 23206@cindex @file{sh-stub.c}
172c2a43 23207@cindex Renesas
104c1213 23208@cindex SH
172c2a43 23209For Renesas SH architectures.
104c1213
JM
23210
23211@item sparc-stub.c
41afff9a 23212@cindex @file{sparc-stub.c}
104c1213
JM
23213@cindex Sparc
23214For @sc{sparc} architectures.
23215
23216@item sparcl-stub.c
41afff9a 23217@cindex @file{sparcl-stub.c}
104c1213
JM
23218@cindex Fujitsu
23219@cindex SparcLite
23220For Fujitsu @sc{sparclite} architectures.
23221
23222@end table
23223
23224The @file{README} file in the @value{GDBN} distribution may list other
23225recently added stubs.
23226
23227@menu
23228* Stub Contents:: What the stub can do for you
23229* Bootstrapping:: What you must do for the stub
23230* Debug Session:: Putting it all together
104c1213
JM
23231@end menu
23232
6d2ebf8b 23233@node Stub Contents
79a6e687 23234@subsection What the Stub Can Do for You
104c1213
JM
23235
23236@cindex remote serial stub
23237The debugging stub for your architecture supplies these three
23238subroutines:
23239
23240@table @code
23241@item set_debug_traps
4644b6e3 23242@findex set_debug_traps
104c1213
JM
23243@cindex remote serial stub, initialization
23244This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23245program stops. You must call this subroutine explicitly in your
23246program's startup code.
104c1213
JM
23247
23248@item handle_exception
4644b6e3 23249@findex handle_exception
104c1213
JM
23250@cindex remote serial stub, main routine
23251This is the central workhorse, but your program never calls it
23252explicitly---the setup code arranges for @code{handle_exception} to
23253run when a trap is triggered.
23254
23255@code{handle_exception} takes control when your program stops during
23256execution (for example, on a breakpoint), and mediates communications
23257with @value{GDBN} on the host machine. This is where the communications
23258protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23259representative on the target machine. It begins by sending summary
104c1213
JM
23260information on the state of your program, then continues to execute,
23261retrieving and transmitting any information @value{GDBN} needs, until you
23262execute a @value{GDBN} command that makes your program resume; at that point,
23263@code{handle_exception} returns control to your own code on the target
5d161b24 23264machine.
104c1213
JM
23265
23266@item breakpoint
23267@cindex @code{breakpoint} subroutine, remote
23268Use this auxiliary subroutine to make your program contain a
23269breakpoint. Depending on the particular situation, this may be the only
23270way for @value{GDBN} to get control. For instance, if your target
23271machine has some sort of interrupt button, you won't need to call this;
23272pressing the interrupt button transfers control to
23273@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23274simply receiving characters on the serial port may also trigger a trap;
23275again, in that situation, you don't need to call @code{breakpoint} from
23276your own program---simply running @samp{target remote} from the host
5d161b24 23277@value{GDBN} session gets control.
104c1213
JM
23278
23279Call @code{breakpoint} if none of these is true, or if you simply want
23280to make certain your program stops at a predetermined point for the
23281start of your debugging session.
23282@end table
23283
6d2ebf8b 23284@node Bootstrapping
79a6e687 23285@subsection What You Must Do for the Stub
104c1213
JM
23286
23287@cindex remote stub, support routines
23288The debugging stubs that come with @value{GDBN} are set up for a particular
23289chip architecture, but they have no information about the rest of your
23290debugging target machine.
23291
23292First of all you need to tell the stub how to communicate with the
23293serial port.
23294
23295@table @code
23296@item int getDebugChar()
4644b6e3 23297@findex getDebugChar
104c1213
JM
23298Write this subroutine to read a single character from the serial port.
23299It may be identical to @code{getchar} for your target system; a
23300different name is used to allow you to distinguish the two if you wish.
23301
23302@item void putDebugChar(int)
4644b6e3 23303@findex putDebugChar
104c1213 23304Write this subroutine to write a single character to the serial port.
5d161b24 23305It may be identical to @code{putchar} for your target system; a
104c1213
JM
23306different name is used to allow you to distinguish the two if you wish.
23307@end table
23308
23309@cindex control C, and remote debugging
23310@cindex interrupting remote targets
23311If you want @value{GDBN} to be able to stop your program while it is
23312running, you need to use an interrupt-driven serial driver, and arrange
23313for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23314character). That is the character which @value{GDBN} uses to tell the
23315remote system to stop.
23316
23317Getting the debugging target to return the proper status to @value{GDBN}
23318probably requires changes to the standard stub; one quick and dirty way
23319is to just execute a breakpoint instruction (the ``dirty'' part is that
23320@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23321
23322Other routines you need to supply are:
23323
23324@table @code
23325@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23326@findex exceptionHandler
104c1213
JM
23327Write this function to install @var{exception_address} in the exception
23328handling tables. You need to do this because the stub does not have any
23329way of knowing what the exception handling tables on your target system
23330are like (for example, the processor's table might be in @sc{rom},
23331containing entries which point to a table in @sc{ram}).
697aa1b7 23332The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23333its meaning is architecture-dependent (for example, different numbers
23334might represent divide by zero, misaligned access, etc). When this
23335exception occurs, control should be transferred directly to
23336@var{exception_address}, and the processor state (stack, registers,
23337and so on) should be just as it is when a processor exception occurs. So if
23338you want to use a jump instruction to reach @var{exception_address}, it
23339should be a simple jump, not a jump to subroutine.
23340
23341For the 386, @var{exception_address} should be installed as an interrupt
23342gate so that interrupts are masked while the handler runs. The gate
23343should be at privilege level 0 (the most privileged level). The
23344@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23345help from @code{exceptionHandler}.
23346
23347@item void flush_i_cache()
4644b6e3 23348@findex flush_i_cache
d4f3574e 23349On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23350instruction cache, if any, on your target machine. If there is no
23351instruction cache, this subroutine may be a no-op.
23352
23353On target machines that have instruction caches, @value{GDBN} requires this
23354function to make certain that the state of your program is stable.
23355@end table
23356
23357@noindent
23358You must also make sure this library routine is available:
23359
23360@table @code
23361@item void *memset(void *, int, int)
4644b6e3 23362@findex memset
104c1213
JM
23363This is the standard library function @code{memset} that sets an area of
23364memory to a known value. If you have one of the free versions of
23365@code{libc.a}, @code{memset} can be found there; otherwise, you must
23366either obtain it from your hardware manufacturer, or write your own.
23367@end table
23368
23369If you do not use the GNU C compiler, you may need other standard
23370library subroutines as well; this varies from one stub to another,
23371but in general the stubs are likely to use any of the common library
e22ea452 23372subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23373
23374
6d2ebf8b 23375@node Debug Session
79a6e687 23376@subsection Putting it All Together
104c1213
JM
23377
23378@cindex remote serial debugging summary
23379In summary, when your program is ready to debug, you must follow these
23380steps.
23381
23382@enumerate
23383@item
6d2ebf8b 23384Make sure you have defined the supporting low-level routines
79a6e687 23385(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23386@display
23387@code{getDebugChar}, @code{putDebugChar},
23388@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23389@end display
23390
23391@item
2fb860fc
PA
23392Insert these lines in your program's startup code, before the main
23393procedure is called:
104c1213 23394
474c8240 23395@smallexample
104c1213
JM
23396set_debug_traps();
23397breakpoint();
474c8240 23398@end smallexample
104c1213 23399
2fb860fc
PA
23400On some machines, when a breakpoint trap is raised, the hardware
23401automatically makes the PC point to the instruction after the
23402breakpoint. If your machine doesn't do that, you may need to adjust
23403@code{handle_exception} to arrange for it to return to the instruction
23404after the breakpoint on this first invocation, so that your program
23405doesn't keep hitting the initial breakpoint instead of making
23406progress.
23407
104c1213
JM
23408@item
23409For the 680x0 stub only, you need to provide a variable called
23410@code{exceptionHook}. Normally you just use:
23411
474c8240 23412@smallexample
104c1213 23413void (*exceptionHook)() = 0;
474c8240 23414@end smallexample
104c1213 23415
d4f3574e 23416@noindent
104c1213 23417but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23418function in your program, that function is called when
104c1213
JM
23419@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23420error). The function indicated by @code{exceptionHook} is called with
23421one parameter: an @code{int} which is the exception number.
23422
23423@item
23424Compile and link together: your program, the @value{GDBN} debugging stub for
23425your target architecture, and the supporting subroutines.
23426
23427@item
23428Make sure you have a serial connection between your target machine and
23429the @value{GDBN} host, and identify the serial port on the host.
23430
23431@item
23432@c The "remote" target now provides a `load' command, so we should
23433@c document that. FIXME.
23434Download your program to your target machine (or get it there by
23435whatever means the manufacturer provides), and start it.
23436
23437@item
07f31aa6 23438Start @value{GDBN} on the host, and connect to the target
79a6e687 23439(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23440
104c1213
JM
23441@end enumerate
23442
8e04817f
AC
23443@node Configurations
23444@chapter Configuration-Specific Information
104c1213 23445
8e04817f
AC
23446While nearly all @value{GDBN} commands are available for all native and
23447cross versions of the debugger, there are some exceptions. This chapter
23448describes things that are only available in certain configurations.
104c1213 23449
8e04817f
AC
23450There are three major categories of configurations: native
23451configurations, where the host and target are the same, embedded
23452operating system configurations, which are usually the same for several
23453different processor architectures, and bare embedded processors, which
23454are quite different from each other.
104c1213 23455
8e04817f
AC
23456@menu
23457* Native::
23458* Embedded OS::
23459* Embedded Processors::
23460* Architectures::
23461@end menu
104c1213 23462
8e04817f
AC
23463@node Native
23464@section Native
104c1213 23465
8e04817f
AC
23466This section describes details specific to particular native
23467configurations.
6cf7e474 23468
8e04817f 23469@menu
7561d450 23470* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23471* Process Information:: Process information
8e04817f 23472* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23473* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23474* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23475* Darwin:: Features specific to Darwin
e9076973 23476* FreeBSD:: Features specific to FreeBSD
8e04817f 23477@end menu
6cf7e474 23478
7561d450
MK
23479@node BSD libkvm Interface
23480@subsection BSD libkvm Interface
23481
23482@cindex libkvm
23483@cindex kernel memory image
23484@cindex kernel crash dump
23485
23486BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23487interface that provides a uniform interface for accessing kernel virtual
23488memory images, including live systems and crash dumps. @value{GDBN}
23489uses this interface to allow you to debug live kernels and kernel crash
23490dumps on many native BSD configurations. This is implemented as a
23491special @code{kvm} debugging target. For debugging a live system, load
23492the currently running kernel into @value{GDBN} and connect to the
23493@code{kvm} target:
23494
23495@smallexample
23496(@value{GDBP}) @b{target kvm}
23497@end smallexample
23498
23499For debugging crash dumps, provide the file name of the crash dump as an
23500argument:
23501
23502@smallexample
23503(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23504@end smallexample
23505
23506Once connected to the @code{kvm} target, the following commands are
23507available:
23508
23509@table @code
23510@kindex kvm
23511@item kvm pcb
721c2651 23512Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23513
23514@item kvm proc
23515Set current context from proc address. This command isn't available on
23516modern FreeBSD systems.
23517@end table
23518
2d97a5d9
JB
23519@node Process Information
23520@subsection Process Information
60bf7e09
EZ
23521@cindex /proc
23522@cindex examine process image
23523@cindex process info via @file{/proc}
104c1213 23524
2d97a5d9
JB
23525Some operating systems provide interfaces to fetch additional
23526information about running processes beyond memory and per-thread
23527register state. If @value{GDBN} is configured for an operating system
23528with a supported interface, the command @code{info proc} is available
23529to report information about the process running your program, or about
23530any process running on your system.
451b7c33 23531
2d97a5d9
JB
23532One supported interface is a facility called @samp{/proc} that can be
23533used to examine the image of a running process using file-system
23534subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23535systems.
451b7c33 23536
aa8509b4
KR
23537On FreeBSD and NetBSD systems, system control nodes are used to query
23538process information.
2d97a5d9
JB
23539
23540In addition, some systems may provide additional process information
23541in core files. Note that a core file may include a subset of the
23542information available from a live process. Process information is
6b92c0d3 23543currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23544systems.
104c1213 23545
8e04817f
AC
23546@table @code
23547@kindex info proc
60bf7e09 23548@cindex process ID
8e04817f 23549@item info proc
60bf7e09 23550@itemx info proc @var{process-id}
73f1bd76 23551Summarize available information about a process. If a
60bf7e09
EZ
23552process ID is specified by @var{process-id}, display information about
23553that process; otherwise display information about the program being
23554debugged. The summary includes the debugged process ID, the command
23555line used to invoke it, its current working directory, and its
23556executable file's absolute file name.
23557
23558On some systems, @var{process-id} can be of the form
23559@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23560within a process. If the optional @var{pid} part is missing, it means
23561a thread from the process being debugged (the leading @samp{/} still
23562needs to be present, or else @value{GDBN} will interpret the number as
23563a process ID rather than a thread ID).
6cf7e474 23564
0c631110
TT
23565@item info proc cmdline
23566@cindex info proc cmdline
23567Show the original command line of the process. This command is
aa8509b4 23568supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23569
23570@item info proc cwd
23571@cindex info proc cwd
23572Show the current working directory of the process. This command is
aa8509b4 23573supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23574
23575@item info proc exe
23576@cindex info proc exe
2d97a5d9 23577Show the name of executable of the process. This command is supported
aa8509b4 23578on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110 23579
8b113111
JB
23580@item info proc files
23581@cindex info proc files
23582Show the file descriptors open by the process. For each open file
23583descriptor, @value{GDBN} shows its number, type (file, directory,
23584character device, socket), file pointer offset, and the name of the
23585resource open on the descriptor. The resource name can be a file name
23586(for files, directories, and devices) or a protocol followed by socket
23587address (for network connections). This command is supported on
23588FreeBSD.
23589
23590This example shows the open file descriptors for a process using a
23591tty for standard input and output as well as two network sockets:
23592
23593@smallexample
23594(gdb) info proc files 22136
23595process 22136
23596Open files:
23597
23598 FD Type Offset Flags Name
23599 text file - r-------- /usr/bin/ssh
23600 ctty chr - rw------- /dev/pts/20
23601 cwd dir - r-------- /usr/home/john
23602 root dir - r-------- /
23603 0 chr 0x32933a4 rw------- /dev/pts/20
23604 1 chr 0x32933a4 rw------- /dev/pts/20
23605 2 chr 0x32933a4 rw------- /dev/pts/20
23606 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23607 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23608@end smallexample
23609
8e04817f 23610@item info proc mappings
60bf7e09 23611@cindex memory address space mappings
73f1bd76 23612Report the memory address space ranges accessible in a process. On
aa8509b4
KR
23613Solaris, FreeBSD and NetBSD systems, each memory range includes information
23614on whether the process has read, write, or execute access rights to each
23615range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
2d97a5d9 23616includes the object file which is mapped to that range.
60bf7e09
EZ
23617
23618@item info proc stat
23619@itemx info proc status
23620@cindex process detailed status information
2d97a5d9
JB
23621Show additional process-related information, including the user ID and
23622group ID; virtual memory usage; the signals that are pending, blocked,
23623and ignored; its TTY; its consumption of system and user time; its
23624stack size; its @samp{nice} value; etc. These commands are supported
aa8509b4 23625on @sc{gnu}/Linux, FreeBSD and NetBSD.
2d97a5d9
JB
23626
23627For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23628information (type @kbd{man 5 proc} from your shell prompt).
23629
aa8509b4
KR
23630For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23631@code{info proc status}.
60bf7e09
EZ
23632
23633@item info proc all
23634Show all the information about the process described under all of the
23635above @code{info proc} subcommands.
23636
8e04817f
AC
23637@ignore
23638@comment These sub-options of 'info proc' were not included when
23639@comment procfs.c was re-written. Keep their descriptions around
23640@comment against the day when someone finds the time to put them back in.
23641@kindex info proc times
23642@item info proc times
23643Starting time, user CPU time, and system CPU time for your program and
23644its children.
6cf7e474 23645
8e04817f
AC
23646@kindex info proc id
23647@item info proc id
23648Report on the process IDs related to your program: its own process ID,
23649the ID of its parent, the process group ID, and the session ID.
8e04817f 23650@end ignore
721c2651
EZ
23651
23652@item set procfs-trace
23653@kindex set procfs-trace
23654@cindex @code{procfs} API calls
23655This command enables and disables tracing of @code{procfs} API calls.
23656
23657@item show procfs-trace
23658@kindex show procfs-trace
23659Show the current state of @code{procfs} API call tracing.
23660
23661@item set procfs-file @var{file}
23662@kindex set procfs-file
23663Tell @value{GDBN} to write @code{procfs} API trace to the named
23664@var{file}. @value{GDBN} appends the trace info to the previous
23665contents of the file. The default is to display the trace on the
23666standard output.
23667
23668@item show procfs-file
23669@kindex show procfs-file
23670Show the file to which @code{procfs} API trace is written.
23671
23672@item proc-trace-entry
23673@itemx proc-trace-exit
23674@itemx proc-untrace-entry
23675@itemx proc-untrace-exit
23676@kindex proc-trace-entry
23677@kindex proc-trace-exit
23678@kindex proc-untrace-entry
23679@kindex proc-untrace-exit
23680These commands enable and disable tracing of entries into and exits
23681from the @code{syscall} interface.
23682
23683@item info pidlist
23684@kindex info pidlist
23685@cindex process list, QNX Neutrino
23686For QNX Neutrino only, this command displays the list of all the
23687processes and all the threads within each process.
23688
23689@item info meminfo
23690@kindex info meminfo
23691@cindex mapinfo list, QNX Neutrino
23692For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23693@end table
104c1213 23694
8e04817f
AC
23695@node DJGPP Native
23696@subsection Features for Debugging @sc{djgpp} Programs
23697@cindex @sc{djgpp} debugging
23698@cindex native @sc{djgpp} debugging
23699@cindex MS-DOS-specific commands
104c1213 23700
514c4d71
EZ
23701@cindex DPMI
23702@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23703MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23704that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23705top of real-mode DOS systems and their emulations.
104c1213 23706
8e04817f
AC
23707@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23708defines a few commands specific to the @sc{djgpp} port. This
23709subsection describes those commands.
104c1213 23710
8e04817f
AC
23711@table @code
23712@kindex info dos
23713@item info dos
23714This is a prefix of @sc{djgpp}-specific commands which print
23715information about the target system and important OS structures.
f1251bdd 23716
8e04817f
AC
23717@kindex sysinfo
23718@cindex MS-DOS system info
23719@cindex free memory information (MS-DOS)
23720@item info dos sysinfo
23721This command displays assorted information about the underlying
23722platform: the CPU type and features, the OS version and flavor, the
23723DPMI version, and the available conventional and DPMI memory.
104c1213 23724
8e04817f
AC
23725@cindex GDT
23726@cindex LDT
23727@cindex IDT
23728@cindex segment descriptor tables
23729@cindex descriptor tables display
23730@item info dos gdt
23731@itemx info dos ldt
23732@itemx info dos idt
23733These 3 commands display entries from, respectively, Global, Local,
23734and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23735tables are data structures which store a descriptor for each segment
23736that is currently in use. The segment's selector is an index into a
23737descriptor table; the table entry for that index holds the
23738descriptor's base address and limit, and its attributes and access
23739rights.
104c1213 23740
8e04817f
AC
23741A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23742segment (used for both data and the stack), and a DOS segment (which
23743allows access to DOS/BIOS data structures and absolute addresses in
23744conventional memory). However, the DPMI host will usually define
23745additional segments in order to support the DPMI environment.
d4f3574e 23746
8e04817f
AC
23747@cindex garbled pointers
23748These commands allow to display entries from the descriptor tables.
23749Without an argument, all entries from the specified table are
23750displayed. An argument, which should be an integer expression, means
23751display a single entry whose index is given by the argument. For
23752example, here's a convenient way to display information about the
23753debugged program's data segment:
104c1213 23754
8e04817f
AC
23755@smallexample
23756@exdent @code{(@value{GDBP}) info dos ldt $ds}
23757@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23758@end smallexample
104c1213 23759
8e04817f
AC
23760@noindent
23761This comes in handy when you want to see whether a pointer is outside
23762the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23763
8e04817f
AC
23764@cindex page tables display (MS-DOS)
23765@item info dos pde
23766@itemx info dos pte
23767These two commands display entries from, respectively, the Page
23768Directory and the Page Tables. Page Directories and Page Tables are
23769data structures which control how virtual memory addresses are mapped
23770into physical addresses. A Page Table includes an entry for every
23771page of memory that is mapped into the program's address space; there
23772may be several Page Tables, each one holding up to 4096 entries. A
23773Page Directory has up to 4096 entries, one each for every Page Table
23774that is currently in use.
104c1213 23775
8e04817f
AC
23776Without an argument, @kbd{info dos pde} displays the entire Page
23777Directory, and @kbd{info dos pte} displays all the entries in all of
23778the Page Tables. An argument, an integer expression, given to the
23779@kbd{info dos pde} command means display only that entry from the Page
23780Directory table. An argument given to the @kbd{info dos pte} command
23781means display entries from a single Page Table, the one pointed to by
23782the specified entry in the Page Directory.
104c1213 23783
8e04817f
AC
23784@cindex direct memory access (DMA) on MS-DOS
23785These commands are useful when your program uses @dfn{DMA} (Direct
23786Memory Access), which needs physical addresses to program the DMA
23787controller.
104c1213 23788
8e04817f 23789These commands are supported only with some DPMI servers.
104c1213 23790
8e04817f
AC
23791@cindex physical address from linear address
23792@item info dos address-pte @var{addr}
23793This command displays the Page Table entry for a specified linear
514c4d71
EZ
23794address. The argument @var{addr} is a linear address which should
23795already have the appropriate segment's base address added to it,
23796because this command accepts addresses which may belong to @emph{any}
23797segment. For example, here's how to display the Page Table entry for
23798the page where a variable @code{i} is stored:
104c1213 23799
b383017d 23800@smallexample
8e04817f
AC
23801@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23802@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23803@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23804@end smallexample
104c1213 23805
8e04817f
AC
23806@noindent
23807This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23808whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23809attributes of that page.
104c1213 23810
8e04817f
AC
23811Note that you must cast the addresses of variables to a @code{char *},
23812since otherwise the value of @code{__djgpp_base_address}, the base
23813address of all variables and functions in a @sc{djgpp} program, will
23814be added using the rules of C pointer arithmetics: if @code{i} is
23815declared an @code{int}, @value{GDBN} will add 4 times the value of
23816@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23817
8e04817f
AC
23818Here's another example, it displays the Page Table entry for the
23819transfer buffer:
104c1213 23820
8e04817f
AC
23821@smallexample
23822@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23823@exdent @code{Page Table entry for address 0x29110:}
23824@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23825@end smallexample
104c1213 23826
8e04817f
AC
23827@noindent
23828(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
238293rd member of the @code{_go32_info_block} structure.) The output
23830clearly shows that this DPMI server maps the addresses in conventional
23831memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23832linear (@code{0x29110}) addresses are identical.
104c1213 23833
8e04817f
AC
23834This command is supported only with some DPMI servers.
23835@end table
104c1213 23836
c45da7e6 23837@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23838In addition to native debugging, the DJGPP port supports remote
23839debugging via a serial data link. The following commands are specific
23840to remote serial debugging in the DJGPP port of @value{GDBN}.
23841
23842@table @code
23843@kindex set com1base
23844@kindex set com1irq
23845@kindex set com2base
23846@kindex set com2irq
23847@kindex set com3base
23848@kindex set com3irq
23849@kindex set com4base
23850@kindex set com4irq
23851@item set com1base @var{addr}
23852This command sets the base I/O port address of the @file{COM1} serial
23853port.
23854
23855@item set com1irq @var{irq}
23856This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23857for the @file{COM1} serial port.
23858
23859There are similar commands @samp{set com2base}, @samp{set com3irq},
23860etc.@: for setting the port address and the @code{IRQ} lines for the
23861other 3 COM ports.
23862
23863@kindex show com1base
23864@kindex show com1irq
23865@kindex show com2base
23866@kindex show com2irq
23867@kindex show com3base
23868@kindex show com3irq
23869@kindex show com4base
23870@kindex show com4irq
23871The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23872display the current settings of the base address and the @code{IRQ}
23873lines used by the COM ports.
c45da7e6
EZ
23874
23875@item info serial
23876@kindex info serial
23877@cindex DOS serial port status
23878This command prints the status of the 4 DOS serial ports. For each
23879port, it prints whether it's active or not, its I/O base address and
23880IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23881counts of various errors encountered so far.
a8f24a35
EZ
23882@end table
23883
23884
78c47bea 23885@node Cygwin Native
79a6e687 23886@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23887@cindex MS Windows debugging
23888@cindex native Cygwin debugging
23889@cindex Cygwin-specific commands
23890
be448670 23891@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23892DLLs with and without symbolic debugging information.
23893
23894@cindex Ctrl-BREAK, MS-Windows
23895@cindex interrupt debuggee on MS-Windows
23896MS-Windows programs that call @code{SetConsoleMode} to switch off the
23897special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23898by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23899supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23900sequence, which can be used to interrupt the debuggee even if it
23901ignores @kbd{C-c}.
23902
23903There are various additional Cygwin-specific commands, described in
23904this section. Working with DLLs that have no debugging symbols is
23905described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
23906
23907@table @code
23908@kindex info w32
23909@item info w32
db2e3e2e 23910This is a prefix of MS Windows-specific commands which print
78c47bea
PM
23911information about the target system and important OS structures.
23912
23913@item info w32 selector
23914This command displays information returned by
23915the Win32 API @code{GetThreadSelectorEntry} function.
23916It takes an optional argument that is evaluated to
23917a long value to give the information about this given selector.
23918Without argument, this command displays information
d3e8051b 23919about the six segment registers.
78c47bea 23920
711e434b
PM
23921@item info w32 thread-information-block
23922This command displays thread specific information stored in the
23923Thread Information Block (readable on the X86 CPU family using @code{$fs}
23924selector for 32-bit programs and @code{$gs} for 64-bit programs).
23925
463888ab
РИ
23926@kindex signal-event
23927@item signal-event @var{id}
23928This command signals an event with user-provided @var{id}. Used to resume
23929crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23930
23931To use it, create or edit the following keys in
23932@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23933@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23934(for x86_64 versions):
23935
23936@itemize @minus
23937@item
23938@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23939Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23940"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23941
23942The first @code{%ld} will be replaced by the process ID of the
23943crashing process, the second @code{%ld} will be replaced by the ID of
23944the event that blocks the crashing process, waiting for @value{GDBN}
23945to attach.
23946
23947@item
23948@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23949make the system run debugger specified by the Debugger key
23950automatically, @code{0} will cause a dialog box with ``OK'' and
23951``Cancel'' buttons to appear, which allows the user to either
23952terminate the crashing process (OK) or debug it (Cancel).
23953@end itemize
23954
be90c084 23955@kindex set cygwin-exceptions
e16b02ee
EZ
23956@cindex debugging the Cygwin DLL
23957@cindex Cygwin DLL, debugging
be90c084 23958@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
23959If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23960happen inside the Cygwin DLL. If @var{mode} is @code{off},
23961@value{GDBN} will delay recognition of exceptions, and may ignore some
23962exceptions which seem to be caused by internal Cygwin DLL
23963``bookkeeping''. This option is meant primarily for debugging the
23964Cygwin DLL itself; the default value is @code{off} to avoid annoying
23965@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
23966
23967@kindex show cygwin-exceptions
23968@item show cygwin-exceptions
e16b02ee
EZ
23969Displays whether @value{GDBN} will break on exceptions that happen
23970inside the Cygwin DLL itself.
be90c084 23971
b383017d 23972@kindex set new-console
78c47bea 23973@item set new-console @var{mode}
b383017d 23974If @var{mode} is @code{on} the debuggee will
78c47bea 23975be started in a new console on next start.
e03e5e7b 23976If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
23977be started in the same console as the debugger.
23978
23979@kindex show new-console
23980@item show new-console
23981Displays whether a new console is used
23982when the debuggee is started.
23983
23984@kindex set new-group
23985@item set new-group @var{mode}
23986This boolean value controls whether the debuggee should
23987start a new group or stay in the same group as the debugger.
23988This affects the way the Windows OS handles
c8aa23ab 23989@samp{Ctrl-C}.
78c47bea
PM
23990
23991@kindex show new-group
23992@item show new-group
23993Displays current value of new-group boolean.
23994
23995@kindex set debugevents
23996@item set debugevents
219eec71
EZ
23997This boolean value adds debug output concerning kernel events related
23998to the debuggee seen by the debugger. This includes events that
23999signal thread and process creation and exit, DLL loading and
24000unloading, console interrupts, and debugging messages produced by the
24001Windows @code{OutputDebugString} API call.
78c47bea
PM
24002
24003@kindex set debugexec
24004@item set debugexec
b383017d 24005This boolean value adds debug output concerning execute events
219eec71 24006(such as resume thread) seen by the debugger.
78c47bea
PM
24007
24008@kindex set debugexceptions
24009@item set debugexceptions
219eec71
EZ
24010This boolean value adds debug output concerning exceptions in the
24011debuggee seen by the debugger.
78c47bea
PM
24012
24013@kindex set debugmemory
24014@item set debugmemory
219eec71
EZ
24015This boolean value adds debug output concerning debuggee memory reads
24016and writes by the debugger.
78c47bea
PM
24017
24018@kindex set shell
24019@item set shell
24020This boolean values specifies whether the debuggee is called
24021via a shell or directly (default value is on).
24022
24023@kindex show shell
24024@item show shell
24025Displays if the debuggee will be started with a shell.
24026
24027@end table
24028
be448670 24029@menu
79a6e687 24030* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
24031@end menu
24032
79a6e687
BW
24033@node Non-debug DLL Symbols
24034@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
24035@cindex DLLs with no debugging symbols
24036@cindex Minimal symbols and DLLs
24037
24038Very often on windows, some of the DLLs that your program relies on do
24039not include symbolic debugging information (for example,
db2e3e2e 24040@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 24041symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 24042information contained in the DLL's export table. This section
be448670
CF
24043describes working with such symbols, known internally to @value{GDBN} as
24044``minimal symbols''.
24045
24046Note that before the debugged program has started execution, no DLLs
db2e3e2e 24047will have been loaded. The easiest way around this problem is simply to
be448670 24048start the program --- either by setting a breakpoint or letting the
95060284 24049program run once to completion.
be448670 24050
79a6e687 24051@subsubsection DLL Name Prefixes
be448670
CF
24052
24053In keeping with the naming conventions used by the Microsoft debugging
24054tools, DLL export symbols are made available with a prefix based on the
24055DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24056also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 24057sufficient. In some cases there will be name clashes within a program
be448670
CF
24058(particularly if the executable itself includes full debugging symbols)
24059necessitating the use of the fully qualified name when referring to the
99e008fe 24060contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
24061exclamation mark (``!'') being interpreted as a language operator.
24062
24063Note that the internal name of the DLL may be all upper-case, even
99e008fe 24064though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
24065symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24066some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
24067@code{info variables} commands or even @code{maint print msymbols}
24068(@pxref{Symbols}). Here's an example:
be448670
CF
24069
24070@smallexample
f7dc1244 24071(@value{GDBP}) info function CreateFileA
be448670
CF
24072All functions matching regular expression "CreateFileA":
24073
24074Non-debugging symbols:
240750x77e885f4 CreateFileA
240760x77e885f4 KERNEL32!CreateFileA
24077@end smallexample
24078
24079@smallexample
f7dc1244 24080(@value{GDBP}) info function !
be448670
CF
24081All functions matching regular expression "!":
24082
24083Non-debugging symbols:
240840x6100114c cygwin1!__assert
240850x61004034 cygwin1!_dll_crt0@@0
240860x61004240 cygwin1!dll_crt0(per_process *)
24087[etc...]
24088@end smallexample
24089
79a6e687 24090@subsubsection Working with Minimal Symbols
be448670
CF
24091
24092Symbols extracted from a DLL's export table do not contain very much
24093type information. All that @value{GDBN} can do is guess whether a symbol
24094refers to a function or variable depending on the linker section that
24095contains the symbol. Also note that the actual contents of the memory
24096contained in a DLL are not available unless the program is running. This
24097means that you cannot examine the contents of a variable or disassemble
24098a function within a DLL without a running program.
24099
24100Variables are generally treated as pointers and dereferenced
24101automatically. For this reason, it is often necessary to prefix a
24102variable name with the address-of operator (``&'') and provide explicit
24103type information in the command. Here's an example of the type of
24104problem:
24105
24106@smallexample
f7dc1244 24107(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 24108'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24109@end smallexample
24110
24111@smallexample
f7dc1244 24112(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 24113'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24114@end smallexample
24115
24116And two possible solutions:
24117
24118@smallexample
f7dc1244 24119(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
24120$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24121@end smallexample
24122
24123@smallexample
f7dc1244 24124(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 241250x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 24126(@value{GDBP}) x/x 0x10021608
be448670 241270x10021608: 0x0022fd98
f7dc1244 24128(@value{GDBP}) x/s 0x0022fd98
be448670
CF
241290x22fd98: "/cygdrive/c/mydirectory/myprogram"
24130@end smallexample
24131
24132Setting a break point within a DLL is possible even before the program
24133starts execution. However, under these circumstances, @value{GDBN} can't
24134examine the initial instructions of the function in order to skip the
24135function's frame set-up code. You can work around this by using ``*&''
24136to set the breakpoint at a raw memory address:
24137
24138@smallexample
f7dc1244 24139(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
24140Breakpoint 1 at 0x1e04eff0
24141@end smallexample
24142
24143The author of these extensions is not entirely convinced that setting a
24144break point within a shared DLL like @file{kernel32.dll} is completely
24145safe.
24146
14d6dd68 24147@node Hurd Native
79a6e687 24148@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
24149@cindex @sc{gnu} Hurd debugging
24150
24151This subsection describes @value{GDBN} commands specific to the
24152@sc{gnu} Hurd native debugging.
24153
24154@table @code
24155@item set signals
24156@itemx set sigs
24157@kindex set signals@r{, Hurd command}
24158@kindex set sigs@r{, Hurd command}
24159This command toggles the state of inferior signal interception by
24160@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24161affected by this command. @code{sigs} is a shorthand alias for
24162@code{signals}.
24163
24164@item show signals
24165@itemx show sigs
24166@kindex show signals@r{, Hurd command}
24167@kindex show sigs@r{, Hurd command}
24168Show the current state of intercepting inferior's signals.
24169
24170@item set signal-thread
24171@itemx set sigthread
24172@kindex set signal-thread
24173@kindex set sigthread
24174This command tells @value{GDBN} which thread is the @code{libc} signal
24175thread. That thread is run when a signal is delivered to a running
24176process. @code{set sigthread} is the shorthand alias of @code{set
24177signal-thread}.
24178
24179@item show signal-thread
24180@itemx show sigthread
24181@kindex show signal-thread
24182@kindex show sigthread
24183These two commands show which thread will run when the inferior is
24184delivered a signal.
24185
24186@item set stopped
24187@kindex set stopped@r{, Hurd command}
24188This commands tells @value{GDBN} that the inferior process is stopped,
24189as with the @code{SIGSTOP} signal. The stopped process can be
24190continued by delivering a signal to it.
24191
24192@item show stopped
24193@kindex show stopped@r{, Hurd command}
24194This command shows whether @value{GDBN} thinks the debuggee is
24195stopped.
24196
24197@item set exceptions
24198@kindex set exceptions@r{, Hurd command}
24199Use this command to turn off trapping of exceptions in the inferior.
24200When exception trapping is off, neither breakpoints nor
24201single-stepping will work. To restore the default, set exception
24202trapping on.
24203
24204@item show exceptions
24205@kindex show exceptions@r{, Hurd command}
24206Show the current state of trapping exceptions in the inferior.
24207
24208@item set task pause
24209@kindex set task@r{, Hurd commands}
24210@cindex task attributes (@sc{gnu} Hurd)
24211@cindex pause current task (@sc{gnu} Hurd)
24212This command toggles task suspension when @value{GDBN} has control.
24213Setting it to on takes effect immediately, and the task is suspended
24214whenever @value{GDBN} gets control. Setting it to off will take
24215effect the next time the inferior is continued. If this option is set
24216to off, you can use @code{set thread default pause on} or @code{set
24217thread pause on} (see below) to pause individual threads.
24218
24219@item show task pause
24220@kindex show task@r{, Hurd commands}
24221Show the current state of task suspension.
24222
24223@item set task detach-suspend-count
24224@cindex task suspend count
24225@cindex detach from task, @sc{gnu} Hurd
24226This command sets the suspend count the task will be left with when
24227@value{GDBN} detaches from it.
24228
24229@item show task detach-suspend-count
24230Show the suspend count the task will be left with when detaching.
24231
24232@item set task exception-port
24233@itemx set task excp
24234@cindex task exception port, @sc{gnu} Hurd
24235This command sets the task exception port to which @value{GDBN} will
24236forward exceptions. The argument should be the value of the @dfn{send
24237rights} of the task. @code{set task excp} is a shorthand alias.
24238
24239@item set noninvasive
24240@cindex noninvasive task options
24241This command switches @value{GDBN} to a mode that is the least
24242invasive as far as interfering with the inferior is concerned. This
24243is the same as using @code{set task pause}, @code{set exceptions}, and
24244@code{set signals} to values opposite to the defaults.
24245
24246@item info send-rights
24247@itemx info receive-rights
24248@itemx info port-rights
24249@itemx info port-sets
24250@itemx info dead-names
24251@itemx info ports
24252@itemx info psets
24253@cindex send rights, @sc{gnu} Hurd
24254@cindex receive rights, @sc{gnu} Hurd
24255@cindex port rights, @sc{gnu} Hurd
24256@cindex port sets, @sc{gnu} Hurd
24257@cindex dead names, @sc{gnu} Hurd
24258These commands display information about, respectively, send rights,
24259receive rights, port rights, port sets, and dead names of a task.
24260There are also shorthand aliases: @code{info ports} for @code{info
24261port-rights} and @code{info psets} for @code{info port-sets}.
24262
24263@item set thread pause
24264@kindex set thread@r{, Hurd command}
24265@cindex thread properties, @sc{gnu} Hurd
24266@cindex pause current thread (@sc{gnu} Hurd)
24267This command toggles current thread suspension when @value{GDBN} has
24268control. Setting it to on takes effect immediately, and the current
24269thread is suspended whenever @value{GDBN} gets control. Setting it to
24270off will take effect the next time the inferior is continued.
24271Normally, this command has no effect, since when @value{GDBN} has
24272control, the whole task is suspended. However, if you used @code{set
24273task pause off} (see above), this command comes in handy to suspend
24274only the current thread.
24275
24276@item show thread pause
24277@kindex show thread@r{, Hurd command}
24278This command shows the state of current thread suspension.
24279
24280@item set thread run
d3e8051b 24281This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24282
24283@item show thread run
24284Show whether the current thread is allowed to run.
24285
24286@item set thread detach-suspend-count
24287@cindex thread suspend count, @sc{gnu} Hurd
24288@cindex detach from thread, @sc{gnu} Hurd
24289This command sets the suspend count @value{GDBN} will leave on a
24290thread when detaching. This number is relative to the suspend count
24291found by @value{GDBN} when it notices the thread; use @code{set thread
24292takeover-suspend-count} to force it to an absolute value.
24293
24294@item show thread detach-suspend-count
24295Show the suspend count @value{GDBN} will leave on the thread when
24296detaching.
24297
24298@item set thread exception-port
24299@itemx set thread excp
24300Set the thread exception port to which to forward exceptions. This
24301overrides the port set by @code{set task exception-port} (see above).
24302@code{set thread excp} is the shorthand alias.
24303
24304@item set thread takeover-suspend-count
24305Normally, @value{GDBN}'s thread suspend counts are relative to the
24306value @value{GDBN} finds when it notices each thread. This command
24307changes the suspend counts to be absolute instead.
24308
24309@item set thread default
24310@itemx show thread default
24311@cindex thread default settings, @sc{gnu} Hurd
24312Each of the above @code{set thread} commands has a @code{set thread
24313default} counterpart (e.g., @code{set thread default pause}, @code{set
24314thread default exception-port}, etc.). The @code{thread default}
24315variety of commands sets the default thread properties for all
24316threads; you can then change the properties of individual threads with
24317the non-default commands.
24318@end table
24319
a80b95ba
TG
24320@node Darwin
24321@subsection Darwin
24322@cindex Darwin
24323
24324@value{GDBN} provides the following commands specific to the Darwin target:
24325
24326@table @code
24327@item set debug darwin @var{num}
24328@kindex set debug darwin
24329When set to a non zero value, enables debugging messages specific to
24330the Darwin support. Higher values produce more verbose output.
24331
24332@item show debug darwin
24333@kindex show debug darwin
24334Show the current state of Darwin messages.
24335
24336@item set debug mach-o @var{num}
24337@kindex set debug mach-o
24338When set to a non zero value, enables debugging messages while
24339@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24340file format used on Darwin for object and executable files.) Higher
24341values produce more verbose output. This is a command to diagnose
24342problems internal to @value{GDBN} and should not be needed in normal
24343usage.
24344
24345@item show debug mach-o
24346@kindex show debug mach-o
24347Show the current state of Mach-O file messages.
24348
24349@item set mach-exceptions on
24350@itemx set mach-exceptions off
24351@kindex set mach-exceptions
24352On Darwin, faults are first reported as a Mach exception and are then
24353mapped to a Posix signal. Use this command to turn on trapping of
24354Mach exceptions in the inferior. This might be sometimes useful to
24355better understand the cause of a fault. The default is off.
24356
24357@item show mach-exceptions
24358@kindex show mach-exceptions
24359Show the current state of exceptions trapping.
24360@end table
24361
e9076973
JB
24362@node FreeBSD
24363@subsection FreeBSD
24364@cindex FreeBSD
24365
24366When the ABI of a system call is changed in the FreeBSD kernel, this
24367is implemented by leaving a compatibility system call using the old
24368ABI at the existing number and allocating a new system call number for
24369the version using the new ABI. As a convenience, when a system call
24370is caught by name (@pxref{catch syscall}), compatibility system calls
24371are also caught.
24372
24373For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24374system call and catching the @code{kevent} system call by name catches
24375both variants:
24376
24377@smallexample
24378(@value{GDBP}) catch syscall kevent
24379Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24380(@value{GDBP})
24381@end smallexample
24382
a64548ea 24383
8e04817f
AC
24384@node Embedded OS
24385@section Embedded Operating Systems
104c1213 24386
8e04817f
AC
24387This section describes configurations involving the debugging of
24388embedded operating systems that are available for several different
24389architectures.
d4f3574e 24390
8e04817f
AC
24391@value{GDBN} includes the ability to debug programs running on
24392various real-time operating systems.
104c1213 24393
6d2ebf8b 24394@node Embedded Processors
104c1213
JM
24395@section Embedded Processors
24396
24397This section goes into details specific to particular embedded
24398configurations.
24399
c45da7e6
EZ
24400@cindex send command to simulator
24401Whenever a specific embedded processor has a simulator, @value{GDBN}
24402allows to send an arbitrary command to the simulator.
24403
24404@table @code
24405@item sim @var{command}
24406@kindex sim@r{, a command}
24407Send an arbitrary @var{command} string to the simulator. Consult the
24408documentation for the specific simulator in use for information about
24409acceptable commands.
24410@end table
24411
7d86b5d5 24412
104c1213 24413@menu
ad0a504f 24414* ARC:: Synopsys ARC
bb615428 24415* ARM:: ARM
39791af2 24416* BPF:: eBPF
104c1213 24417* M68K:: Motorola M68K
08be9d71 24418* MicroBlaze:: Xilinx MicroBlaze
104c1213 24419* MIPS Embedded:: MIPS Embedded
a994fec4 24420* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24421* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24422* AVR:: Atmel AVR
24423* CRIS:: CRIS
24424* Super-H:: Renesas Super-H
104c1213
JM
24425@end menu
24426
ad0a504f
AK
24427@node ARC
24428@subsection Synopsys ARC
24429@cindex Synopsys ARC
24430@cindex ARC specific commands
24431@cindex ARC600
24432@cindex ARC700
24433@cindex ARC EM
24434@cindex ARC HS
24435
24436@value{GDBN} provides the following ARC-specific commands:
24437
24438@table @code
24439@item set debug arc
24440@kindex set debug arc
24441Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24442default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24443
24444@item show debug arc
24445@kindex show debug arc
24446Show the level of ARC specific debugging in operation.
24447
eea78757
AK
24448@item maint print arc arc-instruction @var{address}
24449@kindex maint print arc arc-instruction
24450Print internal disassembler information about instruction at a given address.
24451
ad0a504f
AK
24452@end table
24453
6d2ebf8b 24454@node ARM
104c1213 24455@subsection ARM
8e04817f 24456
e2f4edfd
EZ
24457@value{GDBN} provides the following ARM-specific commands:
24458
24459@table @code
24460@item set arm disassembler
24461@kindex set arm
24462This commands selects from a list of disassembly styles. The
24463@code{"std"} style is the standard style.
24464
24465@item show arm disassembler
24466@kindex show arm
24467Show the current disassembly style.
24468
24469@item set arm apcs32
24470@cindex ARM 32-bit mode
24471This command toggles ARM operation mode between 32-bit and 26-bit.
24472
24473@item show arm apcs32
24474Display the current usage of the ARM 32-bit mode.
24475
24476@item set arm fpu @var{fputype}
24477This command sets the ARM floating-point unit (FPU) type. The
24478argument @var{fputype} can be one of these:
24479
24480@table @code
24481@item auto
24482Determine the FPU type by querying the OS ABI.
24483@item softfpa
24484Software FPU, with mixed-endian doubles on little-endian ARM
24485processors.
24486@item fpa
24487GCC-compiled FPA co-processor.
24488@item softvfp
24489Software FPU with pure-endian doubles.
24490@item vfp
24491VFP co-processor.
24492@end table
24493
24494@item show arm fpu
24495Show the current type of the FPU.
24496
24497@item set arm abi
24498This command forces @value{GDBN} to use the specified ABI.
24499
24500@item show arm abi
24501Show the currently used ABI.
24502
0428b8f5
DJ
24503@item set arm fallback-mode (arm|thumb|auto)
24504@value{GDBN} uses the symbol table, when available, to determine
24505whether instructions are ARM or Thumb. This command controls
24506@value{GDBN}'s default behavior when the symbol table is not
24507available. The default is @samp{auto}, which causes @value{GDBN} to
24508use the current execution mode (from the @code{T} bit in the @code{CPSR}
24509register).
24510
24511@item show arm fallback-mode
24512Show the current fallback instruction mode.
24513
24514@item set arm force-mode (arm|thumb|auto)
24515This command overrides use of the symbol table to determine whether
24516instructions are ARM or Thumb. The default is @samp{auto}, which
24517causes @value{GDBN} to use the symbol table and then the setting
24518of @samp{set arm fallback-mode}.
24519
24520@item show arm force-mode
24521Show the current forced instruction mode.
24522
e2f4edfd
EZ
24523@item set debug arm
24524Toggle whether to display ARM-specific debugging messages from the ARM
24525target support subsystem.
24526
24527@item show debug arm
24528Show whether ARM-specific debugging messages are enabled.
24529@end table
24530
ee8e71d4
EZ
24531@table @code
24532@item target sim @r{[}@var{simargs}@r{]} @dots{}
24533The @value{GDBN} ARM simulator accepts the following optional arguments.
24534
24535@table @code
24536@item --swi-support=@var{type}
697aa1b7 24537Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24538@var{type} may be a comma separated list of the following values.
24539The default value is @code{all}.
24540
24541@table @code
24542@item none
24543@item demon
24544@item angel
24545@item redboot
24546@item all
24547@end table
24548@end table
24549@end table
e2f4edfd 24550
39791af2
JM
24551@node BPF
24552@subsection BPF
24553
24554@table @code
24555@item target sim @r{[}@var{simargs}@r{]} @dots{}
24556The @value{GDBN} BPF simulator accepts the following optional arguments.
24557
24558@table @code
24559@item --skb-data-offset=@var{offset}
24560Tell the simulator the offset, measured in bytes, of the
24561@code{skb_data} field in the kernel @code{struct sk_buff} structure.
24562This offset is used by some BPF specific-purpose load/store
24563instructions. Defaults to 0.
24564@end table
24565@end table
24566
8e04817f
AC
24567@node M68K
24568@subsection M68k
24569
bb615428 24570The Motorola m68k configuration includes ColdFire support.
8e04817f 24571
08be9d71
ME
24572@node MicroBlaze
24573@subsection MicroBlaze
24574@cindex Xilinx MicroBlaze
24575@cindex XMD, Xilinx Microprocessor Debugger
24576
24577The MicroBlaze is a soft-core processor supported on various Xilinx
24578FPGAs, such as Spartan or Virtex series. Boards with these processors
24579usually have JTAG ports which connect to a host system running the Xilinx
24580Embedded Development Kit (EDK) or Software Development Kit (SDK).
24581This host system is used to download the configuration bitstream to
24582the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24583communicates with the target board using the JTAG interface and
24584presents a @code{gdbserver} interface to the board. By default
24585@code{xmd} uses port @code{1234}. (While it is possible to change
24586this default port, it requires the use of undocumented @code{xmd}
24587commands. Contact Xilinx support if you need to do this.)
24588
24589Use these GDB commands to connect to the MicroBlaze target processor.
24590
24591@table @code
24592@item target remote :1234
24593Use this command to connect to the target if you are running @value{GDBN}
24594on the same system as @code{xmd}.
24595
24596@item target remote @var{xmd-host}:1234
24597Use this command to connect to the target if it is connected to @code{xmd}
24598running on a different system named @var{xmd-host}.
24599
24600@item load
24601Use this command to download a program to the MicroBlaze target.
24602
24603@item set debug microblaze @var{n}
24604Enable MicroBlaze-specific debugging messages if non-zero.
24605
24606@item show debug microblaze @var{n}
24607Show MicroBlaze-specific debugging level.
24608@end table
24609
8e04817f 24610@node MIPS Embedded
eb17f351 24611@subsection @acronym{MIPS} Embedded
8e04817f 24612
8e04817f 24613@noindent
f7c38292 24614@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24615
8e04817f 24616@table @code
8e04817f
AC
24617@item set mipsfpu double
24618@itemx set mipsfpu single
24619@itemx set mipsfpu none
a64548ea 24620@itemx set mipsfpu auto
8e04817f
AC
24621@itemx show mipsfpu
24622@kindex set mipsfpu
24623@kindex show mipsfpu
eb17f351
EZ
24624@cindex @acronym{MIPS} remote floating point
24625@cindex floating point, @acronym{MIPS} remote
24626If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24627coprocessor, you should use the command @samp{set mipsfpu none} (if you
24628need this, you may wish to put the command in your @value{GDBN} init
24629file). This tells @value{GDBN} how to find the return value of
24630functions which return floating point values. It also allows
24631@value{GDBN} to avoid saving the floating point registers when calling
24632functions on the board. If you are using a floating point coprocessor
24633with only single precision floating point support, as on the @sc{r4650}
24634processor, use the command @samp{set mipsfpu single}. The default
24635double precision floating point coprocessor may be selected using
24636@samp{set mipsfpu double}.
104c1213 24637
8e04817f
AC
24638In previous versions the only choices were double precision or no
24639floating point, so @samp{set mipsfpu on} will select double precision
24640and @samp{set mipsfpu off} will select no floating point.
104c1213 24641
8e04817f
AC
24642As usual, you can inquire about the @code{mipsfpu} variable with
24643@samp{show mipsfpu}.
8e04817f 24644@end table
104c1213 24645
a994fec4
FJ
24646@node OpenRISC 1000
24647@subsection OpenRISC 1000
24648@cindex OpenRISC 1000
24649
24650@noindent
24651The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24652mainly provided as a soft-core which can run on Xilinx, Altera and other
24653FPGA's.
24654
24655@value{GDBN} for OpenRISC supports the below commands when connecting to
24656a target:
24657
24658@table @code
24659
24660@kindex target sim
24661@item target sim
24662
24663Runs the builtin CPU simulator which can run very basic
24664programs but does not support most hardware functions like MMU.
24665For more complex use cases the user is advised to run an external
24666target, and connect using @samp{target remote}.
24667
24668Example: @code{target sim}
24669
24670@item set debug or1k
24671Toggle whether to display OpenRISC-specific debugging messages from the
24672OpenRISC target support subsystem.
24673
24674@item show debug or1k
24675Show whether OpenRISC-specific debugging messages are enabled.
24676@end table
24677
4acd40f3
TJB
24678@node PowerPC Embedded
24679@subsection PowerPC Embedded
104c1213 24680
66b73624
TJB
24681@cindex DVC register
24682@value{GDBN} supports using the DVC (Data Value Compare) register to
24683implement in hardware simple hardware watchpoint conditions of the form:
24684
24685@smallexample
24686(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24687 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24688@end smallexample
24689
e09342b5
TJB
24690The DVC register will be automatically used when @value{GDBN} detects
24691such pattern in a condition expression, and the created watchpoint uses one
24692debug register (either the @code{exact-watchpoints} option is on and the
24693variable is scalar, or the variable has a length of one byte). This feature
24694is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24695or newer.
24696
24697When running on PowerPC embedded processors, @value{GDBN} automatically uses
24698ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24699in which case watchpoints using only one debug register are created when
24700watching variables of scalar types.
24701
24702You can create an artificial array to watch an arbitrary memory
24703region using one of the following commands (@pxref{Expressions}):
24704
24705@smallexample
24706(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24707(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24708@end smallexample
66b73624 24709
9c06b0b4
TJB
24710PowerPC embedded processors support masked watchpoints. See the discussion
24711about the @code{mask} argument in @ref{Set Watchpoints}.
24712
f1310107
TJB
24713@cindex ranged breakpoint
24714PowerPC embedded processors support hardware accelerated
24715@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24716the inferior whenever it executes an instruction at any address within
24717the range it specifies. To set a ranged breakpoint in @value{GDBN},
24718use the @code{break-range} command.
24719
55eddb0f
DJ
24720@value{GDBN} provides the following PowerPC-specific commands:
24721
104c1213 24722@table @code
f1310107
TJB
24723@kindex break-range
24724@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24725Set a breakpoint for an address range given by
24726@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24727a line number, an offset of lines from the current line or from the start
24728location, or an address of an instruction (see @ref{Specify Location},
24729for a list of all the possible ways to specify a @var{location}.)
24730The breakpoint will stop execution of the inferior whenever it
24731executes an instruction at any address within the specified range,
24732(including @var{start-location} and @var{end-location}.)
24733
55eddb0f
DJ
24734@kindex set powerpc
24735@item set powerpc soft-float
24736@itemx show powerpc soft-float
24737Force @value{GDBN} to use (or not use) a software floating point calling
24738convention. By default, @value{GDBN} selects the calling convention based
24739on the selected architecture and the provided executable file.
24740
24741@item set powerpc vector-abi
24742@itemx show powerpc vector-abi
24743Force @value{GDBN} to use the specified calling convention for vector
24744arguments and return values. The valid options are @samp{auto};
24745@samp{generic}, to avoid vector registers even if they are present;
24746@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24747registers. By default, @value{GDBN} selects the calling convention
24748based on the selected architecture and the provided executable file.
24749
e09342b5
TJB
24750@item set powerpc exact-watchpoints
24751@itemx show powerpc exact-watchpoints
24752Allow @value{GDBN} to use only one debug register when watching a variable
24753of scalar type, thus assuming that the variable is accessed through the
24754address of its first byte.
24755
104c1213
JM
24756@end table
24757
a64548ea
EZ
24758@node AVR
24759@subsection Atmel AVR
24760@cindex AVR
24761
24762When configured for debugging the Atmel AVR, @value{GDBN} supports the
24763following AVR-specific commands:
24764
24765@table @code
24766@item info io_registers
24767@kindex info io_registers@r{, AVR}
24768@cindex I/O registers (Atmel AVR)
24769This command displays information about the AVR I/O registers. For
24770each register, @value{GDBN} prints its number and value.
24771@end table
24772
24773@node CRIS
24774@subsection CRIS
24775@cindex CRIS
24776
24777When configured for debugging CRIS, @value{GDBN} provides the
24778following CRIS-specific commands:
24779
24780@table @code
24781@item set cris-version @var{ver}
24782@cindex CRIS version
e22e55c9
OF
24783Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24784The CRIS version affects register names and sizes. This command is useful in
24785case autodetection of the CRIS version fails.
a64548ea
EZ
24786
24787@item show cris-version
24788Show the current CRIS version.
24789
24790@item set cris-dwarf2-cfi
24791@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24792Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24793Change to @samp{off} when using @code{gcc-cris} whose version is below
24794@code{R59}.
a64548ea
EZ
24795
24796@item show cris-dwarf2-cfi
24797Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24798
24799@item set cris-mode @var{mode}
24800@cindex CRIS mode
24801Set the current CRIS mode to @var{mode}. It should only be changed when
24802debugging in guru mode, in which case it should be set to
24803@samp{guru} (the default is @samp{normal}).
24804
24805@item show cris-mode
24806Show the current CRIS mode.
a64548ea
EZ
24807@end table
24808
24809@node Super-H
24810@subsection Renesas Super-H
24811@cindex Super-H
24812
24813For the Renesas Super-H processor, @value{GDBN} provides these
24814commands:
24815
24816@table @code
c055b101
CV
24817@item set sh calling-convention @var{convention}
24818@kindex set sh calling-convention
24819Set the calling-convention used when calling functions from @value{GDBN}.
24820Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24821With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24822convention. If the DWARF-2 information of the called function specifies
24823that the function follows the Renesas calling convention, the function
24824is called using the Renesas calling convention. If the calling convention
24825is set to @samp{renesas}, the Renesas calling convention is always used,
24826regardless of the DWARF-2 information. This can be used to override the
24827default of @samp{gcc} if debug information is missing, or the compiler
24828does not emit the DWARF-2 calling convention entry for a function.
24829
24830@item show sh calling-convention
24831@kindex show sh calling-convention
24832Show the current calling convention setting.
24833
a64548ea
EZ
24834@end table
24835
24836
8e04817f
AC
24837@node Architectures
24838@section Architectures
104c1213 24839
8e04817f
AC
24840This section describes characteristics of architectures that affect
24841all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24842
8e04817f 24843@menu
430ed3f0 24844* AArch64::
9c16f35a 24845* i386::
8e04817f
AC
24846* Alpha::
24847* MIPS::
a64548ea 24848* HPPA:: HP PA architecture
4acd40f3 24849* PowerPC::
a1217d97 24850* Nios II::
58afddc6 24851* Sparc64::
51d21d60 24852* S12Z::
8e04817f 24853@end menu
104c1213 24854
430ed3f0
MS
24855@node AArch64
24856@subsection AArch64
24857@cindex AArch64 support
24858
24859When @value{GDBN} is debugging the AArch64 architecture, it provides the
24860following special commands:
24861
24862@table @code
24863@item set debug aarch64
24864@kindex set debug aarch64
24865This command determines whether AArch64 architecture-specific debugging
24866messages are to be displayed.
24867
24868@item show debug aarch64
24869Show whether AArch64 debugging messages are displayed.
24870
24871@end table
24872
1461bdac
AH
24873@subsubsection AArch64 SVE.
24874@cindex AArch64 SVE.
24875
24876When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24877Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24878@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24879@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24880@code{$vg} will be provided. This is the vector granule for the current thread
24881and represents the number of 64-bit chunks in an SVE @code{z} register.
24882
24883If the vector length changes, then the @code{$vg} register will be updated,
24884but the lengths of the @code{z} and @code{p} registers will not change. This
24885is a known limitation of @value{GDBN} and does not affect the execution of the
24886target process.
24887
3d31bc39
AH
24888@subsubsection AArch64 Pointer Authentication.
24889@cindex AArch64 Pointer Authentication.
24890
24891When @value{GDBN} is debugging the AArch64 architecture, and the program is
24892using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 24893register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 24894When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
24895postfixed with the marker [PAC]. When using the MI, this is printed as part
24896of the @code{addr_flags} field.
1461bdac 24897
9c16f35a 24898@node i386
db2e3e2e 24899@subsection x86 Architecture-specific Issues
9c16f35a
EZ
24900
24901@table @code
24902@item set struct-convention @var{mode}
24903@kindex set struct-convention
24904@cindex struct return convention
24905@cindex struct/union returned in registers
24906Set the convention used by the inferior to return @code{struct}s and
24907@code{union}s from functions to @var{mode}. Possible values of
24908@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24909default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24910are returned on the stack, while @code{"reg"} means that a
24911@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24912be returned in a register.
24913
24914@item show struct-convention
24915@kindex show struct-convention
24916Show the current setting of the convention to return @code{struct}s
24917from functions.
966f0aef 24918@end table
29c1c244 24919
ca8941bb 24920
bc504a31
PA
24921@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24922@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 24923
ca8941bb
WT
24924Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24925@footnote{The register named with capital letters represent the architecture
24926registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24927which are the lower bound and upper bound. Bounds are effective addresses or
24928memory locations. The upper bounds are architecturally represented in 1's
24929complement form. A bound having lower bound = 0, and upper bound = 0
24930(1's complement of all bits set) will allow access to the entire address space.
24931
24932@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24933through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24934display the upper bound performing the complement of one operation on the
24935upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24936@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24937can also be noted that the upper bounds are inclusive.
24938
24939As an example, assume that the register BND0 holds bounds for a pointer having
24940access allowed for the range between 0x32 and 0x71. The values present on
24941bnd0raw and bnd registers are presented as follows:
24942
24943@smallexample
24944 bnd0raw = @{0x32, 0xffffffff8e@}
24945 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24946@end smallexample
24947
22f25c9d
EZ
24948This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24949change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24950counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24951Python, the display includes the memory size, in bits, accessible to
24952the pointer.
9c16f35a 24953
29c1c244
WT
24954Bounds can also be stored in bounds tables, which are stored in
24955application memory. These tables store bounds for pointers by specifying
24956the bounds pointer's value along with its bounds. Evaluating and changing
24957bounds located in bound tables is therefore interesting while investigating
24958bugs on MPX context. @value{GDBN} provides commands for this purpose:
24959
966f0aef 24960@table @code
29c1c244
WT
24961@item show mpx bound @var{pointer}
24962@kindex show mpx bound
24963Display bounds of the given @var{pointer}.
24964
24965@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24966@kindex set mpx bound
24967Set the bounds of a pointer in the bound table.
24968This command takes three parameters: @var{pointer} is the pointers
24969whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24970for lower and upper bounds respectively.
24971@end table
24972
4a612d6f
WT
24973When you call an inferior function on an Intel MPX enabled program,
24974GDB sets the inferior's bound registers to the init (disabled) state
24975before calling the function. As a consequence, bounds checks for the
24976pointer arguments passed to the function will always pass.
24977
24978This is necessary because when you call an inferior function, the
24979program is usually in the middle of the execution of other function.
24980Since at that point bound registers are in an arbitrary state, not
24981clearing them would lead to random bound violations in the called
24982function.
24983
24984You can still examine the influence of the bound registers on the
24985execution of the called function by stopping the execution of the
24986called function at its prologue, setting bound registers, and
24987continuing the execution. For example:
24988
24989@smallexample
24990 $ break *upper
24991 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24992 $ print upper (a, b, c, d, 1)
24993 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24994 $ print $bnd0
5cf70512 24995 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
24996@end smallexample
24997
24998At this last step the value of bnd0 can be changed for investigation of bound
24999violations caused along the execution of the call. In order to know how to
25000set the bound registers or bound table for the call consult the ABI.
25001
8e04817f
AC
25002@node Alpha
25003@subsection Alpha
104c1213 25004
8e04817f 25005See the following section.
104c1213 25006
8e04817f 25007@node MIPS
eb17f351 25008@subsection @acronym{MIPS}
104c1213 25009
8e04817f 25010@cindex stack on Alpha
eb17f351 25011@cindex stack on @acronym{MIPS}
8e04817f 25012@cindex Alpha stack
eb17f351
EZ
25013@cindex @acronym{MIPS} stack
25014Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
25015sometimes requires @value{GDBN} to search backward in the object code to
25016find the beginning of a function.
104c1213 25017
eb17f351 25018@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
25019To improve response time (especially for embedded applications, where
25020@value{GDBN} may be restricted to a slow serial line for this search)
25021you may want to limit the size of this search, using one of these
25022commands:
104c1213 25023
8e04817f 25024@table @code
eb17f351 25025@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
25026@item set heuristic-fence-post @var{limit}
25027Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25028search for the beginning of a function. A value of @var{0} (the
25029default) means there is no limit. However, except for @var{0}, the
25030larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
25031and therefore the longer it takes to run. You should only need to use
25032this command when debugging a stripped executable.
104c1213 25033
8e04817f
AC
25034@item show heuristic-fence-post
25035Display the current limit.
25036@end table
104c1213
JM
25037
25038@noindent
8e04817f 25039These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 25040for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 25041
eb17f351 25042Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
25043programs:
25044
25045@table @code
a64548ea
EZ
25046@item set mips abi @var{arg}
25047@kindex set mips abi
eb17f351
EZ
25048@cindex set ABI for @acronym{MIPS}
25049Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
25050values of @var{arg} are:
25051
25052@table @samp
25053@item auto
25054The default ABI associated with the current binary (this is the
25055default).
25056@item o32
25057@item o64
25058@item n32
25059@item n64
25060@item eabi32
25061@item eabi64
a64548ea
EZ
25062@end table
25063
25064@item show mips abi
25065@kindex show mips abi
eb17f351 25066Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 25067
4cc0665f
MR
25068@item set mips compression @var{arg}
25069@kindex set mips compression
25070@cindex code compression, @acronym{MIPS}
25071Tell @value{GDBN} which @acronym{MIPS} compressed
25072@acronym{ISA, Instruction Set Architecture} encoding is used by the
25073inferior. @value{GDBN} uses this for code disassembly and other
25074internal interpretation purposes. This setting is only referred to
25075when no executable has been associated with the debugging session or
25076the executable does not provide information about the encoding it uses.
25077Otherwise this setting is automatically updated from information
25078provided by the executable.
25079
25080Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25081The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25082executables containing @acronym{MIPS16} code frequently are not
25083identified as such.
25084
25085This setting is ``sticky''; that is, it retains its value across
25086debugging sessions until reset either explicitly with this command or
25087implicitly from an executable.
25088
25089The compiler and/or assembler typically add symbol table annotations to
25090identify functions compiled for the @acronym{MIPS16} or
25091@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25092are present, @value{GDBN} uses them in preference to the global
25093compressed @acronym{ISA} encoding setting.
25094
25095@item show mips compression
25096@kindex show mips compression
25097Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25098@value{GDBN} to debug the inferior.
25099
a64548ea
EZ
25100@item set mipsfpu
25101@itemx show mipsfpu
25102@xref{MIPS Embedded, set mipsfpu}.
25103
25104@item set mips mask-address @var{arg}
25105@kindex set mips mask-address
eb17f351 25106@cindex @acronym{MIPS} addresses, masking
a64548ea 25107This command determines whether the most-significant 32 bits of 64-bit
eb17f351 25108@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
25109@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25110setting, which lets @value{GDBN} determine the correct value.
25111
25112@item show mips mask-address
25113@kindex show mips mask-address
eb17f351 25114Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
25115not.
25116
25117@item set remote-mips64-transfers-32bit-regs
25118@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
25119This command controls compatibility with 64-bit @acronym{MIPS} targets that
25120transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
25121that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25122and 64 bits for other registers, set this option to @samp{on}.
25123
25124@item show remote-mips64-transfers-32bit-regs
25125@kindex show remote-mips64-transfers-32bit-regs
eb17f351 25126Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
25127
25128@item set debug mips
25129@kindex set debug mips
eb17f351 25130This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
25131target code in @value{GDBN}.
25132
25133@item show debug mips
25134@kindex show debug mips
eb17f351 25135Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
25136@end table
25137
25138
25139@node HPPA
25140@subsection HPPA
25141@cindex HPPA support
25142
d3e8051b 25143When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
25144following special commands:
25145
25146@table @code
25147@item set debug hppa
25148@kindex set debug hppa
db2e3e2e 25149This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
25150messages are to be displayed.
25151
25152@item show debug hppa
25153Show whether HPPA debugging messages are displayed.
25154
25155@item maint print unwind @var{address}
25156@kindex maint print unwind@r{, HPPA}
25157This command displays the contents of the unwind table entry at the
25158given @var{address}.
25159
25160@end table
25161
104c1213 25162
4acd40f3
TJB
25163@node PowerPC
25164@subsection PowerPC
25165@cindex PowerPC architecture
25166
25167When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25168pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25169numbers stored in the floating point registers. These values must be stored
25170in two consecutive registers, always starting at an even register like
25171@code{f0} or @code{f2}.
25172
25173The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25174by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25175@code{f2} and @code{f3} for @code{$dl1} and so on.
25176
aeac0ff9 25177For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25178wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25179
a1217d97
SL
25180@node Nios II
25181@subsection Nios II
25182@cindex Nios II architecture
25183
25184When @value{GDBN} is debugging the Nios II architecture,
25185it provides the following special commands:
25186
25187@table @code
25188
25189@item set debug nios2
25190@kindex set debug nios2
25191This command turns on and off debugging messages for the Nios II
25192target code in @value{GDBN}.
25193
25194@item show debug nios2
25195@kindex show debug nios2
25196Show the current setting of Nios II debugging messages.
25197@end table
23d964e7 25198
58afddc6
WP
25199@node Sparc64
25200@subsection Sparc64
25201@cindex Sparc64 support
25202@cindex Application Data Integrity
25203@subsubsection ADI Support
25204
25205The M7 processor supports an Application Data Integrity (ADI) feature that
25206detects invalid data accesses. When software allocates memory and enables
25207ADI on the allocated memory, it chooses a 4-bit version number, sets the
25208version in the upper 4 bits of the 64-bit pointer to that data, and stores
25209the 4-bit version in every cacheline of that data. Hardware saves the latter
25210in spare bits in the cache and memory hierarchy. On each load and store,
25211the processor compares the upper 4 VA (virtual address) bits to the
25212cacheline's version. If there is a mismatch, the processor generates a
25213version mismatch trap which can be either precise or disrupting. The trap
25214is an error condition which the kernel delivers to the process as a SIGSEGV
25215signal.
25216
25217Note that only 64-bit applications can use ADI and need to be built with
25218ADI-enabled.
25219
25220Values of the ADI version tags, which are in granularity of a
25221cacheline (64 bytes), can be viewed or modified.
25222
25223
25224@table @code
25225@kindex adi examine
25226@item adi (examine | x) [ / @var{n} ] @var{addr}
25227
25228The @code{adi examine} command displays the value of one ADI version tag per
25229cacheline.
25230
25231@var{n} is a decimal integer specifying the number in bytes; the default
25232is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25233block size, to display.
25234
25235@var{addr} is the address in user address space where you want @value{GDBN}
25236to begin displaying the ADI version tags.
25237
25238Below is an example of displaying ADI versions of variable "shmaddr".
25239
25240@smallexample
25241(@value{GDBP}) adi x/100 shmaddr
25242 0xfff800010002c000: 0 0
25243@end smallexample
25244
25245@kindex adi assign
25246@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25247
25248The @code{adi assign} command is used to assign new ADI version tag
25249to an address.
25250
25251@var{n} is a decimal integer specifying the number in bytes;
25252the default is 1. It specifies how much ADI version information, at the
25253ratio of 1:ADI block size, to modify.
25254
25255@var{addr} is the address in user address space where you want @value{GDBN}
25256to begin modifying the ADI version tags.
25257
25258@var{tag} is the new ADI version tag.
25259
25260For example, do the following to modify then verify ADI versions of
25261variable "shmaddr":
25262
25263@smallexample
25264(@value{GDBP}) adi a/100 shmaddr = 7
25265(@value{GDBP}) adi x/100 shmaddr
25266 0xfff800010002c000: 7 7
25267@end smallexample
25268
25269@end table
25270
51d21d60
JD
25271@node S12Z
25272@subsection S12Z
25273@cindex S12Z support
25274
25275When @value{GDBN} is debugging the S12Z architecture,
25276it provides the following special command:
25277
25278@table @code
25279@item maint info bdccsr
25280@kindex maint info bdccsr@r{, S12Z}
25281This command displays the current value of the microprocessor's
25282BDCCSR register.
25283@end table
25284
25285
8e04817f
AC
25286@node Controlling GDB
25287@chapter Controlling @value{GDBN}
25288
25289You can alter the way @value{GDBN} interacts with you by using the
25290@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25291data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25292described here.
25293
25294@menu
25295* Prompt:: Prompt
25296* Editing:: Command editing
d620b259 25297* Command History:: Command history
8e04817f 25298* Screen Size:: Screen size
140a4bc0 25299* Output Styling:: Output styling
8e04817f 25300* Numbers:: Numbers
1e698235 25301* ABI:: Configuring the current ABI
bf88dd68 25302* Auto-loading:: Automatically loading associated files
8e04817f
AC
25303* Messages/Warnings:: Optional warnings and messages
25304* Debugging Output:: Optional messages about internal happenings
14fb1bac 25305* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25306@end menu
25307
25308@node Prompt
25309@section Prompt
104c1213 25310
8e04817f 25311@cindex prompt
104c1213 25312
8e04817f
AC
25313@value{GDBN} indicates its readiness to read a command by printing a string
25314called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25315can change the prompt string with the @code{set prompt} command. For
25316instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25317the prompt in one of the @value{GDBN} sessions so that you can always tell
25318which one you are talking to.
104c1213 25319
8e04817f
AC
25320@emph{Note:} @code{set prompt} does not add a space for you after the
25321prompt you set. This allows you to set a prompt which ends in a space
25322or a prompt that does not.
104c1213 25323
8e04817f
AC
25324@table @code
25325@kindex set prompt
25326@item set prompt @var{newprompt}
25327Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25328
8e04817f
AC
25329@kindex show prompt
25330@item show prompt
25331Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25332@end table
25333
fa3a4f15
PM
25334Versions of @value{GDBN} that ship with Python scripting enabled have
25335prompt extensions. The commands for interacting with these extensions
25336are:
25337
25338@table @code
25339@kindex set extended-prompt
25340@item set extended-prompt @var{prompt}
25341Set an extended prompt that allows for substitutions.
25342@xref{gdb.prompt}, for a list of escape sequences that can be used for
25343substitution. Any escape sequences specified as part of the prompt
25344string are replaced with the corresponding strings each time the prompt
25345is displayed.
25346
25347For example:
25348
25349@smallexample
25350set extended-prompt Current working directory: \w (gdb)
25351@end smallexample
25352
25353Note that when an extended-prompt is set, it takes control of the
25354@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25355
25356@kindex show extended-prompt
25357@item show extended-prompt
25358Prints the extended prompt. Any escape sequences specified as part of
25359the prompt string with @code{set extended-prompt}, are replaced with the
25360corresponding strings each time the prompt is displayed.
25361@end table
25362
8e04817f 25363@node Editing
79a6e687 25364@section Command Editing
8e04817f
AC
25365@cindex readline
25366@cindex command line editing
104c1213 25367
703663ab 25368@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25369@sc{gnu} library provides consistent behavior for programs which provide a
25370command line interface to the user. Advantages are @sc{gnu} Emacs-style
25371or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25372substitution, and a storage and recall of command history across
25373debugging sessions.
104c1213 25374
8e04817f
AC
25375You may control the behavior of command line editing in @value{GDBN} with the
25376command @code{set}.
104c1213 25377
8e04817f
AC
25378@table @code
25379@kindex set editing
25380@cindex editing
25381@item set editing
25382@itemx set editing on
25383Enable command line editing (enabled by default).
104c1213 25384
8e04817f
AC
25385@item set editing off
25386Disable command line editing.
104c1213 25387
8e04817f
AC
25388@kindex show editing
25389@item show editing
25390Show whether command line editing is enabled.
104c1213
JM
25391@end table
25392
39037522
TT
25393@ifset SYSTEM_READLINE
25394@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25395@end ifset
25396@ifclear SYSTEM_READLINE
25397@xref{Command Line Editing},
25398@end ifclear
25399for more details about the Readline
703663ab
EZ
25400interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25401encouraged to read that chapter.
25402
11061048
TT
25403@cindex Readline application name
25404@value{GDBN} sets the Readline application name to @samp{gdb}. This
25405is useful for conditions in @file{.inputrc}.
25406
c71acd15
TT
25407@cindex operate-and-get-next
25408@value{GDBN} defines a bindable Readline command,
25409@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25410This command accepts the current line for execution and fetches the
25411next line relative to the current line from the history for editing.
25412Any argument is ignored.
25413
d620b259 25414@node Command History
79a6e687 25415@section Command History
703663ab 25416@cindex command history
8e04817f
AC
25417
25418@value{GDBN} can keep track of the commands you type during your
25419debugging sessions, so that you can be certain of precisely what
25420happened. Use these commands to manage the @value{GDBN} command
25421history facility.
104c1213 25422
703663ab 25423@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25424package, to provide the history facility.
25425@ifset SYSTEM_READLINE
25426@xref{Using History Interactively, , , history, GNU History Library},
25427@end ifset
25428@ifclear SYSTEM_READLINE
25429@xref{Using History Interactively},
25430@end ifclear
25431for the detailed description of the History library.
703663ab 25432
d620b259 25433To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25434the state which is seen by users, prefix it with @samp{server }
25435(@pxref{Server Prefix}). This
d620b259
NR
25436means that this command will not affect the command history, nor will it
25437affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25438pressed on a line by itself.
25439
25440@cindex @code{server}, command prefix
25441The server prefix does not affect the recording of values into the value
25442history; to print a value without recording it into the value history,
25443use the @code{output} command instead of the @code{print} command.
25444
703663ab
EZ
25445Here is the description of @value{GDBN} commands related to command
25446history.
25447
104c1213 25448@table @code
8e04817f
AC
25449@cindex history substitution
25450@cindex history file
25451@kindex set history filename
4644b6e3 25452@cindex @env{GDBHISTFILE}, environment variable
63e163f2 25453@item set history filename @r{[}@var{fname}@r{]}
8e04817f
AC
25454Set the name of the @value{GDBN} command history file to @var{fname}.
25455This is the file where @value{GDBN} reads an initial command history
25456list, and where it writes the command history from this session when it
25457exits. You can access this list through history expansion or through
25458the history command editing characters listed below. This file defaults
25459to the value of the environment variable @code{GDBHISTFILE}, or to
25460@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25461is not set.
104c1213 25462
63e163f2
AB
25463The @code{GDBHISTFILE} environment variable is read after processing
25464any @value{GDBN} initialization files (@pxref{Startup}) and after
25465processing any commands passed using command line options (for
25466example, @code{-ex}).
25467
25468If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25469is the empty string then @value{GDBN} will neither try to load an
25470existing history file, nor will it try to save the history on exit.
25471
9c16f35a
EZ
25472@cindex save command history
25473@kindex set history save
8e04817f
AC
25474@item set history save
25475@itemx set history save on
25476Record command history in a file, whose name may be specified with the
63e163f2
AB
25477@code{set history filename} command. By default, this option is
25478disabled. The command history will be recorded when @value{GDBN}
25479exits. If @code{set history filename} is set to the empty string then
25480history saving is disabled, even when @code{set history save} is
25481@code{on}.
104c1213 25482
8e04817f 25483@item set history save off
63e163f2
AB
25484Don't record the command history into the file specified by @code{set
25485history filename} when @value{GDBN} exits.
104c1213 25486
8e04817f 25487@cindex history size
9c16f35a 25488@kindex set history size
b58c513b 25489@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25490@item set history size @var{size}
f81d1120 25491@itemx set history size unlimited
8e04817f 25492Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25493This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25494to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25495are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25496either a negative number or the empty string, then the number of commands
25497@value{GDBN} keeps in the history list is unlimited.
fc637f04 25498
63e163f2
AB
25499The @code{GDBHISTSIZE} environment variable is read after processing
25500any @value{GDBN} initialization files (@pxref{Startup}) and after
25501processing any commands passed using command line options (for
25502example, @code{-ex}).
25503
fc637f04
PP
25504@cindex remove duplicate history
25505@kindex set history remove-duplicates
25506@item set history remove-duplicates @var{count}
25507@itemx set history remove-duplicates unlimited
25508Control the removal of duplicate history entries in the command history list.
25509If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25510history entries and remove the first entry that is a duplicate of the current
25511entry being added to the command history list. If @var{count} is
25512@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25513removal of duplicate history entries is disabled.
25514
25515Only history entries added during the current session are considered for
25516removal. This option is set to 0 by default.
25517
104c1213
JM
25518@end table
25519
8e04817f 25520History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25521@ifset SYSTEM_READLINE
25522@xref{Event Designators, , , history, GNU History Library},
25523@end ifset
25524@ifclear SYSTEM_READLINE
25525@xref{Event Designators},
25526@end ifclear
25527for more details.
8e04817f 25528
703663ab 25529@cindex history expansion, turn on/off
8e04817f
AC
25530Since @kbd{!} is also the logical not operator in C, history expansion
25531is off by default. If you decide to enable history expansion with the
25532@code{set history expansion on} command, you may sometimes need to
25533follow @kbd{!} (when it is used as logical not, in an expression) with
25534a space or a tab to prevent it from being expanded. The readline
25535history facilities do not attempt substitution on the strings
25536@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25537
25538The commands to control history expansion are:
104c1213
JM
25539
25540@table @code
8e04817f
AC
25541@item set history expansion on
25542@itemx set history expansion
703663ab 25543@kindex set history expansion
8e04817f 25544Enable history expansion. History expansion is off by default.
104c1213 25545
8e04817f
AC
25546@item set history expansion off
25547Disable history expansion.
104c1213 25548
8e04817f
AC
25549@c @group
25550@kindex show history
25551@item show history
25552@itemx show history filename
25553@itemx show history save
25554@itemx show history size
25555@itemx show history expansion
25556These commands display the state of the @value{GDBN} history parameters.
25557@code{show history} by itself displays all four states.
25558@c @end group
25559@end table
25560
25561@table @code
9c16f35a
EZ
25562@kindex show commands
25563@cindex show last commands
25564@cindex display command history
8e04817f
AC
25565@item show commands
25566Display the last ten commands in the command history.
104c1213 25567
8e04817f
AC
25568@item show commands @var{n}
25569Print ten commands centered on command number @var{n}.
25570
25571@item show commands +
25572Print ten commands just after the commands last printed.
104c1213
JM
25573@end table
25574
8e04817f 25575@node Screen Size
79a6e687 25576@section Screen Size
8e04817f 25577@cindex size of screen
f179cf97
EZ
25578@cindex screen size
25579@cindex pagination
25580@cindex page size
8e04817f 25581@cindex pauses in output
104c1213 25582
8e04817f
AC
25583Certain commands to @value{GDBN} may produce large amounts of
25584information output to the screen. To help you read all of it,
25585@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25586output. Type @key{RET} when you want to see one more page of output,
25587@kbd{q} to discard the remaining output, or @kbd{c} to continue
25588without paging for the rest of the current command. Also, the screen
25589width setting determines when to wrap lines of output. Depending on
25590what is being printed, @value{GDBN} tries to break the line at a
25591readable place, rather than simply letting it overflow onto the
25592following line.
8e04817f
AC
25593
25594Normally @value{GDBN} knows the size of the screen from the terminal
25595driver software. For example, on Unix @value{GDBN} uses the termcap data base
25596together with the value of the @code{TERM} environment variable and the
25597@code{stty rows} and @code{stty cols} settings. If this is not correct,
25598you can override it with the @code{set height} and @code{set
25599width} commands:
25600
25601@table @code
25602@kindex set height
25603@kindex set width
25604@kindex show width
25605@kindex show height
25606@item set height @var{lpp}
f81d1120 25607@itemx set height unlimited
8e04817f
AC
25608@itemx show height
25609@itemx set width @var{cpl}
f81d1120 25610@itemx set width unlimited
8e04817f
AC
25611@itemx show width
25612These @code{set} commands specify a screen height of @var{lpp} lines and
25613a screen width of @var{cpl} characters. The associated @code{show}
25614commands display the current settings.
104c1213 25615
f81d1120
PA
25616If you specify a height of either @code{unlimited} or zero lines,
25617@value{GDBN} does not pause during output no matter how long the
25618output is. This is useful if output is to a file or to an editor
25619buffer.
104c1213 25620
f81d1120
PA
25621Likewise, you can specify @samp{set width unlimited} or @samp{set
25622width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25623
25624@item set pagination on
25625@itemx set pagination off
25626@kindex set pagination
25627Turn the output pagination on or off; the default is on. Turning
f81d1120 25628pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25629running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25630Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25631
25632@item show pagination
25633@kindex show pagination
25634Show the current pagination mode.
104c1213
JM
25635@end table
25636
140a4bc0
TT
25637@node Output Styling
25638@section Output Styling
25639@cindex styling
25640@cindex colors
25641
25642@kindex set style
25643@kindex show style
25644@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25645enabled by default on most systems, but disabled by default when in
25646batch mode (@pxref{Mode Options}). Various style settings are available;
25647and styles can also be disabled entirely.
140a4bc0
TT
25648
25649@table @code
25650@item set style enabled @samp{on|off}
25651Enable or disable all styling. The default is host-dependent, with
25652most hosts defaulting to @samp{on}.
25653
25654@item show style enabled
25655Show the current state of styling.
d085f989
TT
25656
25657@item set style sources @samp{on|off}
25658Enable or disable source code styling. This affects whether source
25659code, such as the output of the @code{list} command, is styled. Note
25660that source styling only works if styling in general is enabled, and
25661if @value{GDBN} was linked with the GNU Source Highlight library. The
25662default is @samp{on}.
25663
25664@item show style sources
25665Show the current state of source code styling.
140a4bc0
TT
25666@end table
25667
25668Subcommands of @code{set style} control specific forms of styling.
25669These subcommands all follow the same pattern: each style-able object
25670can be styled with a foreground color, a background color, and an
25671intensity.
25672
25673For example, the style of file names can be controlled using the
25674@code{set style filename} group of commands:
25675
25676@table @code
25677@item set style filename background @var{color}
25678Set the background to @var{color}. Valid colors are @samp{none}
25679(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25680@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25681and@samp{white}.
25682
25683@item set style filename foreground @var{color}
25684Set the foreground to @var{color}. Valid colors are @samp{none}
25685(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25686@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25687and@samp{white}.
25688
25689@item set style filename intensity @var{value}
25690Set the intensity to @var{value}. Valid intensities are @samp{normal}
25691(the default), @samp{bold}, and @samp{dim}.
25692@end table
25693
e664d728
PW
25694The @code{show style} command and its subcommands are styling
25695a style name in their output using its own style.
25696So, use @command{show style} to see the complete list of styles,
25697their characteristics and the visual aspect of each style.
25698
140a4bc0
TT
25699The style-able objects are:
25700@table @code
25701@item filename
e3624a40
EZ
25702Control the styling of file names. By default, this style's
25703foreground color is green.
140a4bc0
TT
25704
25705@item function
25706Control the styling of function names. These are managed with the
e3624a40
EZ
25707@code{set style function} family of commands. By default, this
25708style's foreground color is yellow.
140a4bc0
TT
25709
25710@item variable
25711Control the styling of variable names. These are managed with the
e3624a40
EZ
25712@code{set style variable} family of commands. By default, this style's
25713foreground color is cyan.
140a4bc0
TT
25714
25715@item address
25716Control the styling of addresses. These are managed with the
e3624a40
EZ
25717@code{set style address} family of commands. By default, this style's
25718foreground color is blue.
e664d728
PW
25719
25720@item title
25721Control the styling of titles. These are managed with the
25722@code{set style title} family of commands. By default, this style's
25723intensity is bold. Commands are using the title style to improve
6b92c0d3 25724the readability of large output. For example, the commands
e664d728
PW
25725@command{apropos} and @command{help} are using the title style
25726for the command names.
25727
25728@item highlight
25729Control the styling of highlightings. These are managed with the
25730@code{set style highlight} family of commands. By default, this style's
25731foreground color is red. Commands are using the highlight style to draw
25732the user attention to some specific parts of their output. For example,
25733the command @command{apropos -v REGEXP} uses the highlight style to
25734mark the documentation parts matching @var{regexp}.
25735
a2a7af0c
TT
25736@item tui-border
25737Control the styling of the TUI border. Note that, unlike other
25738styling options, only the color of the border can be controlled via
25739@code{set style}. This was done for compatibility reasons, as TUI
25740controls to set the border's intensity predated the addition of
25741general styling to @value{GDBN}. @xref{TUI Configuration}.
25742
25743@item tui-active-border
25744Control the styling of the active TUI border; that is, the TUI window
25745that has the focus.
25746
140a4bc0
TT
25747@end table
25748
8e04817f
AC
25749@node Numbers
25750@section Numbers
25751@cindex number representation
25752@cindex entering numbers
104c1213 25753
8e04817f
AC
25754You can always enter numbers in octal, decimal, or hexadecimal in
25755@value{GDBN} by the usual conventions: octal numbers begin with
25756@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25757begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25758@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2575910; likewise, the default display for numbers---when no particular
25760format is specified---is base 10. You can change the default base for
25761both input and output with the commands described below.
104c1213 25762
8e04817f
AC
25763@table @code
25764@kindex set input-radix
25765@item set input-radix @var{base}
25766Set the default base for numeric input. Supported choices
697aa1b7 25767for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25768specified either unambiguously or using the current input radix; for
8e04817f 25769example, any of
104c1213 25770
8e04817f 25771@smallexample
9c16f35a
EZ
25772set input-radix 012
25773set input-radix 10.
25774set input-radix 0xa
8e04817f 25775@end smallexample
104c1213 25776
8e04817f 25777@noindent
9c16f35a 25778sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25779leaves the input radix unchanged, no matter what it was, since
25780@samp{10}, being without any leading or trailing signs of its base, is
25781interpreted in the current radix. Thus, if the current radix is 16,
25782@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25783change the radix.
104c1213 25784
8e04817f
AC
25785@kindex set output-radix
25786@item set output-radix @var{base}
25787Set the default base for numeric display. Supported choices
697aa1b7 25788for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25789specified either unambiguously or using the current input radix.
104c1213 25790
8e04817f
AC
25791@kindex show input-radix
25792@item show input-radix
25793Display the current default base for numeric input.
104c1213 25794
8e04817f
AC
25795@kindex show output-radix
25796@item show output-radix
25797Display the current default base for numeric display.
9c16f35a
EZ
25798
25799@item set radix @r{[}@var{base}@r{]}
25800@itemx show radix
25801@kindex set radix
25802@kindex show radix
25803These commands set and show the default base for both input and output
25804of numbers. @code{set radix} sets the radix of input and output to
25805the same base; without an argument, it resets the radix back to its
25806default value of 10.
25807
8e04817f 25808@end table
104c1213 25809
1e698235 25810@node ABI
79a6e687 25811@section Configuring the Current ABI
1e698235
DJ
25812
25813@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25814application automatically. However, sometimes you need to override its
25815conclusions. Use these commands to manage @value{GDBN}'s view of the
25816current ABI.
25817
98b45e30
DJ
25818@cindex OS ABI
25819@kindex set osabi
b4e9345d 25820@kindex show osabi
430ed3f0 25821@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25822
25823One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25824system targets, either via remote debugging or native emulation.
98b45e30
DJ
25825@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25826but you can override its conclusion using the @code{set osabi} command.
25827One example where this is useful is in debugging of binaries which use
25828an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25829not have the same identifying marks that the standard C library for your
25830platform provides.
25831
430ed3f0
MS
25832When @value{GDBN} is debugging the AArch64 architecture, it provides a
25833``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25834@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25835The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25836
98b45e30
DJ
25837@table @code
25838@item show osabi
25839Show the OS ABI currently in use.
25840
25841@item set osabi
25842With no argument, show the list of registered available OS ABI's.
25843
25844@item set osabi @var{abi}
25845Set the current OS ABI to @var{abi}.
25846@end table
25847
1e698235 25848@cindex float promotion
1e698235
DJ
25849
25850Generally, the way that an argument of type @code{float} is passed to a
25851function depends on whether the function is prototyped. For a prototyped
25852(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25853according to the architecture's convention for @code{float}. For unprototyped
25854(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25855@code{double} and then passed.
25856
25857Unfortunately, some forms of debug information do not reliably indicate whether
25858a function is prototyped. If @value{GDBN} calls a function that is not marked
25859as prototyped, it consults @kbd{set coerce-float-to-double}.
25860
25861@table @code
a8f24a35 25862@kindex set coerce-float-to-double
1e698235
DJ
25863@item set coerce-float-to-double
25864@itemx set coerce-float-to-double on
25865Arguments of type @code{float} will be promoted to @code{double} when passed
25866to an unprototyped function. This is the default setting.
25867
25868@item set coerce-float-to-double off
25869Arguments of type @code{float} will be passed directly to unprototyped
25870functions.
9c16f35a
EZ
25871
25872@kindex show coerce-float-to-double
25873@item show coerce-float-to-double
25874Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
25875@end table
25876
f1212245
DJ
25877@kindex set cp-abi
25878@kindex show cp-abi
25879@value{GDBN} needs to know the ABI used for your program's C@t{++}
25880objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25881used to build your application. @value{GDBN} only fully supports
25882programs with a single C@t{++} ABI; if your program contains code using
25883multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25884program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25885Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25886before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25887``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25888use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25889``auto''.
25890
25891@table @code
25892@item show cp-abi
25893Show the C@t{++} ABI currently in use.
25894
25895@item set cp-abi
25896With no argument, show the list of supported C@t{++} ABI's.
25897
25898@item set cp-abi @var{abi}
25899@itemx set cp-abi auto
25900Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25901@end table
25902
bf88dd68
JK
25903@node Auto-loading
25904@section Automatically loading associated files
25905@cindex auto-loading
25906
25907@value{GDBN} sometimes reads files with commands and settings automatically,
25908without being explicitly told so by the user. We call this feature
25909@dfn{auto-loading}. While auto-loading is useful for automatically adapting
25910@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25911results or introduce security risks (e.g., if the file comes from untrusted
25912sources).
25913
71b8c845
DE
25914@menu
25915* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25916* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25917
25918* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25919* Auto-loading verbose mode:: @samp{set/show debug auto-load}
25920@end menu
25921
25922There are various kinds of files @value{GDBN} can automatically load.
25923In addition to these files, @value{GDBN} supports auto-loading code written
25924in various extension languages. @xref{Auto-loading extensions}.
25925
c1668e4e
JK
25926Note that loading of these associated files (including the local @file{.gdbinit}
25927file) requires accordingly configured @code{auto-load safe-path}
25928(@pxref{Auto-loading safe path}).
25929
bf88dd68
JK
25930For these reasons, @value{GDBN} includes commands and options to let you
25931control when to auto-load files and which files should be auto-loaded.
25932
25933@table @code
25934@anchor{set auto-load off}
25935@kindex set auto-load off
25936@item set auto-load off
25937Globally disable loading of all auto-loaded files.
25938You may want to use this command with the @samp{-iex} option
25939(@pxref{Option -init-eval-command}) such as:
25940@smallexample
25941$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25942@end smallexample
25943
25944Be aware that system init file (@pxref{System-wide configuration})
25945and init files from your home directory (@pxref{Home Directory Init File})
25946still get read (as they come from generally trusted directories).
25947To prevent @value{GDBN} from auto-loading even those init files, use the
25948@option{-nx} option (@pxref{Mode Options}), in addition to
25949@code{set auto-load no}.
25950
25951@anchor{show auto-load}
25952@kindex show auto-load
25953@item show auto-load
25954Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25955or disabled.
25956
25957@smallexample
25958(gdb) show auto-load
25959gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25960libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
25961local-gdbinit: Auto-loading of .gdbinit script from current directory
25962 is on.
bf88dd68 25963python-scripts: Auto-loading of Python scripts is on.
bccbefd2 25964safe-path: List of directories from which it is safe to auto-load files
1564a261 25965 is $debugdir:$datadir/auto-load.
7349ff92 25966scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 25967 is $debugdir:$datadir/auto-load.
bf88dd68
JK
25968@end smallexample
25969
25970@anchor{info auto-load}
25971@kindex info auto-load
25972@item info auto-load
25973Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25974not.
25975
25976@smallexample
25977(gdb) info auto-load
25978gdb-scripts:
25979Loaded Script
25980Yes /home/user/gdb/gdb-gdb.gdb
25981libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
25982local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25983 loaded.
bf88dd68
JK
25984python-scripts:
25985Loaded Script
25986Yes /home/user/gdb/gdb-gdb.py
25987@end smallexample
25988@end table
25989
bf88dd68
JK
25990These are @value{GDBN} control commands for the auto-loading:
25991
25992@multitable @columnfractions .5 .5
25993@item @xref{set auto-load off}.
25994@tab Disable auto-loading globally.
25995@item @xref{show auto-load}.
25996@tab Show setting of all kinds of files.
25997@item @xref{info auto-load}.
25998@tab Show state of all kinds of files.
25999@item @xref{set auto-load gdb-scripts}.
26000@tab Control for @value{GDBN} command scripts.
26001@item @xref{show auto-load gdb-scripts}.
26002@tab Show setting of @value{GDBN} command scripts.
26003@item @xref{info auto-load gdb-scripts}.
26004@tab Show state of @value{GDBN} command scripts.
26005@item @xref{set auto-load python-scripts}.
26006@tab Control for @value{GDBN} Python scripts.
26007@item @xref{show auto-load python-scripts}.
26008@tab Show setting of @value{GDBN} Python scripts.
26009@item @xref{info auto-load python-scripts}.
26010@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
26011@item @xref{set auto-load guile-scripts}.
26012@tab Control for @value{GDBN} Guile scripts.
26013@item @xref{show auto-load guile-scripts}.
26014@tab Show setting of @value{GDBN} Guile scripts.
26015@item @xref{info auto-load guile-scripts}.
26016@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
26017@item @xref{set auto-load scripts-directory}.
26018@tab Control for @value{GDBN} auto-loaded scripts location.
26019@item @xref{show auto-load scripts-directory}.
26020@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
26021@item @xref{add-auto-load-scripts-directory}.
26022@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
26023@item @xref{set auto-load local-gdbinit}.
26024@tab Control for init file in the current directory.
26025@item @xref{show auto-load local-gdbinit}.
26026@tab Show setting of init file in the current directory.
26027@item @xref{info auto-load local-gdbinit}.
26028@tab Show state of init file in the current directory.
26029@item @xref{set auto-load libthread-db}.
26030@tab Control for thread debugging library.
26031@item @xref{show auto-load libthread-db}.
26032@tab Show setting of thread debugging library.
26033@item @xref{info auto-load libthread-db}.
26034@tab Show state of thread debugging library.
bccbefd2
JK
26035@item @xref{set auto-load safe-path}.
26036@tab Control directories trusted for automatic loading.
26037@item @xref{show auto-load safe-path}.
26038@tab Show directories trusted for automatic loading.
26039@item @xref{add-auto-load-safe-path}.
26040@tab Add directory trusted for automatic loading.
bf88dd68
JK
26041@end multitable
26042
bf88dd68
JK
26043@node Init File in the Current Directory
26044@subsection Automatically loading init file in the current directory
26045@cindex auto-loading init file in the current directory
26046
26047By default, @value{GDBN} reads and executes the canned sequences of commands
26048from init file (if any) in the current working directory,
26049see @ref{Init File in the Current Directory during Startup}.
26050
c1668e4e
JK
26051Note that loading of this local @file{.gdbinit} file also requires accordingly
26052configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26053
bf88dd68
JK
26054@table @code
26055@anchor{set auto-load local-gdbinit}
26056@kindex set auto-load local-gdbinit
26057@item set auto-load local-gdbinit [on|off]
26058Enable or disable the auto-loading of canned sequences of commands
26059(@pxref{Sequences}) found in init file in the current directory.
26060
26061@anchor{show auto-load local-gdbinit}
26062@kindex show auto-load local-gdbinit
26063@item show auto-load local-gdbinit
26064Show whether auto-loading of canned sequences of commands from init file in the
26065current directory is enabled or disabled.
26066
26067@anchor{info auto-load local-gdbinit}
26068@kindex info auto-load local-gdbinit
26069@item info auto-load local-gdbinit
26070Print whether canned sequences of commands from init file in the
26071current directory have been auto-loaded.
26072@end table
26073
26074@node libthread_db.so.1 file
26075@subsection Automatically loading thread debugging library
26076@cindex auto-loading libthread_db.so.1
26077
26078This feature is currently present only on @sc{gnu}/Linux native hosts.
26079
26080@value{GDBN} reads in some cases thread debugging library from places specific
26081to the inferior (@pxref{set libthread-db-search-path}).
26082
26083The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26084without checking this @samp{set auto-load libthread-db} switch as system
26085libraries have to be trusted in general. In all other cases of
26086@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26087auto-load libthread-db} is enabled before trying to open such thread debugging
26088library.
26089
c1668e4e
JK
26090Note that loading of this debugging library also requires accordingly configured
26091@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26092
bf88dd68
JK
26093@table @code
26094@anchor{set auto-load libthread-db}
26095@kindex set auto-load libthread-db
26096@item set auto-load libthread-db [on|off]
26097Enable or disable the auto-loading of inferior specific thread debugging library.
26098
26099@anchor{show auto-load libthread-db}
26100@kindex show auto-load libthread-db
26101@item show auto-load libthread-db
26102Show whether auto-loading of inferior specific thread debugging library is
26103enabled or disabled.
26104
26105@anchor{info auto-load libthread-db}
26106@kindex info auto-load libthread-db
26107@item info auto-load libthread-db
26108Print the list of all loaded inferior specific thread debugging libraries and
26109for each such library print list of inferior @var{pid}s using it.
26110@end table
26111
bccbefd2
JK
26112@node Auto-loading safe path
26113@subsection Security restriction for auto-loading
26114@cindex auto-loading safe-path
26115
26116As the files of inferior can come from untrusted source (such as submitted by
26117an application user) @value{GDBN} does not always load any files automatically.
26118@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26119directories trusted for loading files not explicitly requested by user.
202cbf1c 26120Each directory can also be a shell wildcard pattern.
bccbefd2
JK
26121
26122If the path is not set properly you will see a warning and the file will not
26123get loaded:
26124
26125@smallexample
26126$ ./gdb -q ./gdb
0bab6cf1 26127Reading symbols from /home/user/gdb/gdb...
bccbefd2 26128warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
26129 declined by your `auto-load safe-path' set
26130 to "$debugdir:$datadir/auto-load".
bccbefd2 26131warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
26132 declined by your `auto-load safe-path' set
26133 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
26134@end smallexample
26135
2c91021c
JK
26136@noindent
26137To instruct @value{GDBN} to go ahead and use the init files anyway,
26138invoke @value{GDBN} like this:
26139
26140@smallexample
26141$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26142@end smallexample
26143
bccbefd2
JK
26144The list of trusted directories is controlled by the following commands:
26145
26146@table @code
26147@anchor{set auto-load safe-path}
26148@kindex set auto-load safe-path
af2c1515 26149@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
26150Set the list of directories (and their subdirectories) trusted for automatic
26151loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
26152Each directory can also be a shell wildcard pattern; wildcards do not match
26153directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26154(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
26155If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26156its default value as specified during @value{GDBN} compilation.
26157
d9242c17 26158The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
26159systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26160to the @env{PATH} environment variable.
26161
26162@anchor{show auto-load safe-path}
26163@kindex show auto-load safe-path
26164@item show auto-load safe-path
26165Show the list of directories trusted for automatic loading and execution of
26166scripts.
26167
26168@anchor{add-auto-load-safe-path}
26169@kindex add-auto-load-safe-path
26170@item add-auto-load-safe-path
413b59ae
JK
26171Add an entry (or list of entries) to the list of directories trusted for
26172automatic loading and execution of scripts. Multiple entries may be delimited
26173by the host platform path separator in use.
bccbefd2
JK
26174@end table
26175
7349ff92 26176This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
26177to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26178substitution applies the same as for @ref{set auto-load scripts-directory}.
26179The default @code{set auto-load safe-path} value can be also overriden by
26180@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 26181
6dea1fbd
JK
26182Setting this variable to @file{/} disables this security protection,
26183corresponding @value{GDBN} configuration option is
26184@option{--without-auto-load-safe-path}.
bccbefd2
JK
26185This variable is supposed to be set to the system directories writable by the
26186system superuser only. Users can add their source directories in init files in
26187their home directories (@pxref{Home Directory Init File}). See also deprecated
26188init file in the current directory
26189(@pxref{Init File in the Current Directory during Startup}).
26190
26191To force @value{GDBN} to load the files it declined to load in the previous
26192example, you could use one of the following ways:
26193
0511cc75
JK
26194@table @asis
26195@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26196Specify this trusted directory (or a file) as additional component of the list.
26197You have to specify also any existing directories displayed by
26198by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26199
174bb630 26200@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26201Specify this directory as in the previous case but just for a single
26202@value{GDBN} session.
26203
af2c1515 26204@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26205Disable auto-loading safety for a single @value{GDBN} session.
26206This assumes all the files you debug during this @value{GDBN} session will come
26207from trusted sources.
26208
26209@item @kbd{./configure --without-auto-load-safe-path}
26210During compilation of @value{GDBN} you may disable any auto-loading safety.
26211This assumes all the files you will ever debug with this @value{GDBN} come from
26212trusted sources.
0511cc75 26213@end table
bccbefd2
JK
26214
26215On the other hand you can also explicitly forbid automatic files loading which
26216also suppresses any such warning messages:
26217
0511cc75 26218@table @asis
174bb630 26219@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26220You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26221
0511cc75 26222@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26223Disable auto-loading globally for the user
26224(@pxref{Home Directory Init File}). While it is improbable, you could also
26225use system init file instead (@pxref{System-wide configuration}).
0511cc75 26226@end table
bccbefd2
JK
26227
26228This setting applies to the file names as entered by user. If no entry matches
26229@value{GDBN} tries as a last resort to also resolve all the file names into
26230their canonical form (typically resolving symbolic links) and compare the
26231entries again. @value{GDBN} already canonicalizes most of the filenames on its
26232own before starting the comparison so a canonical form of directories is
26233recommended to be entered.
26234
4dc84fd1
JK
26235@node Auto-loading verbose mode
26236@subsection Displaying files tried for auto-load
26237@cindex auto-loading verbose mode
26238
26239For better visibility of all the file locations where you can place scripts to
26240be auto-loaded with inferior --- or to protect yourself against accidental
26241execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26242all the files attempted to be loaded. Both existing and non-existing files may
26243be printed.
26244
26245For example the list of directories from which it is safe to auto-load files
26246(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26247may not be too obvious while setting it up.
26248
26249@smallexample
0070f25a 26250(gdb) set debug auto-load on
4dc84fd1
JK
26251(gdb) file ~/src/t/true
26252auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26253 for objfile "/tmp/true".
26254auto-load: Updating directories of "/usr:/opt".
26255auto-load: Using directory "/usr".
26256auto-load: Using directory "/opt".
26257warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26258 by your `auto-load safe-path' set to "/usr:/opt".
26259@end smallexample
26260
26261@table @code
26262@anchor{set debug auto-load}
26263@kindex set debug auto-load
26264@item set debug auto-load [on|off]
26265Set whether to print the filenames attempted to be auto-loaded.
26266
26267@anchor{show debug auto-load}
26268@kindex show debug auto-load
26269@item show debug auto-load
26270Show whether printing of the filenames attempted to be auto-loaded is turned
26271on or off.
26272@end table
26273
8e04817f 26274@node Messages/Warnings
79a6e687 26275@section Optional Warnings and Messages
104c1213 26276
9c16f35a
EZ
26277@cindex verbose operation
26278@cindex optional warnings
8e04817f
AC
26279By default, @value{GDBN} is silent about its inner workings. If you are
26280running on a slow machine, you may want to use the @code{set verbose}
26281command. This makes @value{GDBN} tell you when it does a lengthy
26282internal operation, so you will not think it has crashed.
104c1213 26283
8e04817f
AC
26284Currently, the messages controlled by @code{set verbose} are those
26285which announce that the symbol table for a source file is being read;
79a6e687 26286see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26287
8e04817f
AC
26288@table @code
26289@kindex set verbose
26290@item set verbose on
26291Enables @value{GDBN} output of certain informational messages.
104c1213 26292
8e04817f
AC
26293@item set verbose off
26294Disables @value{GDBN} output of certain informational messages.
104c1213 26295
8e04817f
AC
26296@kindex show verbose
26297@item show verbose
26298Displays whether @code{set verbose} is on or off.
26299@end table
104c1213 26300
8e04817f
AC
26301By default, if @value{GDBN} encounters bugs in the symbol table of an
26302object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26303find this information useful (@pxref{Symbol Errors, ,Errors Reading
26304Symbol Files}).
104c1213 26305
8e04817f 26306@table @code
104c1213 26307
8e04817f
AC
26308@kindex set complaints
26309@item set complaints @var{limit}
26310Permits @value{GDBN} to output @var{limit} complaints about each type of
26311unusual symbols before becoming silent about the problem. Set
26312@var{limit} to zero to suppress all complaints; set it to a large number
26313to prevent complaints from being suppressed.
104c1213 26314
8e04817f
AC
26315@kindex show complaints
26316@item show complaints
26317Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26318
8e04817f 26319@end table
104c1213 26320
d837706a 26321@anchor{confirmation requests}
8e04817f
AC
26322By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26323lot of stupid questions to confirm certain commands. For example, if
26324you try to run a program which is already running:
104c1213 26325
474c8240 26326@smallexample
8e04817f
AC
26327(@value{GDBP}) run
26328The program being debugged has been started already.
26329Start it from the beginning? (y or n)
474c8240 26330@end smallexample
104c1213 26331
8e04817f
AC
26332If you are willing to unflinchingly face the consequences of your own
26333commands, you can disable this ``feature'':
104c1213 26334
8e04817f 26335@table @code
104c1213 26336
8e04817f
AC
26337@kindex set confirm
26338@cindex flinching
26339@cindex confirmation
26340@cindex stupid questions
26341@item set confirm off
7c953934
TT
26342Disables confirmation requests. Note that running @value{GDBN} with
26343the @option{--batch} option (@pxref{Mode Options, -batch}) also
26344automatically disables confirmation requests.
104c1213 26345
8e04817f
AC
26346@item set confirm on
26347Enables confirmation requests (the default).
104c1213 26348
8e04817f
AC
26349@kindex show confirm
26350@item show confirm
26351Displays state of confirmation requests.
26352
26353@end table
104c1213 26354
16026cd7
AS
26355@cindex command tracing
26356If you need to debug user-defined commands or sourced files you may find it
26357useful to enable @dfn{command tracing}. In this mode each command will be
26358printed as it is executed, prefixed with one or more @samp{+} symbols, the
26359quantity denoting the call depth of each command.
26360
26361@table @code
26362@kindex set trace-commands
26363@cindex command scripts, debugging
26364@item set trace-commands on
26365Enable command tracing.
26366@item set trace-commands off
26367Disable command tracing.
26368@item show trace-commands
26369Display the current state of command tracing.
26370@end table
26371
8e04817f 26372@node Debugging Output
79a6e687 26373@section Optional Messages about Internal Happenings
4644b6e3
EZ
26374@cindex optional debugging messages
26375
da316a69
EZ
26376@value{GDBN} has commands that enable optional debugging messages from
26377various @value{GDBN} subsystems; normally these commands are of
26378interest to @value{GDBN} maintainers, or when reporting a bug. This
26379section documents those commands.
26380
104c1213 26381@table @code
a8f24a35
EZ
26382@kindex set exec-done-display
26383@item set exec-done-display
26384Turns on or off the notification of asynchronous commands'
26385completion. When on, @value{GDBN} will print a message when an
26386asynchronous command finishes its execution. The default is off.
26387@kindex show exec-done-display
26388@item show exec-done-display
26389Displays the current setting of asynchronous command completion
26390notification.
4644b6e3 26391@kindex set debug
be9a8770
PA
26392@cindex ARM AArch64
26393@item set debug aarch64
26394Turns on or off display of debugging messages related to ARM AArch64.
26395The default is off.
26396@kindex show debug
26397@item show debug aarch64
26398Displays the current state of displaying debugging messages related to
26399ARM AArch64.
4644b6e3 26400@cindex gdbarch debugging info
a8f24a35 26401@cindex architecture debugging info
8e04817f 26402@item set debug arch
a8f24a35 26403Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26404@item show debug arch
26405Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
26406@item set debug aix-solib
26407@cindex AIX shared library debugging
26408Control display of debugging messages from the AIX shared library
26409support module. The default is off.
26410@item show debug aix-thread
26411Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
26412@item set debug aix-thread
26413@cindex AIX threads
26414Display debugging messages about inner workings of the AIX thread
26415module.
26416@item show debug aix-thread
26417Show the current state of AIX thread debugging info display.
900e11f9
JK
26418@item set debug check-physname
26419@cindex physname
26420Check the results of the ``physname'' computation. When reading DWARF
26421debugging information for C@t{++}, @value{GDBN} attempts to compute
26422each entity's name. @value{GDBN} can do this computation in two
26423different ways, depending on exactly what information is present.
26424When enabled, this setting causes @value{GDBN} to compute the names
26425both ways and display any discrepancies.
26426@item show debug check-physname
26427Show the current state of ``physname'' checking.
be9a8770
PA
26428@item set debug coff-pe-read
26429@cindex COFF/PE exported symbols
26430Control display of debugging messages related to reading of COFF/PE
26431exported symbols. The default is off.
26432@item show debug coff-pe-read
26433Displays the current state of displaying debugging messages related to
26434reading of COFF/PE exported symbols.
b4f54984
DE
26435@item set debug dwarf-die
26436@cindex DWARF DIEs
26437Dump DWARF DIEs after they are read in.
d97bc12b
DE
26438The value is the number of nesting levels to print.
26439A value of zero turns off the display.
b4f54984
DE
26440@item show debug dwarf-die
26441Show the current state of DWARF DIE debugging.
27e0867f
DE
26442@item set debug dwarf-line
26443@cindex DWARF Line Tables
26444Turns on or off display of debugging messages related to reading
26445DWARF line tables. The default is 0 (off).
26446A value of 1 provides basic information.
26447A value greater than 1 provides more verbose information.
26448@item show debug dwarf-line
26449Show the current state of DWARF line table debugging.
b4f54984
DE
26450@item set debug dwarf-read
26451@cindex DWARF Reading
45cfd468 26452Turns on or off display of debugging messages related to reading
73be47f5
DE
26453DWARF debug info. The default is 0 (off).
26454A value of 1 provides basic information.
26455A value greater than 1 provides more verbose information.
b4f54984
DE
26456@item show debug dwarf-read
26457Show the current state of DWARF reader debugging.
237fc4c9
PA
26458@item set debug displaced
26459@cindex displaced stepping debugging info
26460Turns on or off display of @value{GDBN} debugging info for the
26461displaced stepping support. The default is off.
26462@item show debug displaced
26463Displays the current state of displaying @value{GDBN} debugging info
26464related to displaced stepping.
8e04817f 26465@item set debug event
4644b6e3 26466@cindex event debugging info
a8f24a35 26467Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26468default is off.
8e04817f
AC
26469@item show debug event
26470Displays the current state of displaying @value{GDBN} event debugging
26471info.
8e04817f 26472@item set debug expression
4644b6e3 26473@cindex expression debugging info
721c2651
EZ
26474Turns on or off display of debugging info about @value{GDBN}
26475expression parsing. The default is off.
8e04817f 26476@item show debug expression
721c2651
EZ
26477Displays the current state of displaying debugging info about
26478@value{GDBN} expression parsing.
6e9567fe
JB
26479@item set debug fbsd-lwp
26480@cindex FreeBSD LWP debug messages
26481Turns on or off debugging messages from the FreeBSD LWP debug support.
26482@item show debug fbsd-lwp
26483Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
26484@item set debug fbsd-nat
26485@cindex FreeBSD native target debug messages
26486Turns on or off debugging messages from the FreeBSD native target.
26487@item show debug fbsd-nat
26488Show the current state of FreeBSD native target debugging messages.
7453dc06 26489@item set debug frame
4644b6e3 26490@cindex frame debugging info
7453dc06
AC
26491Turns on or off display of @value{GDBN} frame debugging info. The
26492default is off.
7453dc06
AC
26493@item show debug frame
26494Displays the current state of displaying @value{GDBN} frame debugging
26495info.
cbe54154
PA
26496@item set debug gnu-nat
26497@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26498Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26499@item show debug gnu-nat
26500Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
26501@item set debug infrun
26502@cindex inferior debugging info
26503Turns on or off display of @value{GDBN} debugging info for running the inferior.
26504The default is off. @file{infrun.c} contains GDB's runtime state machine used
26505for implementing operations such as single-stepping the inferior.
26506@item show debug infrun
26507Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
26508@item set debug jit
26509@cindex just-in-time compilation, debugging messages
67ebd9cb 26510Turn on or off debugging messages from JIT debug support.
a255712f
PP
26511@item show debug jit
26512Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
26513@item set debug lin-lwp
26514@cindex @sc{gnu}/Linux LWP debug messages
26515@cindex Linux lightweight processes
67ebd9cb 26516Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26517@item show debug lin-lwp
26518Show the current state of Linux LWP debugging messages.
7a6a1731
GB
26519@item set debug linux-namespaces
26520@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26521Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26522@item show debug linux-namespaces
26523Show the current state of Linux namespaces debugging messages.
be9a8770
PA
26524@item set debug mach-o
26525@cindex Mach-O symbols processing
26526Control display of debugging messages related to Mach-O symbols
26527processing. The default is off.
26528@item show debug mach-o
26529Displays the current state of displaying debugging messages related to
26530reading of COFF/PE exported symbols.
c9b6281a
YQ
26531@item set debug notification
26532@cindex remote async notification debugging info
67ebd9cb 26533Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26534The default is off.
26535@item show debug notification
26536Displays the current state of remote async notification debugging messages.
2b4855ab 26537@item set debug observer
4644b6e3 26538@cindex observer debugging info
2b4855ab
AC
26539Turns on or off display of @value{GDBN} observer debugging. This
26540includes info such as the notification of observable events.
2b4855ab
AC
26541@item show debug observer
26542Displays the current state of observer debugging.
8e04817f 26543@item set debug overload
4644b6e3 26544@cindex C@t{++} overload debugging info
8e04817f 26545Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26546info. This includes info such as ranking of functions, etc. The default
8e04817f 26547is off.
8e04817f
AC
26548@item show debug overload
26549Displays the current state of displaying @value{GDBN} C@t{++} overload
26550debugging info.
92981e24
TT
26551@cindex expression parser, debugging info
26552@cindex debug expression parser
26553@item set debug parser
26554Turns on or off the display of expression parser debugging output.
26555Internally, this sets the @code{yydebug} variable in the expression
26556parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26557details. The default is off.
26558@item show debug parser
26559Show the current state of expression parser debugging.
8e04817f
AC
26560@cindex packets, reporting on stdout
26561@cindex serial connections, debugging
605a56cb
DJ
26562@cindex debug remote protocol
26563@cindex remote protocol debugging
26564@cindex display remote packets
8e04817f
AC
26565@item set debug remote
26566Turns on or off display of reports on all packets sent back and forth across
26567the serial line to the remote machine. The info is printed on the
26568@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26569@item show debug remote
26570Displays the state of display of remote packets.
c4dcb155 26571
6cc8564b
LM
26572@item set debug remote-packet-max-chars
26573Sets the maximum number of characters to display for each remote packet when
26574@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26575displaying lengthy remote packets and polluting the console.
26576
26577The default value is @code{512}, which means @value{GDBN} will truncate each
26578remote packet after 512 bytes.
26579
26580Setting this option to @code{unlimited} will disable truncation and will output
26581the full length of the remote packets.
26582@item show debug remote-packet-max-chars
26583Displays the number of bytes to output for remote packet debugging.
26584
c4dcb155
SM
26585@item set debug separate-debug-file
26586Turns on or off display of debug output about separate debug file search.
26587@item show debug separate-debug-file
26588Displays the state of separate debug file search debug output.
26589
8e04817f
AC
26590@item set debug serial
26591Turns on or off display of @value{GDBN} serial debugging info. The
26592default is off.
8e04817f
AC
26593@item show debug serial
26594Displays the current state of displaying @value{GDBN} serial debugging
26595info.
c45da7e6
EZ
26596@item set debug solib-frv
26597@cindex FR-V shared-library debugging
67ebd9cb 26598Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26599@item show debug solib-frv
26600Display the current state of FR-V shared-library code debugging
26601messages.
cc485e62
DE
26602@item set debug symbol-lookup
26603@cindex symbol lookup
26604Turns on or off display of debugging messages related to symbol lookup.
26605The default is 0 (off).
26606A value of 1 provides basic information.
26607A value greater than 1 provides more verbose information.
26608@item show debug symbol-lookup
26609Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
26610@item set debug symfile
26611@cindex symbol file functions
26612Turns on or off display of debugging messages related to symbol file functions.
26613The default is off. @xref{Files}.
26614@item show debug symfile
26615Show the current state of symbol file debugging messages.
45cfd468
DE
26616@item set debug symtab-create
26617@cindex symbol table creation
26618Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26619The default is 0 (off).
26620A value of 1 provides basic information.
26621A value greater than 1 provides more verbose information.
45cfd468
DE
26622@item show debug symtab-create
26623Show the current state of symbol table creation debugging.
8e04817f 26624@item set debug target
4644b6e3 26625@cindex target debugging info
8e04817f
AC
26626Turns on or off display of @value{GDBN} target debugging info. This info
26627includes what is going on at the target level of GDB, as it happens. The
701b08bb 26628default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26629value of large memory transfers.
8e04817f
AC
26630@item show debug target
26631Displays the current state of displaying @value{GDBN} target debugging
26632info.
75feb17d 26633@item set debug timestamp
6b92c0d3 26634@cindex timestamping debugging info
75feb17d
DJ
26635Turns on or off display of timestamps with @value{GDBN} debugging info.
26636When enabled, seconds and microseconds are displayed before each debugging
26637message.
26638@item show debug timestamp
26639Displays the current state of displaying timestamps with @value{GDBN}
26640debugging info.
f989a1c8 26641@item set debug varobj
4644b6e3 26642@cindex variable object debugging info
8e04817f
AC
26643Turns on or off display of @value{GDBN} variable object debugging
26644info. The default is off.
f989a1c8 26645@item show debug varobj
8e04817f
AC
26646Displays the current state of displaying @value{GDBN} variable object
26647debugging info.
e776119f
DJ
26648@item set debug xml
26649@cindex XML parser debugging
67ebd9cb 26650Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26651@item show debug xml
26652Displays the current state of XML debugging messages.
8e04817f 26653@end table
104c1213 26654
14fb1bac
JB
26655@node Other Misc Settings
26656@section Other Miscellaneous Settings
26657@cindex miscellaneous settings
26658
26659@table @code
26660@kindex set interactive-mode
26661@item set interactive-mode
7bfc9434
JB
26662If @code{on}, forces @value{GDBN} to assume that GDB was started
26663in a terminal. In practice, this means that @value{GDBN} should wait
26664for the user to answer queries generated by commands entered at
26665the command prompt. If @code{off}, forces @value{GDBN} to operate
26666in the opposite mode, and it uses the default answers to all queries.
26667If @code{auto} (the default), @value{GDBN} tries to determine whether
26668its standard input is a terminal, and works in interactive-mode if it
26669is, non-interactively otherwise.
14fb1bac
JB
26670
26671In the vast majority of cases, the debugger should be able to guess
26672correctly which mode should be used. But this setting can be useful
26673in certain specific cases, such as running a MinGW @value{GDBN}
26674inside a cygwin window.
26675
26676@kindex show interactive-mode
26677@item show interactive-mode
26678Displays whether the debugger is operating in interactive mode or not.
26679@end table
26680
d57a3c85
TJB
26681@node Extending GDB
26682@chapter Extending @value{GDBN}
26683@cindex extending GDB
26684
71b8c845
DE
26685@value{GDBN} provides several mechanisms for extension.
26686@value{GDBN} also provides the ability to automatically load
26687extensions when it reads a file for debugging. This allows the
26688user to automatically customize @value{GDBN} for the program
26689being debugged.
d57a3c85 26690
71b8c845
DE
26691@menu
26692* Sequences:: Canned Sequences of @value{GDBN} Commands
26693* Python:: Extending @value{GDBN} using Python
ed3ef339 26694* Guile:: Extending @value{GDBN} using Guile
71b8c845 26695* Auto-loading extensions:: Automatically loading extensions
ed3ef339 26696* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
26697* Aliases:: Creating new spellings of existing commands
26698@end menu
26699
26700To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26701of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26702can recognize which extension language is being used by looking at
95433b34
JB
26703the filename extension. Files with an unrecognized filename extension
26704are always treated as a @value{GDBN} Command Files.
26705@xref{Command Files,, Command files}.
26706
26707You can control how @value{GDBN} evaluates these files with the following
26708setting:
26709
26710@table @code
26711@kindex set script-extension
26712@kindex show script-extension
26713@item set script-extension off
26714All scripts are always evaluated as @value{GDBN} Command Files.
26715
26716@item set script-extension soft
26717The debugger determines the scripting language based on filename
26718extension. If this scripting language is supported, @value{GDBN}
26719evaluates the script using that language. Otherwise, it evaluates
26720the file as a @value{GDBN} Command File.
26721
26722@item set script-extension strict
26723The debugger determines the scripting language based on filename
26724extension, and evaluates the script using that language. If the
26725language is not supported, then the evaluation fails.
26726
26727@item show script-extension
26728Display the current value of the @code{script-extension} option.
26729
26730@end table
26731
ed2a2229
CB
26732@ifset SYSTEM_GDBINIT_DIR
26733This setting is not used for files in the system-wide gdbinit directory.
26734Files in that directory must have an extension matching their language,
26735or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26736commands. @xref{Startup}.
26737@end ifset
26738
8e04817f 26739@node Sequences
d57a3c85 26740@section Canned Sequences of Commands
104c1213 26741
8e04817f 26742Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26743Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26744commands for execution as a unit: user-defined commands and command
26745files.
104c1213 26746
8e04817f 26747@menu
fcc73fe3
EZ
26748* Define:: How to define your own commands
26749* Hooks:: Hooks for user-defined commands
26750* Command Files:: How to write scripts of commands to be stored in a file
26751* Output:: Commands for controlled output
71b8c845 26752* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26753@end menu
104c1213 26754
8e04817f 26755@node Define
d57a3c85 26756@subsection User-defined Commands
104c1213 26757
8e04817f 26758@cindex user-defined command
fcc73fe3 26759@cindex arguments, to user-defined commands
8e04817f
AC
26760A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26761which you assign a new name as a command. This is done with the
df3ee9ca 26762@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26763separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26764via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26765
8e04817f
AC
26766@smallexample
26767define adder
26768 print $arg0 + $arg1 + $arg2
c03c782f 26769end
8e04817f 26770@end smallexample
104c1213
JM
26771
26772@noindent
8e04817f 26773To execute the command use:
104c1213 26774
8e04817f
AC
26775@smallexample
26776adder 1 2 3
26777@end smallexample
104c1213 26778
8e04817f
AC
26779@noindent
26780This defines the command @code{adder}, which prints the sum of
26781its three arguments. Note the arguments are text substitutions, so they may
26782reference variables, use complex expressions, or even perform inferior
26783functions calls.
104c1213 26784
fcc73fe3
EZ
26785@cindex argument count in user-defined commands
26786@cindex how many arguments (user-defined commands)
c03c782f 26787In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26788been passed.
c03c782f
AS
26789
26790@smallexample
26791define adder
26792 if $argc == 2
26793 print $arg0 + $arg1
26794 end
26795 if $argc == 3
26796 print $arg0 + $arg1 + $arg2
26797 end
26798end
26799@end smallexample
26800
01770bbd
PA
26801Combining with the @code{eval} command (@pxref{eval}) makes it easier
26802to process a variable number of arguments:
26803
26804@smallexample
26805define adder
26806 set $i = 0
26807 set $sum = 0
26808 while $i < $argc
26809 eval "set $sum = $sum + $arg%d", $i
26810 set $i = $i + 1
26811 end
26812 print $sum
26813end
26814@end smallexample
26815
104c1213 26816@table @code
104c1213 26817
8e04817f
AC
26818@kindex define
26819@item define @var{commandname}
26820Define a command named @var{commandname}. If there is already a command
26821by that name, you are asked to confirm that you want to redefine it.
697aa1b7 26822The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
26823numbers, dashes, dots, and underscores. It may also start with any
26824predefined or user-defined prefix command.
26825For example, @samp{define target my-target} creates
adb483fe 26826a user-defined @samp{target my-target} command.
104c1213 26827
8e04817f
AC
26828The definition of the command is made up of other @value{GDBN} command lines,
26829which are given following the @code{define} command. The end of these
26830commands is marked by a line containing @code{end}.
104c1213 26831
8e04817f 26832@kindex document
ca91424e 26833@kindex end@r{ (user-defined commands)}
8e04817f
AC
26834@item document @var{commandname}
26835Document the user-defined command @var{commandname}, so that it can be
26836accessed by @code{help}. The command @var{commandname} must already be
26837defined. This command reads lines of documentation just as @code{define}
26838reads the lines of the command definition, ending with @code{end}.
26839After the @code{document} command is finished, @code{help} on command
26840@var{commandname} displays the documentation you have written.
104c1213 26841
8e04817f
AC
26842You may use the @code{document} command again to change the
26843documentation of a command. Redefining the command with @code{define}
26844does not change the documentation.
104c1213 26845
bf498525
PW
26846@kindex define-prefix
26847@item define-prefix @var{commandname}
26848Define or mark the command @var{commandname} as a user-defined prefix
26849command. Once marked, @var{commandname} can be used as prefix command
26850by the @code{define} command.
26851Note that @code{define-prefix} can be used with a not yet defined
26852@var{commandname}. In such a case, @var{commandname} is defined as
26853an empty user-defined command.
26854In case you redefine a command that was marked as a user-defined
26855prefix command, the subcommands of the redefined command are kept
26856(and @value{GDBN} indicates so to the user).
26857
26858Example:
26859@example
26860(gdb) define-prefix abc
26861(gdb) define-prefix abc def
26862(gdb) define abc def
26863Type commands for definition of "abc def".
26864End with a line saying just "end".
26865>echo command initial def\n
26866>end
26867(gdb) define abc def ghi
26868Type commands for definition of "abc def ghi".
26869End with a line saying just "end".
26870>echo command ghi\n
26871>end
26872(gdb) define abc def
26873Keeping subcommands of prefix command "def".
26874Redefine command "def"? (y or n) y
26875Type commands for definition of "abc def".
26876End with a line saying just "end".
26877>echo command def\n
26878>end
26879(gdb) abc def ghi
26880command ghi
26881(gdb) abc def
26882command def
26883(gdb)
26884@end example
26885
c45da7e6
EZ
26886@kindex dont-repeat
26887@cindex don't repeat command
26888@item dont-repeat
26889Used inside a user-defined command, this tells @value{GDBN} that this
26890command should not be repeated when the user hits @key{RET}
26891(@pxref{Command Syntax, repeat last command}).
26892
8e04817f
AC
26893@kindex help user-defined
26894@item help user-defined
7d74f244 26895List all user-defined commands and all python commands defined in class
6b92c0d3 26896COMMAND_USER. The first line of the documentation or docstring is
7d74f244 26897included (if any).
104c1213 26898
8e04817f
AC
26899@kindex show user
26900@item show user
26901@itemx show user @var{commandname}
26902Display the @value{GDBN} commands used to define @var{commandname} (but
26903not its documentation). If no @var{commandname} is given, display the
26904definitions for all user-defined commands.
7d74f244 26905This does not work for user-defined python commands.
104c1213 26906
fcc73fe3 26907@cindex infinite recursion in user-defined commands
20f01a46
DH
26908@kindex show max-user-call-depth
26909@kindex set max-user-call-depth
26910@item show max-user-call-depth
5ca0cb28
DH
26911@itemx set max-user-call-depth
26912The value of @code{max-user-call-depth} controls how many recursion
3f94c067 26913levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 26914infinite recursion and aborts the command.
7d74f244 26915This does not apply to user-defined python commands.
104c1213
JM
26916@end table
26917
fcc73fe3
EZ
26918In addition to the above commands, user-defined commands frequently
26919use control flow commands, described in @ref{Command Files}.
26920
8e04817f
AC
26921When user-defined commands are executed, the
26922commands of the definition are not printed. An error in any command
26923stops execution of the user-defined command.
104c1213 26924
8e04817f
AC
26925If used interactively, commands that would ask for confirmation proceed
26926without asking when used inside a user-defined command. Many @value{GDBN}
26927commands that normally print messages to say what they are doing omit the
26928messages when used in a user-defined command.
104c1213 26929
8e04817f 26930@node Hooks
d57a3c85 26931@subsection User-defined Command Hooks
8e04817f
AC
26932@cindex command hooks
26933@cindex hooks, for commands
26934@cindex hooks, pre-command
104c1213 26935
8e04817f 26936@kindex hook
8e04817f
AC
26937You may define @dfn{hooks}, which are a special kind of user-defined
26938command. Whenever you run the command @samp{foo}, if the user-defined
26939command @samp{hook-foo} exists, it is executed (with no arguments)
26940before that command.
104c1213 26941
8e04817f
AC
26942@cindex hooks, post-command
26943@kindex hookpost
8e04817f
AC
26944A hook may also be defined which is run after the command you executed.
26945Whenever you run the command @samp{foo}, if the user-defined command
26946@samp{hookpost-foo} exists, it is executed (with no arguments) after
26947that command. Post-execution hooks may exist simultaneously with
26948pre-execution hooks, for the same command.
104c1213 26949
8e04817f 26950It is valid for a hook to call the command which it hooks. If this
9f1c6395 26951occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 26952
8e04817f
AC
26953@c It would be nice if hookpost could be passed a parameter indicating
26954@c if the command it hooks executed properly or not. FIXME!
104c1213 26955
8e04817f
AC
26956@kindex stop@r{, a pseudo-command}
26957In addition, a pseudo-command, @samp{stop} exists. Defining
26958(@samp{hook-stop}) makes the associated commands execute every time
26959execution stops in your program: before breakpoint commands are run,
26960displays are printed, or the stack frame is printed.
104c1213 26961
8e04817f
AC
26962For example, to ignore @code{SIGALRM} signals while
26963single-stepping, but treat them normally during normal execution,
26964you could define:
104c1213 26965
474c8240 26966@smallexample
8e04817f
AC
26967define hook-stop
26968handle SIGALRM nopass
26969end
104c1213 26970
8e04817f
AC
26971define hook-run
26972handle SIGALRM pass
26973end
104c1213 26974
8e04817f 26975define hook-continue
d3e8051b 26976handle SIGALRM pass
8e04817f 26977end
474c8240 26978@end smallexample
104c1213 26979
d3e8051b 26980As a further example, to hook at the beginning and end of the @code{echo}
b383017d 26981command, and to add extra text to the beginning and end of the message,
8e04817f 26982you could define:
104c1213 26983
474c8240 26984@smallexample
8e04817f
AC
26985define hook-echo
26986echo <<<---
26987end
104c1213 26988
8e04817f
AC
26989define hookpost-echo
26990echo --->>>\n
26991end
104c1213 26992
8e04817f
AC
26993(@value{GDBP}) echo Hello World
26994<<<---Hello World--->>>
26995(@value{GDBP})
104c1213 26996
474c8240 26997@end smallexample
104c1213 26998
8e04817f
AC
26999You can define a hook for any single-word command in @value{GDBN}, but
27000not for command aliases; you should define a hook for the basic command
c1468174 27001name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
27002@c FIXME! So how does Joe User discover whether a command is an alias
27003@c or not?
adb483fe
DJ
27004You can hook a multi-word command by adding @code{hook-} or
27005@code{hookpost-} to the last word of the command, e.g.@:
27006@samp{define target hook-remote} to add a hook to @samp{target remote}.
27007
8e04817f
AC
27008If an error occurs during the execution of your hook, execution of
27009@value{GDBN} commands stops and @value{GDBN} issues a prompt
27010(before the command that you actually typed had a chance to run).
104c1213 27011
8e04817f
AC
27012If you try to define a hook which does not match any known command, you
27013get a warning from the @code{define} command.
c906108c 27014
8e04817f 27015@node Command Files
d57a3c85 27016@subsection Command Files
c906108c 27017
8e04817f 27018@cindex command files
fcc73fe3 27019@cindex scripting commands
6fc08d32
EZ
27020A command file for @value{GDBN} is a text file made of lines that are
27021@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27022also be included. An empty line in a command file does nothing; it
27023does not mean to repeat the last command, as it would from the
27024terminal.
c906108c 27025
6fc08d32 27026You can request the execution of a command file with the @code{source}
95433b34
JB
27027command. Note that the @code{source} command is also used to evaluate
27028scripts that are not Command Files. The exact behavior can be configured
27029using the @code{script-extension} setting.
27030@xref{Extending GDB,, Extending GDB}.
c906108c 27031
8e04817f
AC
27032@table @code
27033@kindex source
ca91424e 27034@cindex execute commands from a file
3f7b2faa 27035@item source [-s] [-v] @var{filename}
8e04817f 27036Execute the command file @var{filename}.
c906108c
SS
27037@end table
27038
fcc73fe3
EZ
27039The lines in a command file are generally executed sequentially,
27040unless the order of execution is changed by one of the
27041@emph{flow-control commands} described below. The commands are not
a71ec265
DH
27042printed as they are executed. An error in any command terminates
27043execution of the command file and control is returned to the console.
c906108c 27044
08001717
DE
27045@value{GDBN} first searches for @var{filename} in the current directory.
27046If the file is not found there, and @var{filename} does not specify a
27047directory, then @value{GDBN} also looks for the file on the source search path
27048(specified with the @samp{directory} command);
27049except that @file{$cdir} is not searched because the compilation directory
27050is not relevant to scripts.
4b505b12 27051
3f7b2faa
DE
27052If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27053on the search path even if @var{filename} specifies a directory.
27054The search is done by appending @var{filename} to each element of the
27055search path. So, for example, if @var{filename} is @file{mylib/myscript}
27056and the search path contains @file{/home/user} then @value{GDBN} will
27057look for the script @file{/home/user/mylib/myscript}.
27058The search is also done if @var{filename} is an absolute path.
27059For example, if @var{filename} is @file{/tmp/myscript} and
27060the search path contains @file{/home/user} then @value{GDBN} will
27061look for the script @file{/home/user/tmp/myscript}.
27062For DOS-like systems, if @var{filename} contains a drive specification,
27063it is stripped before concatenation. For example, if @var{filename} is
27064@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27065will look for the script @file{c:/tmp/myscript}.
27066
16026cd7
AS
27067If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27068each command as it is executed. The option must be given before
27069@var{filename}, and is interpreted as part of the filename anywhere else.
27070
8e04817f
AC
27071Commands that would ask for confirmation if used interactively proceed
27072without asking when used in a command file. Many @value{GDBN} commands that
27073normally print messages to say what they are doing omit the messages
27074when called from command files.
c906108c 27075
8e04817f
AC
27076@value{GDBN} also accepts command input from standard input. In this
27077mode, normal output goes to standard output and error output goes to
27078standard error. Errors in a command file supplied on standard input do
6fc08d32 27079not terminate execution of the command file---execution continues with
8e04817f 27080the next command.
c906108c 27081
474c8240 27082@smallexample
8e04817f 27083gdb < cmds > log 2>&1
474c8240 27084@end smallexample
c906108c 27085
8e04817f
AC
27086(The syntax above will vary depending on the shell used.) This example
27087will execute commands from the file @file{cmds}. All output and errors
27088would be directed to @file{log}.
c906108c 27089
fcc73fe3
EZ
27090Since commands stored on command files tend to be more general than
27091commands typed interactively, they frequently need to deal with
27092complicated situations, such as different or unexpected values of
27093variables and symbols, changes in how the program being debugged is
27094built, etc. @value{GDBN} provides a set of flow-control commands to
27095deal with these complexities. Using these commands, you can write
27096complex scripts that loop over data structures, execute commands
27097conditionally, etc.
27098
27099@table @code
27100@kindex if
27101@kindex else
27102@item if
27103@itemx else
27104This command allows to include in your script conditionally executed
27105commands. The @code{if} command takes a single argument, which is an
27106expression to evaluate. It is followed by a series of commands that
27107are executed only if the expression is true (its value is nonzero).
27108There can then optionally be an @code{else} line, followed by a series
27109of commands that are only executed if the expression was false. The
27110end of the list is marked by a line containing @code{end}.
27111
27112@kindex while
27113@item while
27114This command allows to write loops. Its syntax is similar to
27115@code{if}: the command takes a single argument, which is an expression
27116to evaluate, and must be followed by the commands to execute, one per
27117line, terminated by an @code{end}. These commands are called the
27118@dfn{body} of the loop. The commands in the body of @code{while} are
27119executed repeatedly as long as the expression evaluates to true.
27120
27121@kindex loop_break
27122@item loop_break
27123This command exits the @code{while} loop in whose body it is included.
27124Execution of the script continues after that @code{while}s @code{end}
27125line.
27126
27127@kindex loop_continue
27128@item loop_continue
27129This command skips the execution of the rest of the body of commands
27130in the @code{while} loop in whose body it is included. Execution
27131branches to the beginning of the @code{while} loop, where it evaluates
27132the controlling expression.
ca91424e
EZ
27133
27134@kindex end@r{ (if/else/while commands)}
27135@item end
27136Terminate the block of commands that are the body of @code{if},
27137@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
27138@end table
27139
27140
8e04817f 27141@node Output
d57a3c85 27142@subsection Commands for Controlled Output
c906108c 27143
8e04817f
AC
27144During the execution of a command file or a user-defined command, normal
27145@value{GDBN} output is suppressed; the only output that appears is what is
27146explicitly printed by the commands in the definition. This section
27147describes three commands useful for generating exactly the output you
27148want.
c906108c
SS
27149
27150@table @code
8e04817f
AC
27151@kindex echo
27152@item echo @var{text}
27153@c I do not consider backslash-space a standard C escape sequence
27154@c because it is not in ANSI.
27155Print @var{text}. Nonprinting characters can be included in
27156@var{text} using C escape sequences, such as @samp{\n} to print a
27157newline. @strong{No newline is printed unless you specify one.}
27158In addition to the standard C escape sequences, a backslash followed
27159by a space stands for a space. This is useful for displaying a
27160string with spaces at the beginning or the end, since leading and
27161trailing spaces are otherwise trimmed from all arguments.
27162To print @samp{@w{ }and foo =@w{ }}, use the command
27163@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 27164
8e04817f
AC
27165A backslash at the end of @var{text} can be used, as in C, to continue
27166the command onto subsequent lines. For example,
c906108c 27167
474c8240 27168@smallexample
8e04817f
AC
27169echo This is some text\n\
27170which is continued\n\
27171onto several lines.\n
474c8240 27172@end smallexample
c906108c 27173
8e04817f 27174produces the same output as
c906108c 27175
474c8240 27176@smallexample
8e04817f
AC
27177echo This is some text\n
27178echo which is continued\n
27179echo onto several lines.\n
474c8240 27180@end smallexample
c906108c 27181
8e04817f
AC
27182@kindex output
27183@item output @var{expression}
27184Print the value of @var{expression} and nothing but that value: no
27185newlines, no @samp{$@var{nn} = }. The value is not entered in the
27186value history either. @xref{Expressions, ,Expressions}, for more information
27187on expressions.
c906108c 27188
8e04817f
AC
27189@item output/@var{fmt} @var{expression}
27190Print the value of @var{expression} in format @var{fmt}. You can use
27191the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 27192Formats}, for more information.
c906108c 27193
8e04817f 27194@kindex printf
82160952
EZ
27195@item printf @var{template}, @var{expressions}@dots{}
27196Print the values of one or more @var{expressions} under the control of
27197the string @var{template}. To print several values, make
27198@var{expressions} be a comma-separated list of individual expressions,
27199which may be either numbers or pointers. Their values are printed as
27200specified by @var{template}, exactly as a C program would do by
27201executing the code below:
c906108c 27202
474c8240 27203@smallexample
82160952 27204printf (@var{template}, @var{expressions}@dots{});
474c8240 27205@end smallexample
c906108c 27206
82160952
EZ
27207As in @code{C} @code{printf}, ordinary characters in @var{template}
27208are printed verbatim, while @dfn{conversion specification} introduced
27209by the @samp{%} character cause subsequent @var{expressions} to be
27210evaluated, their values converted and formatted according to type and
27211style information encoded in the conversion specifications, and then
27212printed.
27213
8e04817f 27214For example, you can print two values in hex like this:
c906108c 27215
8e04817f
AC
27216@smallexample
27217printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27218@end smallexample
c906108c 27219
82160952
EZ
27220@code{printf} supports all the standard @code{C} conversion
27221specifications, including the flags and modifiers between the @samp{%}
27222character and the conversion letter, with the following exceptions:
27223
27224@itemize @bullet
27225@item
27226The argument-ordering modifiers, such as @samp{2$}, are not supported.
27227
27228@item
27229The modifier @samp{*} is not supported for specifying precision or
27230width.
27231
27232@item
27233The @samp{'} flag (for separation of digits into groups according to
27234@code{LC_NUMERIC'}) is not supported.
27235
27236@item
27237The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27238supported.
27239
27240@item
27241The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27242
27243@item
27244The conversion letters @samp{a} and @samp{A} are not supported.
27245@end itemize
27246
27247@noindent
27248Note that the @samp{ll} type modifier is supported only if the
27249underlying @code{C} implementation used to build @value{GDBN} supports
27250the @code{long long int} type, and the @samp{L} type modifier is
27251supported only if @code{long double} type is available.
27252
27253As in @code{C}, @code{printf} supports simple backslash-escape
27254sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27255@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27256single character. Octal and hexadecimal escape sequences are not
27257supported.
1a619819
LM
27258
27259Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27260(@dfn{Decimal Floating Point}) types using the following length modifiers
27261together with a floating point specifier.
1a619819
LM
27262letters:
27263
27264@itemize @bullet
27265@item
27266@samp{H} for printing @code{Decimal32} types.
27267
27268@item
27269@samp{D} for printing @code{Decimal64} types.
27270
27271@item
27272@samp{DD} for printing @code{Decimal128} types.
27273@end itemize
27274
27275If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27276support for the three length modifiers for DFP types, other modifiers
3b784c4f 27277such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27278
27279In case there is no such @code{C} support, no additional modifiers will be
27280available and the value will be printed in the standard way.
27281
27282Here's an example of printing DFP types using the above conversion letters:
27283@smallexample
0aea4bf3 27284printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27285@end smallexample
27286
01770bbd 27287@anchor{eval}
f1421989
HZ
27288@kindex eval
27289@item eval @var{template}, @var{expressions}@dots{}
27290Convert the values of one or more @var{expressions} under the control of
27291the string @var{template} to a command line, and call it.
27292
c906108c
SS
27293@end table
27294
71b8c845
DE
27295@node Auto-loading sequences
27296@subsection Controlling auto-loading native @value{GDBN} scripts
27297@cindex native script auto-loading
27298
27299When a new object file is read (for example, due to the @code{file}
27300command, or because the inferior has loaded a shared library),
27301@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27302@xref{Auto-loading extensions}.
27303
27304Auto-loading can be enabled or disabled,
27305and the list of auto-loaded scripts can be printed.
27306
27307@table @code
27308@anchor{set auto-load gdb-scripts}
27309@kindex set auto-load gdb-scripts
27310@item set auto-load gdb-scripts [on|off]
27311Enable or disable the auto-loading of canned sequences of commands scripts.
27312
27313@anchor{show auto-load gdb-scripts}
27314@kindex show auto-load gdb-scripts
27315@item show auto-load gdb-scripts
27316Show whether auto-loading of canned sequences of commands scripts is enabled or
27317disabled.
27318
27319@anchor{info auto-load gdb-scripts}
27320@kindex info auto-load gdb-scripts
27321@cindex print list of auto-loaded canned sequences of commands scripts
27322@item info auto-load gdb-scripts [@var{regexp}]
27323Print the list of all canned sequences of commands scripts that @value{GDBN}
27324auto-loaded.
27325@end table
27326
27327If @var{regexp} is supplied only canned sequences of commands scripts with
27328matching names are printed.
27329
329baa95
DE
27330@c Python docs live in a separate file.
27331@include python.texi
0e3509db 27332
ed3ef339
DE
27333@c Guile docs live in a separate file.
27334@include guile.texi
27335
71b8c845
DE
27336@node Auto-loading extensions
27337@section Auto-loading extensions
27338@cindex auto-loading extensions
27339
27340@value{GDBN} provides two mechanisms for automatically loading extensions
27341when a new object file is read (for example, due to the @code{file}
27342command, or because the inferior has loaded a shared library):
27343@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27344section of modern file formats like ELF.
27345
27346@menu
27347* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27348* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27349* Which flavor to choose?::
27350@end menu
27351
27352The auto-loading feature is useful for supplying application-specific
27353debugging commands and features.
27354
27355Auto-loading can be enabled or disabled,
27356and the list of auto-loaded scripts can be printed.
27357See the @samp{auto-loading} section of each extension language
27358for more information.
27359For @value{GDBN} command files see @ref{Auto-loading sequences}.
27360For Python files see @ref{Python Auto-loading}.
27361
27362Note that loading of this script file also requires accordingly configured
27363@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27364
27365@node objfile-gdbdotext file
27366@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27367@cindex @file{@var{objfile}-gdb.gdb}
27368@cindex @file{@var{objfile}-gdb.py}
27369@cindex @file{@var{objfile}-gdb.scm}
27370
27371When a new object file is read, @value{GDBN} looks for a file named
27372@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27373where @var{objfile} is the object file's name and
27374where @var{ext} is the file extension for the extension language:
27375
27376@table @code
27377@item @file{@var{objfile}-gdb.gdb}
27378GDB's own command language
27379@item @file{@var{objfile}-gdb.py}
27380Python
ed3ef339
DE
27381@item @file{@var{objfile}-gdb.scm}
27382Guile
71b8c845
DE
27383@end table
27384
27385@var{script-name} is formed by ensuring that the file name of @var{objfile}
27386is absolute, following all symlinks, and resolving @code{.} and @code{..}
27387components, and appending the @file{-gdb.@var{ext}} suffix.
27388If this file exists and is readable, @value{GDBN} will evaluate it as a
27389script in the specified extension language.
27390
27391If this file does not exist, then @value{GDBN} will look for
27392@var{script-name} file in all of the directories as specified below.
6e2469ff
HD
27393(On MS-Windows/MS-DOS, the drive letter of the executable's leading
27394directories is converted to a one-letter subdirectory, i.e.@:
27395@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27396filesystems disallow colons in file names.)
71b8c845
DE
27397
27398Note that loading of these files requires an accordingly configured
27399@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27400
27401For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27402scripts normally according to its @file{.exe} filename. But if no scripts are
27403found @value{GDBN} also tries script filenames matching the object file without
27404its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27405is attempted on any platform. This makes the script filenames compatible
27406between Unix and MS-Windows hosts.
27407
27408@table @code
27409@anchor{set auto-load scripts-directory}
27410@kindex set auto-load scripts-directory
27411@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27412Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27413may be delimited by the host platform path separator in use
27414(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27415
27416Each entry here needs to be covered also by the security setting
27417@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27418
27419@anchor{with-auto-load-dir}
27420This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27421@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27422configuration option @option{--with-auto-load-dir}.
27423
27424Any reference to @file{$debugdir} will get replaced by
27425@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27426reference to @file{$datadir} will get replaced by @var{data-directory} which is
27427determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27428@file{$datadir} must be placed as a directory component --- either alone or
27429delimited by @file{/} or @file{\} directory separators, depending on the host
27430platform.
27431
27432The list of directories uses path separator (@samp{:} on GNU and Unix
27433systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27434to the @env{PATH} environment variable.
27435
27436@anchor{show auto-load scripts-directory}
27437@kindex show auto-load scripts-directory
27438@item show auto-load scripts-directory
27439Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27440
27441@anchor{add-auto-load-scripts-directory}
27442@kindex add-auto-load-scripts-directory
27443@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27444Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27445Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27446@end table
27447
27448@value{GDBN} does not track which files it has already auto-loaded this way.
27449@value{GDBN} will load the associated script every time the corresponding
27450@var{objfile} is opened.
27451So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27452is evaluated more than once.
27453
27454@node dotdebug_gdb_scripts section
27455@subsection The @code{.debug_gdb_scripts} section
27456@cindex @code{.debug_gdb_scripts} section
27457
27458For systems using file formats like ELF and COFF,
27459when @value{GDBN} loads a new object file
27460it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27461If this section exists, its contents is a list of null-terminated entries
27462specifying scripts to load. Each entry begins with a non-null prefix byte that
27463specifies the kind of entry, typically the extension language and whether the
27464script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27465
9f050062
DE
27466The following entries are supported:
27467
27468@table @code
27469@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27470@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27471@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27472@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27473@end table
27474
27475@subsubsection Script File Entries
27476
27477If the entry specifies a file, @value{GDBN} will look for the file first
27478in the current directory and then along the source search path
71b8c845
DE
27479(@pxref{Source Path, ,Specifying Source Directories}),
27480except that @file{$cdir} is not searched, since the compilation
27481directory is not relevant to scripts.
27482
9f050062 27483File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27484for example, this GCC macro for Python scripts.
27485
27486@example
27487/* Note: The "MS" section flags are to remove duplicates. */
27488#define DEFINE_GDB_PY_SCRIPT(script_name) \
27489 asm("\
27490.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27491.byte 1 /* Python */\n\
27492.asciz \"" script_name "\"\n\
27493.popsection \n\
27494");
27495@end example
27496
27497@noindent
ed3ef339 27498For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27499Then one can reference the macro in a header or source file like this:
27500
27501@example
27502DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27503@end example
27504
27505The script name may include directories if desired.
27506
27507Note that loading of this script file also requires accordingly configured
27508@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27509
27510If the macro invocation is put in a header, any application or library
27511using this header will get a reference to the specified script,
27512and with the use of @code{"MS"} attributes on the section, the linker
27513will remove duplicates.
27514
9f050062
DE
27515@subsubsection Script Text Entries
27516
27517Script text entries allow to put the executable script in the entry
27518itself instead of loading it from a file.
27519The first line of the entry, everything after the prefix byte and up to
27520the first newline (@code{0xa}) character, is the script name, and must not
27521contain any kind of space character, e.g., spaces or tabs.
27522The rest of the entry, up to the trailing null byte, is the script to
27523execute in the specified language. The name needs to be unique among
27524all script names, as @value{GDBN} executes each script only once based
27525on its name.
27526
27527Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27528testsuite.
27529
27530@example
27531#include "symcat.h"
27532#include "gdb/section-scripts.h"
27533asm(
27534".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27535".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27536".ascii \"gdb.inlined-script\\n\"\n"
27537".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27538".ascii \" def __init__ (self):\\n\"\n"
27539".ascii \" super (test_cmd, self).__init__ ("
27540 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27541".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27542".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27543".ascii \"test_cmd ()\\n\"\n"
27544".byte 0\n"
27545".popsection\n"
27546);
27547@end example
27548
27549Loading of inlined scripts requires a properly configured
27550@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27551The path to specify in @code{auto-load safe-path} is the path of the file
27552containing the @code{.debug_gdb_scripts} section.
27553
71b8c845
DE
27554@node Which flavor to choose?
27555@subsection Which flavor to choose?
27556
27557Given the multiple ways of auto-loading extensions, it might not always
27558be clear which one to choose. This section provides some guidance.
27559
27560@noindent
27561Benefits of the @file{-gdb.@var{ext}} way:
27562
27563@itemize @bullet
27564@item
27565Can be used with file formats that don't support multiple sections.
27566
27567@item
27568Ease of finding scripts for public libraries.
27569
27570Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27571in the source search path.
27572For publicly installed libraries, e.g., @file{libstdc++}, there typically
27573isn't a source directory in which to find the script.
27574
27575@item
27576Doesn't require source code additions.
27577@end itemize
27578
27579@noindent
27580Benefits of the @code{.debug_gdb_scripts} way:
27581
27582@itemize @bullet
27583@item
27584Works with static linking.
27585
27586Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27587trigger their loading. When an application is statically linked the only
27588objfile available is the executable, and it is cumbersome to attach all the
27589scripts from all the input libraries to the executable's
27590@file{-gdb.@var{ext}} script.
27591
27592@item
27593Works with classes that are entirely inlined.
27594
27595Some classes can be entirely inlined, and thus there may not be an associated
27596shared library to attach a @file{-gdb.@var{ext}} script to.
27597
27598@item
27599Scripts needn't be copied out of the source tree.
27600
27601In some circumstances, apps can be built out of large collections of internal
27602libraries, and the build infrastructure necessary to install the
27603@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27604cumbersome. It may be easier to specify the scripts in the
27605@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27606top of the source tree to the source search path.
27607@end itemize
27608
ed3ef339
DE
27609@node Multiple Extension Languages
27610@section Multiple Extension Languages
27611
27612The Guile and Python extension languages do not share any state,
27613and generally do not interfere with each other.
27614There are some things to be aware of, however.
27615
27616@subsection Python comes first
27617
27618Python was @value{GDBN}'s first extension language, and to avoid breaking
27619existing behaviour Python comes first. This is generally solved by the
27620``first one wins'' principle. @value{GDBN} maintains a list of enabled
27621extension languages, and when it makes a call to an extension language,
27622(say to pretty-print a value), it tries each in turn until an extension
27623language indicates it has performed the request (e.g., has returned the
27624pretty-printed form of a value).
27625This extends to errors while performing such requests: If an error happens
27626while, for example, trying to pretty-print an object then the error is
27627reported and any following extension languages are not tried.
27628
5a56e9c5
DE
27629@node Aliases
27630@section Creating new spellings of existing commands
27631@cindex aliases for commands
27632
27633It is often useful to define alternate spellings of existing commands.
27634For example, if a new @value{GDBN} command defined in Python has
27635a long name to type, it is handy to have an abbreviated version of it
27636that involves less typing.
27637
27638@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27639of the @samp{step} command even though it is otherwise an ambiguous
27640abbreviation of other commands like @samp{set} and @samp{show}.
27641
27642Aliases are also used to provide shortened or more common versions
27643of multi-word commands. For example, @value{GDBN} provides the
27644@samp{tty} alias of the @samp{set inferior-tty} command.
27645
27646You can define a new alias with the @samp{alias} command.
27647
27648@table @code
27649
27650@kindex alias
5b860c93 27651@item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
5a56e9c5
DE
27652
27653@end table
27654
27655@var{ALIAS} specifies the name of the new alias.
27656Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27657underscores.
27658
27659@var{COMMAND} specifies the name of an existing command
27660that is being aliased.
27661
5b860c93
PW
27662@var{COMMAND} can also be the name of an existing alias. In this case,
27663@var{COMMAND} cannot be an alias that has default arguments.
27664
5a56e9c5 27665The @samp{-a} option specifies that the new alias is an abbreviation
5b4a1a8d 27666of the command. Abbreviations are not used in command completion.
5a56e9c5
DE
27667
27668The @samp{--} option specifies the end of options,
27669and is useful when @var{ALIAS} begins with a dash.
27670
5b860c93
PW
27671You can specify @var{default-args} for your alias.
27672These @var{default-args} will be automatically added before the alias
27673arguments typed explicitly on the command line.
27674
27675For example, the below defines an alias @code{btfullall} that shows all local
27676variables and all frame arguments:
27677@smallexample
27678(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27679@end smallexample
27680
27681For more information about @var{default-args}, see @ref{Command aliases default args,
27682,Automatically prepend default arguments to user-defined aliases}.
27683
5a56e9c5
DE
27684Here is a simple example showing how to make an abbreviation
27685of a command so that there is less to type.
27686Suppose you were tired of typing @samp{disas}, the current
27687shortest unambiguous abbreviation of the @samp{disassemble} command
27688and you wanted an even shorter version named @samp{di}.
27689The following will accomplish this.
27690
27691@smallexample
27692(gdb) alias -a di = disas
27693@end smallexample
27694
27695Note that aliases are different from user-defined commands.
27696With a user-defined command, you also need to write documentation
27697for it with the @samp{document} command.
27698An alias automatically picks up the documentation of the existing command.
27699
27700Here is an example where we make @samp{elms} an abbreviation of
27701@samp{elements} in the @samp{set print elements} command.
27702This is to show that you can make an abbreviation of any part
27703of a command.
27704
27705@smallexample
27706(gdb) alias -a set print elms = set print elements
27707(gdb) alias -a show print elms = show print elements
27708(gdb) set p elms 20
27709(gdb) show p elms
27710Limit on string chars or array elements to print is 200.
27711@end smallexample
27712
27713Note that if you are defining an alias of a @samp{set} command,
27714and you want to have an alias for the corresponding @samp{show}
27715command, then you need to define the latter separately.
27716
27717Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27718@var{ALIAS}, just as they are normally.
27719
27720@smallexample
27721(gdb) alias -a set pr elms = set p ele
27722@end smallexample
27723
27724Finally, here is an example showing the creation of a one word
27725alias for a more complex command.
27726This creates alias @samp{spe} of the command @samp{set print elements}.
27727
27728@smallexample
27729(gdb) alias spe = set print elements
27730(gdb) spe 20
27731@end smallexample
27732
21c294e6
AC
27733@node Interpreters
27734@chapter Command Interpreters
27735@cindex command interpreters
27736
27737@value{GDBN} supports multiple command interpreters, and some command
27738infrastructure to allow users or user interface writers to switch
27739between interpreters or run commands in other interpreters.
27740
27741@value{GDBN} currently supports two command interpreters, the console
27742interpreter (sometimes called the command-line interpreter or @sc{cli})
27743and the machine interface interpreter (or @sc{gdb/mi}). This manual
27744describes both of these interfaces in great detail.
27745
27746By default, @value{GDBN} will start with the console interpreter.
27747However, the user may choose to start @value{GDBN} with another
27748interpreter by specifying the @option{-i} or @option{--interpreter}
27749startup options. Defined interpreters include:
27750
27751@table @code
27752@item console
27753@cindex console interpreter
27754The traditional console or command-line interpreter. This is the most often
27755used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27756@value{GDBN} will use this interpreter.
27757
27758@item mi
27759@cindex mi interpreter
b4be1b06 27760The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
27761by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27762or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27763Interface}.
27764
b4be1b06
SM
27765@item mi3
27766@cindex mi3 interpreter
27767The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27768
21c294e6
AC
27769@item mi2
27770@cindex mi2 interpreter
b4be1b06 27771The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
27772
27773@item mi1
27774@cindex mi1 interpreter
b4be1b06 27775The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
27776
27777@end table
27778
27779@cindex invoke another interpreter
21c294e6
AC
27780
27781@kindex interpreter-exec
86f78169
PA
27782You may execute commands in any interpreter from the current
27783interpreter using the appropriate command. If you are running the
27784console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
27785
27786@smallexample
27787interpreter-exec mi "-data-list-register-names"
27788@end smallexample
27789
27790@sc{gdb/mi} has a similar command, although it is only available in versions of
27791@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27792
86f78169
PA
27793Note that @code{interpreter-exec} only changes the interpreter for the
27794duration of the specified command. It does not change the interpreter
27795permanently.
27796
27797@cindex start a new independent interpreter
27798
27799Although you may only choose a single interpreter at startup, it is
27800possible to run an independent interpreter on a specified input/output
27801device (usually a tty).
27802
27803For example, consider a debugger GUI or IDE that wants to provide a
27804@value{GDBN} console view. It may do so by embedding a terminal
27805emulator widget in its GUI, starting @value{GDBN} in the traditional
27806command-line mode with stdin/stdout/stderr redirected to that
27807terminal, and then creating an MI interpreter running on a specified
27808input/output device. The console interpreter created by @value{GDBN}
27809at startup handles commands the user types in the terminal widget,
27810while the GUI controls and synchronizes state with @value{GDBN} using
27811the separate MI interpreter.
27812
27813To start a new secondary @dfn{user interface} running MI, use the
27814@code{new-ui} command:
27815
27816@kindex new-ui
27817@cindex new user interface
27818@smallexample
27819new-ui @var{interpreter} @var{tty}
27820@end smallexample
27821
27822The @var{interpreter} parameter specifies the interpreter to run.
27823This accepts the same values as the @code{interpreter-exec} command.
27824For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27825@var{tty} parameter specifies the name of the bidirectional file the
27826interpreter uses for input/output, usually the name of a
27827pseudoterminal slave on Unix systems. For example:
27828
27829@smallexample
27830(@value{GDBP}) new-ui mi /dev/pts/9
27831@end smallexample
27832
27833@noindent
27834runs an MI interpreter on @file{/dev/pts/9}.
27835
8e04817f
AC
27836@node TUI
27837@chapter @value{GDBN} Text User Interface
27838@cindex TUI
d0d5df6f 27839@cindex Text User Interface
c906108c 27840
8e04817f
AC
27841@menu
27842* TUI Overview:: TUI overview
27843* TUI Keys:: TUI key bindings
7cf36c78 27844* TUI Single Key Mode:: TUI single key mode
db2e3e2e 27845* TUI Commands:: TUI-specific commands
8e04817f
AC
27846* TUI Configuration:: TUI configuration variables
27847@end menu
c906108c 27848
46ba6afa 27849The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
27850interface which uses the @code{curses} library to show the source
27851file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
27852commands in separate text windows. The TUI mode is supported only
27853on platforms where a suitable version of the @code{curses} library
27854is available.
d0d5df6f 27855
46ba6afa 27856The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 27857@samp{@value{GDBP} -tui}.
46ba6afa 27858You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 27859using various TUI commands and key bindings, such as @command{tui
bcd8537c 27860enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 27861@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 27862
8e04817f 27863@node TUI Overview
79a6e687 27864@section TUI Overview
c906108c 27865
46ba6afa 27866In TUI mode, @value{GDBN} can display several text windows:
c906108c 27867
8e04817f
AC
27868@table @emph
27869@item command
27870This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
27871prompt and the @value{GDBN} output. The @value{GDBN} input is still
27872managed using readline.
c906108c 27873
8e04817f
AC
27874@item source
27875The source window shows the source file of the program. The current
46ba6afa 27876line and active breakpoints are displayed in this window.
c906108c 27877
8e04817f
AC
27878@item assembly
27879The assembly window shows the disassembly output of the program.
c906108c 27880
8e04817f 27881@item register
46ba6afa
BW
27882This window shows the processor registers. Registers are highlighted
27883when their values change.
c906108c
SS
27884@end table
27885
269c21fe 27886The source and assembly windows show the current program position
46ba6afa
BW
27887by highlighting the current line and marking it with a @samp{>} marker.
27888Breakpoints are indicated with two markers. The first marker
269c21fe
SC
27889indicates the breakpoint type:
27890
27891@table @code
27892@item B
27893Breakpoint which was hit at least once.
27894
27895@item b
27896Breakpoint which was never hit.
27897
27898@item H
27899Hardware breakpoint which was hit at least once.
27900
27901@item h
27902Hardware breakpoint which was never hit.
269c21fe
SC
27903@end table
27904
27905The second marker indicates whether the breakpoint is enabled or not:
27906
27907@table @code
27908@item +
27909Breakpoint is enabled.
27910
27911@item -
27912Breakpoint is disabled.
269c21fe
SC
27913@end table
27914
46ba6afa
BW
27915The source, assembly and register windows are updated when the current
27916thread changes, when the frame changes, or when the program counter
27917changes.
27918
27919These windows are not all visible at the same time. The command
27920window is always visible. The others can be arranged in several
27921layouts:
c906108c 27922
8e04817f
AC
27923@itemize @bullet
27924@item
46ba6afa 27925source only,
2df3850c 27926
8e04817f 27927@item
46ba6afa 27928assembly only,
8e04817f
AC
27929
27930@item
46ba6afa 27931source and assembly,
8e04817f
AC
27932
27933@item
46ba6afa 27934source and registers, or
c906108c 27935
8e04817f 27936@item
46ba6afa 27937assembly and registers.
8e04817f 27938@end itemize
c906108c 27939
ee325b61
TT
27940These are the standard layouts, but other layouts can be defined.
27941
46ba6afa 27942A status line above the command window shows the following information:
b7bb15bc
SC
27943
27944@table @emph
27945@item target
46ba6afa 27946Indicates the current @value{GDBN} target.
b7bb15bc
SC
27947(@pxref{Targets, ,Specifying a Debugging Target}).
27948
27949@item process
46ba6afa 27950Gives the current process or thread number.
b7bb15bc
SC
27951When no process is being debugged, this field is set to @code{No process}.
27952
27953@item function
27954Gives the current function name for the selected frame.
27955The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 27956When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
27957the string @code{??} is displayed.
27958
27959@item line
27960Indicates the current line number for the selected frame.
46ba6afa 27961When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
27962
27963@item pc
27964Indicates the current program counter address.
b7bb15bc
SC
27965@end table
27966
8e04817f
AC
27967@node TUI Keys
27968@section TUI Key Bindings
27969@cindex TUI key bindings
c906108c 27970
8e04817f 27971The TUI installs several key bindings in the readline keymaps
39037522
TT
27972@ifset SYSTEM_READLINE
27973(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27974@end ifset
27975@ifclear SYSTEM_READLINE
27976(@pxref{Command Line Editing}).
27977@end ifclear
27978The following key bindings are installed for both TUI mode and the
27979@value{GDBN} standard mode.
c906108c 27980
8e04817f
AC
27981@table @kbd
27982@kindex C-x C-a
27983@item C-x C-a
27984@kindex C-x a
27985@itemx C-x a
27986@kindex C-x A
27987@itemx C-x A
46ba6afa
BW
27988Enter or leave the TUI mode. When leaving the TUI mode,
27989the curses window management stops and @value{GDBN} operates using
27990its standard mode, writing on the terminal directly. When reentering
27991the TUI mode, control is given back to the curses windows.
8e04817f 27992The screen is then refreshed.
c906108c 27993
c86d74cc
TT
27994This key binding uses the bindable Readline function
27995@code{tui-switch-mode}.
27996
8e04817f
AC
27997@kindex C-x 1
27998@item C-x 1
27999Use a TUI layout with only one window. The layout will
28000either be @samp{source} or @samp{assembly}. When the TUI mode
28001is not active, it will switch to the TUI mode.
2df3850c 28002
8e04817f 28003Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 28004
c86d74cc
TT
28005This key binding uses the bindable Readline function
28006@code{tui-delete-other-windows}.
28007
8e04817f
AC
28008@kindex C-x 2
28009@item C-x 2
28010Use a TUI layout with at least two windows. When the current
46ba6afa 28011layout already has two windows, the next layout with two windows is used.
8e04817f
AC
28012When a new layout is chosen, one window will always be common to the
28013previous layout and the new one.
c906108c 28014
8e04817f 28015Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 28016
c86d74cc
TT
28017This key binding uses the bindable Readline function
28018@code{tui-change-windows}.
28019
72ffddc9
SC
28020@kindex C-x o
28021@item C-x o
28022Change the active window. The TUI associates several key bindings
46ba6afa 28023(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
28024gives the focus to the next TUI window.
28025
28026Think of it as the Emacs @kbd{C-x o} binding.
28027
c86d74cc
TT
28028This key binding uses the bindable Readline function
28029@code{tui-other-window}.
28030
7cf36c78
SC
28031@kindex C-x s
28032@item C-x s
46ba6afa
BW
28033Switch in and out of the TUI SingleKey mode that binds single
28034keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
28035
28036This key binding uses the bindable Readline function
28037@code{next-keymap}.
c906108c
SS
28038@end table
28039
46ba6afa 28040The following key bindings only work in the TUI mode:
5d161b24 28041
46ba6afa 28042@table @asis
8e04817f 28043@kindex PgUp
46ba6afa 28044@item @key{PgUp}
8e04817f 28045Scroll the active window one page up.
c906108c 28046
8e04817f 28047@kindex PgDn
46ba6afa 28048@item @key{PgDn}
8e04817f 28049Scroll the active window one page down.
c906108c 28050
8e04817f 28051@kindex Up
46ba6afa 28052@item @key{Up}
8e04817f 28053Scroll the active window one line up.
c906108c 28054
8e04817f 28055@kindex Down
46ba6afa 28056@item @key{Down}
8e04817f 28057Scroll the active window one line down.
c906108c 28058
8e04817f 28059@kindex Left
46ba6afa 28060@item @key{Left}
8e04817f 28061Scroll the active window one column left.
c906108c 28062
8e04817f 28063@kindex Right
46ba6afa 28064@item @key{Right}
8e04817f 28065Scroll the active window one column right.
c906108c 28066
8e04817f 28067@kindex C-L
46ba6afa 28068@item @kbd{C-L}
8e04817f 28069Refresh the screen.
8e04817f 28070@end table
c906108c 28071
46ba6afa
BW
28072Because the arrow keys scroll the active window in the TUI mode, they
28073are not available for their normal use by readline unless the command
28074window has the focus. When another window is active, you must use
28075other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28076and @kbd{C-f} to control the command window.
8e04817f 28077
7cf36c78
SC
28078@node TUI Single Key Mode
28079@section TUI Single Key Mode
28080@cindex TUI single key mode
28081
46ba6afa
BW
28082The TUI also provides a @dfn{SingleKey} mode, which binds several
28083frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28084switch into this mode, where the following key bindings are used:
7cf36c78
SC
28085
28086@table @kbd
28087@kindex c @r{(SingleKey TUI key)}
28088@item c
28089continue
28090
28091@kindex d @r{(SingleKey TUI key)}
28092@item d
28093down
28094
28095@kindex f @r{(SingleKey TUI key)}
28096@item f
28097finish
28098
28099@kindex n @r{(SingleKey TUI key)}
28100@item n
28101next
28102
a5afdb16
RK
28103@kindex o @r{(SingleKey TUI key)}
28104@item o
28105nexti. The shortcut letter @samp{o} stands for ``step Over''.
28106
7cf36c78
SC
28107@kindex q @r{(SingleKey TUI key)}
28108@item q
46ba6afa 28109exit the SingleKey mode.
7cf36c78
SC
28110
28111@kindex r @r{(SingleKey TUI key)}
28112@item r
28113run
28114
28115@kindex s @r{(SingleKey TUI key)}
28116@item s
28117step
28118
a5afdb16
RK
28119@kindex i @r{(SingleKey TUI key)}
28120@item i
28121stepi. The shortcut letter @samp{i} stands for ``step Into''.
28122
7cf36c78
SC
28123@kindex u @r{(SingleKey TUI key)}
28124@item u
28125up
28126
28127@kindex v @r{(SingleKey TUI key)}
28128@item v
28129info locals
28130
28131@kindex w @r{(SingleKey TUI key)}
28132@item w
28133where
7cf36c78
SC
28134@end table
28135
28136Other keys temporarily switch to the @value{GDBN} command prompt.
28137The key that was pressed is inserted in the editing buffer so that
28138it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
28139with the TUI SingleKey mode. Once the command is entered the TUI
28140SingleKey mode is restored. The only way to permanently leave
7f9087cb 28141this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 28142
11061048
TT
28143@cindex SingleKey keymap name
28144If @value{GDBN} was built with Readline 8.0 or later, the TUI
28145SingleKey keymap will be named @samp{SingleKey}. This can be used in
28146@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 28147
8e04817f 28148@node TUI Commands
db2e3e2e 28149@section TUI-specific Commands
8e04817f
AC
28150@cindex TUI commands
28151
28152The TUI has specific commands to control the text windows.
46ba6afa
BW
28153These commands are always available, even when @value{GDBN} is not in
28154the TUI mode. When @value{GDBN} is in the standard mode, most
28155of these commands will automatically switch to the TUI mode.
c906108c 28156
ff12863f
PA
28157Note that if @value{GDBN}'s @code{stdout} is not connected to a
28158terminal, or @value{GDBN} has been started with the machine interface
28159interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28160these commands will fail with an error, because it would not be
28161possible or desirable to enable curses window management.
28162
c906108c 28163@table @code
a4ea0946
AB
28164@item tui enable
28165@kindex tui enable
28166Activate TUI mode. The last active TUI window layout will be used if
760f7560 28167TUI mode has previously been used in the current debugging session,
a4ea0946
AB
28168otherwise a default layout is used.
28169
28170@item tui disable
28171@kindex tui disable
28172Disable TUI mode, returning to the console interpreter.
28173
3d757584
SC
28174@item info win
28175@kindex info win
28176List and give the size of all displayed windows.
28177
ee325b61
TT
28178@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28179@kindex tui new-layout
28180Create a new TUI layout. The new layout will be named @var{name}, and
28181can be accessed using the @code{layout} command (see below).
28182
7c043ba6
TT
28183Each @var{window} parameter is either the name of a window to display,
28184or a window description. The windows will be displayed from top to
28185bottom in the order listed.
28186
28187The names of the windows are the same as the ones given to the
ee325b61 28188@code{focus} command (see below); additional, the @code{status}
7c043ba6
TT
28189window can be specified. Note that, because it is of fixed height,
28190the weight assigned to the status window is of no importance. It is
28191conventional to use @samp{0} here.
28192
28193A window description looks a bit like an invocation of @code{tui
28194new-layout}, and is of the form
28195@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28196
28197This specifies a sub-layout. If @code{-horizontal} is given, the
28198windows in this description will be arranged side-by-side, rather than
28199top-to-bottom.
ee325b61
TT
28200
28201Each @var{weight} is an integer. It is the weight of this window
28202relative to all the other windows in the layout. These numbers are
28203used to calculate how much of the screen is given to each window.
28204
28205For example:
28206
28207@example
28208(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28209@end example
28210
28211Here, the new layout is called @samp{example}. It shows the source
28212and register windows, followed by the status window, and then finally
28213the command window. The non-status windows all have the same weight,
28214so the terminal will be split into three roughly equal sections.
28215
7c043ba6
TT
28216Here is a more complex example, showing a horizontal layout:
28217
28218@example
28219(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28220@end example
28221
28222This will result in side-by-side source and assembly windows; with the
28223status and command window being beneath these, filling the entire
28224width of the terminal. Because they have weight 2, the source and
28225assembly windows will be twice the height of the command window.
28226
6008fc5f 28227@item layout @var{name}
4644b6e3 28228@kindex layout
ee325b61
TT
28229Changes which TUI windows are displayed. The @var{name} parameter
28230controls which layout is shown. It can be either one of the built-in
28231layout names, or the name of a layout defined by the user using
28232@code{tui new-layout}.
28233
28234The built-in layouts are as follows:
6008fc5f
AB
28235
28236@table @code
28237@item next
8e04817f 28238Display the next layout.
2df3850c 28239
6008fc5f 28240@item prev
8e04817f 28241Display the previous layout.
c906108c 28242
6008fc5f
AB
28243@item src
28244Display the source and command windows.
c906108c 28245
6008fc5f
AB
28246@item asm
28247Display the assembly and command windows.
c906108c 28248
6008fc5f
AB
28249@item split
28250Display the source, assembly, and command windows.
c906108c 28251
6008fc5f
AB
28252@item regs
28253When in @code{src} layout display the register, source, and command
28254windows. When in @code{asm} or @code{split} layout display the
28255register, assembler, and command windows.
28256@end table
8e04817f 28257
6008fc5f 28258@item focus @var{name}
8e04817f 28259@kindex focus
6008fc5f
AB
28260Changes which TUI window is currently active for scrolling. The
28261@var{name} parameter can be any of the following:
28262
28263@table @code
28264@item next
46ba6afa
BW
28265Make the next window active for scrolling.
28266
6008fc5f 28267@item prev
46ba6afa
BW
28268Make the previous window active for scrolling.
28269
6008fc5f 28270@item src
46ba6afa
BW
28271Make the source window active for scrolling.
28272
6008fc5f 28273@item asm
46ba6afa
BW
28274Make the assembly window active for scrolling.
28275
6008fc5f 28276@item regs
46ba6afa
BW
28277Make the register window active for scrolling.
28278
6008fc5f 28279@item cmd
46ba6afa 28280Make the command window active for scrolling.
6008fc5f 28281@end table
c906108c 28282
8e04817f
AC
28283@item refresh
28284@kindex refresh
7f9087cb 28285Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28286
51f0e40d 28287@item tui reg @var{group}
6a1b180d 28288@kindex tui reg
51f0e40d
AB
28289Changes the register group displayed in the tui register window to
28290@var{group}. If the register window is not currently displayed this
28291command will cause the register window to be displayed. The list of
28292register groups, as well as their order is target specific. The
28293following groups are available on most targets:
28294@table @code
28295@item next
28296Repeatedly selecting this group will cause the display to cycle
28297through all of the available register groups.
28298
28299@item prev
28300Repeatedly selecting this group will cause the display to cycle
28301through all of the available register groups in the reverse order to
28302@var{next}.
28303
28304@item general
28305Display the general registers.
28306@item float
28307Display the floating point registers.
28308@item system
28309Display the system registers.
28310@item vector
28311Display the vector registers.
28312@item all
28313Display all registers.
28314@end table
6a1b180d 28315
8e04817f
AC
28316@item update
28317@kindex update
28318Update the source window and the current execution point.
c906108c 28319
8e04817f
AC
28320@item winheight @var{name} +@var{count}
28321@itemx winheight @var{name} -@var{count}
28322@kindex winheight
28323Change the height of the window @var{name} by @var{count}
28324lines. Positive counts increase the height, while negative counts
bf555842
EZ
28325decrease it. The @var{name} parameter can be one of @code{src} (the
28326source window), @code{cmd} (the command window), @code{asm} (the
28327disassembly window), or @code{regs} (the register display window).
d6677607 28328@end table
2df3850c 28329
8e04817f 28330@node TUI Configuration
79a6e687 28331@section TUI Configuration Variables
8e04817f 28332@cindex TUI configuration variables
c906108c 28333
46ba6afa 28334Several configuration variables control the appearance of TUI windows.
c906108c 28335
8e04817f
AC
28336@table @code
28337@item set tui border-kind @var{kind}
28338@kindex set tui border-kind
28339Select the border appearance for the source, assembly and register windows.
28340The possible values are the following:
28341@table @code
28342@item space
28343Use a space character to draw the border.
c906108c 28344
8e04817f 28345@item ascii
46ba6afa 28346Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28347
8e04817f
AC
28348@item acs
28349Use the Alternate Character Set to draw the border. The border is
28350drawn using character line graphics if the terminal supports them.
8e04817f 28351@end table
c78b4128 28352
8e04817f
AC
28353@item set tui border-mode @var{mode}
28354@kindex set tui border-mode
46ba6afa
BW
28355@itemx set tui active-border-mode @var{mode}
28356@kindex set tui active-border-mode
28357Select the display attributes for the borders of the inactive windows
28358or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28359@table @code
28360@item normal
28361Use normal attributes to display the border.
c906108c 28362
8e04817f
AC
28363@item standout
28364Use standout mode.
c906108c 28365
8e04817f
AC
28366@item reverse
28367Use reverse video mode.
c906108c 28368
8e04817f
AC
28369@item half
28370Use half bright mode.
c906108c 28371
8e04817f
AC
28372@item half-standout
28373Use half bright and standout mode.
c906108c 28374
8e04817f
AC
28375@item bold
28376Use extra bright or bold mode.
c78b4128 28377
8e04817f
AC
28378@item bold-standout
28379Use extra bright or bold and standout mode.
8e04817f 28380@end table
7806cea7
TT
28381
28382@item set tui tab-width @var{nchars}
28383@kindex set tui tab-width
28384@kindex tabset
28385Set the width of tab stops to be @var{nchars} characters. This
28386setting affects the display of TAB characters in the source and
28387assembly windows.
d1da6b01
TT
28388
28389@item set tui compact-source @r{[}on@r{|}off@r{]}
28390@kindex set tui compact-source
28391Set whether the TUI source window is displayed in ``compact'' form.
28392The default display uses more space for line numbers and starts the
28393source text at the next tab stop; the compact display uses only as
28394much space as is needed for the line numbers in the current file, and
28395only a single space to separate the line numbers from the source.
7806cea7 28396@end table
c78b4128 28397
a2a7af0c
TT
28398Note that the colors of the TUI borders can be controlled using the
28399appropriate @code{set style} commands. @xref{Output Styling}.
28400
8e04817f
AC
28401@node Emacs
28402@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28403
8e04817f
AC
28404@cindex Emacs
28405@cindex @sc{gnu} Emacs
28406A special interface allows you to use @sc{gnu} Emacs to view (and
28407edit) the source files for the program you are debugging with
28408@value{GDBN}.
c906108c 28409
8e04817f
AC
28410To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28411executable file you want to debug as an argument. This command starts
28412@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28413created Emacs buffer.
28414@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28415
5e252a2e 28416Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28417things:
c906108c 28418
8e04817f
AC
28419@itemize @bullet
28420@item
5e252a2e
NR
28421All ``terminal'' input and output goes through an Emacs buffer, called
28422the GUD buffer.
c906108c 28423
8e04817f
AC
28424This applies both to @value{GDBN} commands and their output, and to the input
28425and output done by the program you are debugging.
bf0184be 28426
8e04817f
AC
28427This is useful because it means that you can copy the text of previous
28428commands and input them again; you can even use parts of the output
28429in this way.
bf0184be 28430
8e04817f
AC
28431All the facilities of Emacs' Shell mode are available for interacting
28432with your program. In particular, you can send signals the usual
28433way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28434stop.
bf0184be
ND
28435
28436@item
8e04817f 28437@value{GDBN} displays source code through Emacs.
bf0184be 28438
8e04817f
AC
28439Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28440source file for that frame and puts an arrow (@samp{=>}) at the
28441left margin of the current line. Emacs uses a separate buffer for
28442source display, and splits the screen to show both your @value{GDBN} session
28443and the source.
bf0184be 28444
8e04817f
AC
28445Explicit @value{GDBN} @code{list} or search commands still produce output as
28446usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28447@end itemize
28448
28449We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28450a graphical mode, enabled by default, which provides further buffers
28451that can control the execution and describe the state of your program.
28452@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28453
64fabec2
AC
28454If you specify an absolute file name when prompted for the @kbd{M-x
28455gdb} argument, then Emacs sets your current working directory to where
28456your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28457sets your current working directory to the directory associated
64fabec2
AC
28458with the previous buffer. In this case, @value{GDBN} may find your
28459program by searching your environment's @code{PATH} variable, but on
28460some operating systems it might not find the source. So, although the
28461@value{GDBN} input and output session proceeds normally, the auxiliary
28462buffer does not display the current source and line of execution.
28463
28464The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28465line of the GUD buffer and this serves as a default for the commands
28466that specify files for @value{GDBN} to operate on. @xref{Files,
28467,Commands to Specify Files}.
64fabec2
AC
28468
28469By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28470need to call @value{GDBN} by a different name (for example, if you
28471keep several configurations around, with different names) you can
28472customize the Emacs variable @code{gud-gdb-command-name} to run the
28473one you want.
8e04817f 28474
5e252a2e 28475In the GUD buffer, you can use these special Emacs commands in
8e04817f 28476addition to the standard Shell mode commands:
c906108c 28477
8e04817f
AC
28478@table @kbd
28479@item C-h m
5e252a2e 28480Describe the features of Emacs' GUD Mode.
c906108c 28481
64fabec2 28482@item C-c C-s
8e04817f
AC
28483Execute to another source line, like the @value{GDBN} @code{step} command; also
28484update the display window to show the current file and location.
c906108c 28485
64fabec2 28486@item C-c C-n
8e04817f
AC
28487Execute to next source line in this function, skipping all function
28488calls, like the @value{GDBN} @code{next} command. Then update the display window
28489to show the current file and location.
c906108c 28490
64fabec2 28491@item C-c C-i
8e04817f
AC
28492Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28493display window accordingly.
c906108c 28494
8e04817f
AC
28495@item C-c C-f
28496Execute until exit from the selected stack frame, like the @value{GDBN}
28497@code{finish} command.
c906108c 28498
64fabec2 28499@item C-c C-r
8e04817f
AC
28500Continue execution of your program, like the @value{GDBN} @code{continue}
28501command.
b433d00b 28502
64fabec2 28503@item C-c <
8e04817f
AC
28504Go up the number of frames indicated by the numeric argument
28505(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28506like the @value{GDBN} @code{up} command.
b433d00b 28507
64fabec2 28508@item C-c >
8e04817f
AC
28509Go down the number of frames indicated by the numeric argument, like the
28510@value{GDBN} @code{down} command.
8e04817f 28511@end table
c906108c 28512
7f9087cb 28513In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28514tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28515
5e252a2e
NR
28516In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28517separate frame which shows a backtrace when the GUD buffer is current.
28518Move point to any frame in the stack and type @key{RET} to make it
28519become the current frame and display the associated source in the
28520source buffer. Alternatively, click @kbd{Mouse-2} to make the
28521selected frame become the current one. In graphical mode, the
28522speedbar displays watch expressions.
64fabec2 28523
8e04817f
AC
28524If you accidentally delete the source-display buffer, an easy way to get
28525it back is to type the command @code{f} in the @value{GDBN} buffer, to
28526request a frame display; when you run under Emacs, this recreates
28527the source buffer if necessary to show you the context of the current
28528frame.
c906108c 28529
8e04817f
AC
28530The source files displayed in Emacs are in ordinary Emacs buffers
28531which are visiting the source files in the usual way. You can edit
28532the files with these buffers if you wish; but keep in mind that @value{GDBN}
28533communicates with Emacs in terms of line numbers. If you add or
28534delete lines from the text, the line numbers that @value{GDBN} knows cease
28535to correspond properly with the code.
b383017d 28536
5e252a2e
NR
28537A more detailed description of Emacs' interaction with @value{GDBN} is
28538given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28539Emacs Manual}).
c906108c 28540
922fbb7b
AC
28541@node GDB/MI
28542@chapter The @sc{gdb/mi} Interface
28543
28544@unnumberedsec Function and Purpose
28545
28546@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28547@sc{gdb/mi} is a line based machine oriented text interface to
28548@value{GDBN} and is activated by specifying using the
28549@option{--interpreter} command line option (@pxref{Mode Options}). It
28550is specifically intended to support the development of systems which
28551use the debugger as just one small component of a larger system.
922fbb7b
AC
28552
28553This chapter is a specification of the @sc{gdb/mi} interface. It is written
28554in the form of a reference manual.
28555
28556Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28557features described below are incomplete and subject to change
28558(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28559
28560@unnumberedsec Notation and Terminology
28561
28562@cindex notational conventions, for @sc{gdb/mi}
28563This chapter uses the following notation:
28564
28565@itemize @bullet
28566@item
28567@code{|} separates two alternatives.
28568
28569@item
28570@code{[ @var{something} ]} indicates that @var{something} is optional:
28571it may or may not be given.
28572
28573@item
28574@code{( @var{group} )*} means that @var{group} inside the parentheses
28575may repeat zero or more times.
28576
28577@item
28578@code{( @var{group} )+} means that @var{group} inside the parentheses
28579may repeat one or more times.
28580
28581@item
28582@code{"@var{string}"} means a literal @var{string}.
28583@end itemize
28584
28585@ignore
28586@heading Dependencies
28587@end ignore
28588
922fbb7b 28589@menu
c3b108f7 28590* GDB/MI General Design::
922fbb7b
AC
28591* GDB/MI Command Syntax::
28592* GDB/MI Compatibility with CLI::
af6eff6f 28593* GDB/MI Development and Front Ends::
922fbb7b 28594* GDB/MI Output Records::
ef21caaf 28595* GDB/MI Simple Examples::
922fbb7b 28596* GDB/MI Command Description Format::
ef21caaf 28597* GDB/MI Breakpoint Commands::
3fa7bf06 28598* GDB/MI Catchpoint Commands::
a2c02241
NR
28599* GDB/MI Program Context::
28600* GDB/MI Thread Commands::
5d77fe44 28601* GDB/MI Ada Tasking Commands::
a2c02241
NR
28602* GDB/MI Program Execution::
28603* GDB/MI Stack Manipulation::
28604* GDB/MI Variable Objects::
922fbb7b 28605* GDB/MI Data Manipulation::
a2c02241
NR
28606* GDB/MI Tracepoint Commands::
28607* GDB/MI Symbol Query::
351ff01a 28608* GDB/MI File Commands::
922fbb7b
AC
28609@ignore
28610* GDB/MI Kod Commands::
28611* GDB/MI Memory Overlay Commands::
28612* GDB/MI Signal Handling Commands::
28613@end ignore
922fbb7b 28614* GDB/MI Target Manipulation::
a6b151f1 28615* GDB/MI File Transfer Commands::
58d06528 28616* GDB/MI Ada Exceptions Commands::
d192b373 28617* GDB/MI Support Commands::
ef21caaf 28618* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28619@end menu
28620
c3b108f7
VP
28621@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28622@node GDB/MI General Design
28623@section @sc{gdb/mi} General Design
28624@cindex GDB/MI General Design
28625
28626Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28627parts---commands sent to @value{GDBN}, responses to those commands
28628and notifications. Each command results in exactly one response,
28629indicating either successful completion of the command, or an error.
28630For the commands that do not resume the target, the response contains the
28631requested information. For the commands that resume the target, the
28632response only indicates whether the target was successfully resumed.
28633Notifications is the mechanism for reporting changes in the state of the
28634target, or in @value{GDBN} state, that cannot conveniently be associated with
28635a command and reported as part of that command response.
28636
28637The important examples of notifications are:
28638@itemize @bullet
28639
28640@item
28641Exec notifications. These are used to report changes in
28642target state---when a target is resumed, or stopped. It would not
28643be feasible to include this information in response of resuming
28644commands, because one resume commands can result in multiple events in
28645different threads. Also, quite some time may pass before any event
28646happens in the target, while a frontend needs to know whether the resuming
28647command itself was successfully executed.
28648
28649@item
28650Console output, and status notifications. Console output
28651notifications are used to report output of CLI commands, as well as
28652diagnostics for other commands. Status notifications are used to
28653report the progress of a long-running operation. Naturally, including
28654this information in command response would mean no output is produced
28655until the command is finished, which is undesirable.
28656
28657@item
28658General notifications. Commands may have various side effects on
28659the @value{GDBN} or target state beyond their official purpose. For example,
28660a command may change the selected thread. Although such changes can
28661be included in command response, using notification allows for more
28662orthogonal frontend design.
28663
28664@end itemize
28665
28666There's no guarantee that whenever an MI command reports an error,
28667@value{GDBN} or the target are in any specific state, and especially,
28668the state is not reverted to the state before the MI command was
28669processed. Therefore, whenever an MI command results in an error,
28670we recommend that the frontend refreshes all the information shown in
28671the user interface.
28672
508094de
NR
28673
28674@menu
28675* Context management::
28676* Asynchronous and non-stop modes::
28677* Thread groups::
28678@end menu
28679
28680@node Context management
c3b108f7
VP
28681@subsection Context management
28682
403cb6b1
JB
28683@subsubsection Threads and Frames
28684
c3b108f7
VP
28685In most cases when @value{GDBN} accesses the target, this access is
28686done in context of a specific thread and frame (@pxref{Frames}).
28687Often, even when accessing global data, the target requires that a thread
28688be specified. The CLI interface maintains the selected thread and frame,
28689and supplies them to target on each command. This is convenient,
28690because a command line user would not want to specify that information
28691explicitly on each command, and because user interacts with
28692@value{GDBN} via a single terminal, so no confusion is possible as
28693to what thread and frame are the current ones.
28694
28695In the case of MI, the concept of selected thread and frame is less
28696useful. First, a frontend can easily remember this information
28697itself. Second, a graphical frontend can have more than one window,
28698each one used for debugging a different thread, and the frontend might
28699want to access additional threads for internal purposes. This
28700increases the risk that by relying on implicitly selected thread, the
28701frontend may be operating on a wrong one. Therefore, each MI command
28702should explicitly specify which thread and frame to operate on. To
28703make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28704@samp{--frame} options, the value to each is @value{GDBN} global
28705identifier for thread and frame to operate on.
c3b108f7
VP
28706
28707Usually, each top-level window in a frontend allows the user to select
28708a thread and a frame, and remembers the user selection for further
28709operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28710current thread or frame be changed. For example, when stopping on a
28711breakpoint it is reasonable to switch to the thread where breakpoint is
28712hit. For another example, if the user issues the CLI @samp{thread} or
28713@samp{frame} commands via the frontend, it is desirable to change the
28714frontend's selection to the one specified by user. @value{GDBN}
28715communicates the suggestion to change current thread and frame using the
28716@samp{=thread-selected} notification.
c3b108f7
VP
28717
28718Note that historically, MI shares the selected thread with CLI, so
28719frontends used the @code{-thread-select} to execute commands in the
28720right context. However, getting this to work right is cumbersome. The
28721simplest way is for frontend to emit @code{-thread-select} command
28722before every command. This doubles the number of commands that need
28723to be sent. The alternative approach is to suppress @code{-thread-select}
28724if the selected thread in @value{GDBN} is supposed to be identical to the
28725thread the frontend wants to operate on. However, getting this
28726optimization right can be tricky. In particular, if the frontend
28727sends several commands to @value{GDBN}, and one of the commands changes the
28728selected thread, then the behaviour of subsequent commands will
28729change. So, a frontend should either wait for response from such
28730problematic commands, or explicitly add @code{-thread-select} for
28731all subsequent commands. No frontend is known to do this exactly
28732right, so it is suggested to just always pass the @samp{--thread} and
28733@samp{--frame} options.
28734
403cb6b1
JB
28735@subsubsection Language
28736
28737The execution of several commands depends on which language is selected.
28738By default, the current language (@pxref{show language}) is used.
28739But for commands known to be language-sensitive, it is recommended
28740to use the @samp{--language} option. This option takes one argument,
28741which is the name of the language to use while executing the command.
28742For instance:
28743
28744@smallexample
28745-data-evaluate-expression --language c "sizeof (void*)"
28746^done,value="4"
28747(gdb)
28748@end smallexample
28749
28750The valid language names are the same names accepted by the
28751@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28752@samp{local} or @samp{unknown}.
28753
508094de 28754@node Asynchronous and non-stop modes
c3b108f7
VP
28755@subsection Asynchronous command execution and non-stop mode
28756
28757On some targets, @value{GDBN} is capable of processing MI commands
28758even while the target is running. This is called @dfn{asynchronous
28759command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 28760specify a preference for asynchronous execution using the
329ea579 28761@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
28762either running the executable or attaching to the target. After the
28763frontend has started the executable or attached to the target, it can
28764find if asynchronous execution is enabled using the
28765@code{-list-target-features} command.
28766
329ea579
PA
28767@table @code
28768@item -gdb-set mi-async on
28769@item -gdb-set mi-async off
28770Set whether MI is in asynchronous mode.
28771
28772When @code{off}, which is the default, MI execution commands (e.g.,
28773@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28774for the program to stop before processing further commands.
28775
28776When @code{on}, MI execution commands are background execution
28777commands (e.g., @code{-exec-continue} becomes the equivalent of the
28778@code{c&} CLI command), and so @value{GDBN} is capable of processing
28779MI commands even while the target is running.
28780
28781@item -gdb-show mi-async
28782Show whether MI asynchronous mode is enabled.
28783@end table
28784
28785Note: In @value{GDBN} version 7.7 and earlier, this option was called
28786@code{target-async} instead of @code{mi-async}, and it had the effect
28787of both putting MI in asynchronous mode and making CLI background
28788commands possible. CLI background commands are now always possible
28789``out of the box'' if the target supports them. The old spelling is
28790kept as a deprecated alias for backwards compatibility.
28791
c3b108f7
VP
28792Even if @value{GDBN} can accept a command while target is running,
28793many commands that access the target do not work when the target is
28794running. Therefore, asynchronous command execution is most useful
28795when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28796it is possible to examine the state of one thread, while other threads
28797are running.
28798
28799When a given thread is running, MI commands that try to access the
28800target in the context of that thread may not work, or may work only on
28801some targets. In particular, commands that try to operate on thread's
28802stack will not work, on any target. Commands that read memory, or
28803modify breakpoints, may work or not work, depending on the target. Note
28804that even commands that operate on global state, such as @code{print},
28805@code{set}, and breakpoint commands, still access the target in the
28806context of a specific thread, so frontend should try to find a
28807stopped thread and perform the operation on that thread (using the
28808@samp{--thread} option).
28809
28810Which commands will work in the context of a running thread is
28811highly target dependent. However, the two commands
28812@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28813to find the state of a thread, will always work.
28814
508094de 28815@node Thread groups
c3b108f7
VP
28816@subsection Thread groups
28817@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 28818On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
28819hardware systems, each one having several cores with several different
28820processes running on each core. This section describes the MI
28821mechanism to support such debugging scenarios.
28822
28823The key observation is that regardless of the structure of the
28824target, MI can have a global list of threads, because most commands that
28825accept the @samp{--thread} option do not need to know what process that
28826thread belongs to. Therefore, it is not necessary to introduce
28827neither additional @samp{--process} option, nor an notion of the
28828current process in the MI interface. The only strictly new feature
28829that is required is the ability to find how the threads are grouped
28830into processes.
28831
28832To allow the user to discover such grouping, and to support arbitrary
28833hierarchy of machines/cores/processes, MI introduces the concept of a
28834@dfn{thread group}. Thread group is a collection of threads and other
28835thread groups. A thread group always has a string identifier, a type,
28836and may have additional attributes specific to the type. A new
28837command, @code{-list-thread-groups}, returns the list of top-level
28838thread groups, which correspond to processes that @value{GDBN} is
28839debugging at the moment. By passing an identifier of a thread group
28840to the @code{-list-thread-groups} command, it is possible to obtain
28841the members of specific thread group.
28842
28843To allow the user to easily discover processes, and other objects, he
28844wishes to debug, a concept of @dfn{available thread group} is
28845introduced. Available thread group is an thread group that
28846@value{GDBN} is not debugging, but that can be attached to, using the
28847@code{-target-attach} command. The list of available top-level thread
28848groups can be obtained using @samp{-list-thread-groups --available}.
28849In general, the content of a thread group may be only retrieved only
28850after attaching to that thread group.
28851
65c574f6 28852Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
28853Programs}). Each inferior corresponds to a thread group of a special
28854type @samp{process}, and some additional operations are permitted on
28855such thread groups.
28856
922fbb7b
AC
28857@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28858@node GDB/MI Command Syntax
28859@section @sc{gdb/mi} Command Syntax
28860
28861@menu
28862* GDB/MI Input Syntax::
28863* GDB/MI Output Syntax::
922fbb7b
AC
28864@end menu
28865
28866@node GDB/MI Input Syntax
28867@subsection @sc{gdb/mi} Input Syntax
28868
28869@cindex input syntax for @sc{gdb/mi}
28870@cindex @sc{gdb/mi}, input syntax
28871@table @code
28872@item @var{command} @expansion{}
28873@code{@var{cli-command} | @var{mi-command}}
28874
28875@item @var{cli-command} @expansion{}
28876@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28877@var{cli-command} is any existing @value{GDBN} CLI command.
28878
28879@item @var{mi-command} @expansion{}
28880@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28881@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28882
28883@item @var{token} @expansion{}
28884"any sequence of digits"
28885
28886@item @var{option} @expansion{}
28887@code{"-" @var{parameter} [ " " @var{parameter} ]}
28888
28889@item @var{parameter} @expansion{}
28890@code{@var{non-blank-sequence} | @var{c-string}}
28891
28892@item @var{operation} @expansion{}
28893@emph{any of the operations described in this chapter}
28894
28895@item @var{non-blank-sequence} @expansion{}
28896@emph{anything, provided it doesn't contain special characters such as
28897"-", @var{nl}, """ and of course " "}
28898
28899@item @var{c-string} @expansion{}
28900@code{""" @var{seven-bit-iso-c-string-content} """}
28901
28902@item @var{nl} @expansion{}
28903@code{CR | CR-LF}
28904@end table
28905
28906@noindent
28907Notes:
28908
28909@itemize @bullet
28910@item
28911The CLI commands are still handled by the @sc{mi} interpreter; their
28912output is described below.
28913
28914@item
28915The @code{@var{token}}, when present, is passed back when the command
28916finishes.
28917
28918@item
28919Some @sc{mi} commands accept optional arguments as part of the parameter
28920list. Each option is identified by a leading @samp{-} (dash) and may be
28921followed by an optional argument parameter. Options occur first in the
28922parameter list and can be delimited from normal parameters using
28923@samp{--} (this is useful when some parameters begin with a dash).
28924@end itemize
28925
28926Pragmatics:
28927
28928@itemize @bullet
28929@item
28930We want easy access to the existing CLI syntax (for debugging).
28931
28932@item
28933We want it to be easy to spot a @sc{mi} operation.
28934@end itemize
28935
28936@node GDB/MI Output Syntax
28937@subsection @sc{gdb/mi} Output Syntax
28938
28939@cindex output syntax of @sc{gdb/mi}
28940@cindex @sc{gdb/mi}, output syntax
28941The output from @sc{gdb/mi} consists of zero or more out-of-band records
28942followed, optionally, by a single result record. This result record
28943is for the most recent command. The sequence of output records is
594fe323 28944terminated by @samp{(gdb)}.
922fbb7b
AC
28945
28946If an input command was prefixed with a @code{@var{token}} then the
28947corresponding output for that command will also be prefixed by that same
28948@var{token}.
28949
28950@table @code
28951@item @var{output} @expansion{}
594fe323 28952@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
28953
28954@item @var{result-record} @expansion{}
28955@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28956
28957@item @var{out-of-band-record} @expansion{}
28958@code{@var{async-record} | @var{stream-record}}
28959
28960@item @var{async-record} @expansion{}
28961@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28962
28963@item @var{exec-async-output} @expansion{}
dcf106f3 28964@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
28965
28966@item @var{status-async-output} @expansion{}
dcf106f3 28967@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
28968
28969@item @var{notify-async-output} @expansion{}
dcf106f3 28970@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
28971
28972@item @var{async-output} @expansion{}
dcf106f3 28973@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
28974
28975@item @var{result-class} @expansion{}
28976@code{"done" | "running" | "connected" | "error" | "exit"}
28977
28978@item @var{async-class} @expansion{}
28979@code{"stopped" | @var{others}} (where @var{others} will be added
28980depending on the needs---this is still in development).
28981
28982@item @var{result} @expansion{}
28983@code{ @var{variable} "=" @var{value}}
28984
28985@item @var{variable} @expansion{}
28986@code{ @var{string} }
28987
28988@item @var{value} @expansion{}
28989@code{ @var{const} | @var{tuple} | @var{list} }
28990
28991@item @var{const} @expansion{}
28992@code{@var{c-string}}
28993
28994@item @var{tuple} @expansion{}
28995@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28996
28997@item @var{list} @expansion{}
28998@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28999@var{result} ( "," @var{result} )* "]" }
29000
29001@item @var{stream-record} @expansion{}
29002@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29003
29004@item @var{console-stream-output} @expansion{}
dcf106f3 29005@code{"~" @var{c-string nl}}
922fbb7b
AC
29006
29007@item @var{target-stream-output} @expansion{}
dcf106f3 29008@code{"@@" @var{c-string nl}}
922fbb7b
AC
29009
29010@item @var{log-stream-output} @expansion{}
dcf106f3 29011@code{"&" @var{c-string nl}}
922fbb7b
AC
29012
29013@item @var{nl} @expansion{}
29014@code{CR | CR-LF}
29015
29016@item @var{token} @expansion{}
29017@emph{any sequence of digits}.
29018@end table
29019
29020@noindent
29021Notes:
29022
29023@itemize @bullet
29024@item
29025All output sequences end in a single line containing a period.
29026
29027@item
721c02de
VP
29028The @code{@var{token}} is from the corresponding request. Note that
29029for all async output, while the token is allowed by the grammar and
29030may be output by future versions of @value{GDBN} for select async
29031output messages, it is generally omitted. Frontends should treat
29032all async output as reporting general changes in the state of the
29033target and there should be no need to associate async output to any
29034prior command.
922fbb7b
AC
29035
29036@item
29037@cindex status output in @sc{gdb/mi}
29038@var{status-async-output} contains on-going status information about the
29039progress of a slow operation. It can be discarded. All status output is
29040prefixed by @samp{+}.
29041
29042@item
29043@cindex async output in @sc{gdb/mi}
29044@var{exec-async-output} contains asynchronous state change on the target
29045(stopped, started, disappeared). All async output is prefixed by
29046@samp{*}.
29047
29048@item
29049@cindex notify output in @sc{gdb/mi}
29050@var{notify-async-output} contains supplementary information that the
29051client should handle (e.g., a new breakpoint information). All notify
29052output is prefixed by @samp{=}.
29053
29054@item
29055@cindex console output in @sc{gdb/mi}
29056@var{console-stream-output} is output that should be displayed as is in the
29057console. It is the textual response to a CLI command. All the console
29058output is prefixed by @samp{~}.
29059
29060@item
29061@cindex target output in @sc{gdb/mi}
29062@var{target-stream-output} is the output produced by the target program.
29063All the target output is prefixed by @samp{@@}.
29064
29065@item
29066@cindex log output in @sc{gdb/mi}
29067@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29068instance messages that should be displayed as part of an error log. All
29069the log output is prefixed by @samp{&}.
29070
29071@item
29072@cindex list output in @sc{gdb/mi}
29073New @sc{gdb/mi} commands should only output @var{lists} containing
29074@var{values}.
29075
29076
29077@end itemize
29078
29079@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29080details about the various output records.
29081
922fbb7b
AC
29082@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29083@node GDB/MI Compatibility with CLI
29084@section @sc{gdb/mi} Compatibility with CLI
29085
29086@cindex compatibility, @sc{gdb/mi} and CLI
29087@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 29088
a2c02241
NR
29089For the developers convenience CLI commands can be entered directly,
29090but there may be some unexpected behaviour. For example, commands
29091that query the user will behave as if the user replied yes, breakpoint
29092command lists are not executed and some CLI commands, such as
29093@code{if}, @code{when} and @code{define}, prompt for further input with
29094@samp{>}, which is not valid MI output.
ef21caaf
NR
29095
29096This feature may be removed at some stage in the future and it is
a2c02241
NR
29097recommended that front ends use the @code{-interpreter-exec} command
29098(@pxref{-interpreter-exec}).
922fbb7b 29099
af6eff6f
NR
29100@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29101@node GDB/MI Development and Front Ends
29102@section @sc{gdb/mi} Development and Front Ends
29103@cindex @sc{gdb/mi} development
29104
29105The application which takes the MI output and presents the state of the
29106program being debugged to the user is called a @dfn{front end}.
29107
1fea0d53
SM
29108Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29109to the MI interface may break existing usage. This section describes how the
29110protocol changes and how to request previous version of the protocol when it
29111does.
af6eff6f
NR
29112
29113Some changes in MI need not break a carefully designed front end, and
29114for these the MI version will remain unchanged. The following is a
29115list of changes that may occur within one level, so front ends should
29116parse MI output in a way that can handle them:
29117
29118@itemize @bullet
29119@item
29120New MI commands may be added.
29121
29122@item
29123New fields may be added to the output of any MI command.
29124
36ece8b3
NR
29125@item
29126The range of values for fields with specified values, e.g.,
9f708cb2 29127@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 29128
af6eff6f
NR
29129@c The format of field's content e.g type prefix, may change so parse it
29130@c at your own risk. Yes, in general?
29131
29132@c The order of fields may change? Shouldn't really matter but it might
29133@c resolve inconsistencies.
29134@end itemize
29135
29136If the changes are likely to break front ends, the MI version level
1fea0d53
SM
29137will be increased by one. The new versions of the MI protocol are not compatible
29138with the old versions. Old versions of MI remain available, allowing front ends
29139to keep using them until they are modified to use the latest MI version.
af6eff6f 29140
1fea0d53
SM
29141Since @code{--interpreter=mi} always points to the latest MI version, it is
29142recommended that front ends request a specific version of MI when launching
29143@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29144interpreter with the MI version they expect.
29145
09f2921c 29146The following table gives a summary of the released versions of the MI
1fea0d53
SM
29147interface: the version number, the version of GDB in which it first appeared
29148and the breaking changes compared to the previous version.
29149
29150@multitable @columnfractions .05 .05 .9
29151@headitem MI version @tab GDB version @tab Breaking changes
29152
29153@item
29154@center 1
29155@tab
29156@center 5.1
29157@tab
29158None
29159
29160@item
29161@center 2
29162@tab
29163@center 6.0
29164@tab
29165
29166@itemize
29167@item
29168The @code{-environment-pwd}, @code{-environment-directory} and
29169@code{-environment-path} commands now returns values using the MI output
29170syntax, rather than CLI output syntax.
29171
29172@item
29173@code{-var-list-children}'s @code{children} result field is now a list, rather
29174than a tuple.
29175
29176@item
29177@code{-var-update}'s @code{changelist} result field is now a list, rather than
29178a tuple.
29179@end itemize
29180
b4be1b06
SM
29181@item
29182@center 3
29183@tab
29184@center 9.1
29185@tab
29186
29187@itemize
29188@item
29189The output of information about multi-location breakpoints has changed in the
29190responses to the @code{-break-insert} and @code{-break-info} commands, as well
29191as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29192The multiple locations are now placed in a @code{locations} field, whose value
29193is a list.
29194@end itemize
29195
1fea0d53 29196@end multitable
af6eff6f 29197
b4be1b06
SM
29198If your front end cannot yet migrate to a more recent version of the
29199MI protocol, you can nevertheless selectively enable specific features
29200available in those recent MI versions, using the following commands:
29201
29202@table @code
29203
29204@item -fix-multi-location-breakpoint-output
29205Use the output for multi-location breakpoints which was introduced by
29206MI 3, even when using MI versions 2 or 1. This command has no
29207effect when using MI version 3 or later.
29208
5c85e20d 29209@end table
b4be1b06 29210
af6eff6f
NR
29211The best way to avoid unexpected changes in MI that might break your front
29212end is to make your project known to @value{GDBN} developers and
7a9a6b69 29213follow development on @email{gdb@@sourceware.org} and
fa0f268d 29214@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
29215@cindex mailing lists
29216
922fbb7b
AC
29217@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29218@node GDB/MI Output Records
29219@section @sc{gdb/mi} Output Records
29220
29221@menu
29222* GDB/MI Result Records::
29223* GDB/MI Stream Records::
82f68b1c 29224* GDB/MI Async Records::
54516a0b 29225* GDB/MI Breakpoint Information::
c3b108f7 29226* GDB/MI Frame Information::
dc146f7c 29227* GDB/MI Thread Information::
4368ebeb 29228* GDB/MI Ada Exception Information::
922fbb7b
AC
29229@end menu
29230
29231@node GDB/MI Result Records
29232@subsection @sc{gdb/mi} Result Records
29233
29234@cindex result records in @sc{gdb/mi}
29235@cindex @sc{gdb/mi}, result records
29236In addition to a number of out-of-band notifications, the response to a
29237@sc{gdb/mi} command includes one of the following result indications:
29238
29239@table @code
29240@findex ^done
29241@item "^done" [ "," @var{results} ]
29242The synchronous operation was successful, @code{@var{results}} are the return
29243values.
29244
29245@item "^running"
29246@findex ^running
8e9c5e02
VP
29247This result record is equivalent to @samp{^done}. Historically, it
29248was output instead of @samp{^done} if the command has resumed the
29249target. This behaviour is maintained for backward compatibility, but
29250all frontends should treat @samp{^done} and @samp{^running}
29251identically and rely on the @samp{*running} output record to determine
29252which threads are resumed.
922fbb7b 29253
ef21caaf
NR
29254@item "^connected"
29255@findex ^connected
3f94c067 29256@value{GDBN} has connected to a remote target.
ef21caaf 29257
2ea126fa 29258@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 29259@findex ^error
2ea126fa
JB
29260The operation failed. The @code{msg=@var{c-string}} variable contains
29261the corresponding error message.
29262
29263If present, the @code{code=@var{c-string}} variable provides an error
29264code on which consumers can rely on to detect the corresponding
29265error condition. At present, only one error code is defined:
29266
29267@table @samp
29268@item "undefined-command"
29269Indicates that the command causing the error does not exist.
29270@end table
ef21caaf
NR
29271
29272@item "^exit"
29273@findex ^exit
3f94c067 29274@value{GDBN} has terminated.
ef21caaf 29275
922fbb7b
AC
29276@end table
29277
29278@node GDB/MI Stream Records
29279@subsection @sc{gdb/mi} Stream Records
29280
29281@cindex @sc{gdb/mi}, stream records
29282@cindex stream records in @sc{gdb/mi}
29283@value{GDBN} internally maintains a number of output streams: the console, the
29284target, and the log. The output intended for each of these streams is
29285funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29286
29287Each stream record begins with a unique @dfn{prefix character} which
29288identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29289Syntax}). In addition to the prefix, each stream record contains a
29290@code{@var{string-output}}. This is either raw text (with an implicit new
29291line) or a quoted C string (which does not contain an implicit newline).
29292
29293@table @code
29294@item "~" @var{string-output}
29295The console output stream contains text that should be displayed in the
29296CLI console window. It contains the textual responses to CLI commands.
29297
29298@item "@@" @var{string-output}
29299The target output stream contains any textual output from the running
ef21caaf
NR
29300target. This is only present when GDB's event loop is truly
29301asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29302
29303@item "&" @var{string-output}
29304The log stream contains debugging messages being produced by @value{GDBN}'s
29305internals.
29306@end table
29307
82f68b1c
VP
29308@node GDB/MI Async Records
29309@subsection @sc{gdb/mi} Async Records
922fbb7b 29310
82f68b1c
VP
29311@cindex async records in @sc{gdb/mi}
29312@cindex @sc{gdb/mi}, async records
29313@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29314additional changes that have occurred. Those changes can either be a
82f68b1c 29315consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29316target activity (e.g., target stopped).
29317
8eb41542 29318The following is the list of possible async records:
922fbb7b
AC
29319
29320@table @code
034dad6f 29321
e1ac3328 29322@item *running,thread-id="@var{thread}"
5d5658a1 29323The target is now running. The @var{thread} field can be the global
09f2921c 29324thread ID of the thread that is now running, and it can be
5d5658a1
PA
29325@samp{all} if all threads are running. The frontend should assume
29326that no interaction with a running thread is possible after this
29327notification is produced. The frontend should not assume that this
29328notification is output only once for any command. @value{GDBN} may
29329emit this notification several times, either for different threads,
29330because it cannot resume all threads together, or even for a single
29331thread, if the thread must be stepped though some code before letting
29332it run freely.
e1ac3328 29333
dc146f7c 29334@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29335The target has stopped. The @var{reason} field can have one of the
29336following values:
034dad6f
BR
29337
29338@table @code
29339@item breakpoint-hit
29340A breakpoint was reached.
29341@item watchpoint-trigger
29342A watchpoint was triggered.
29343@item read-watchpoint-trigger
29344A read watchpoint was triggered.
29345@item access-watchpoint-trigger
29346An access watchpoint was triggered.
29347@item function-finished
29348An -exec-finish or similar CLI command was accomplished.
29349@item location-reached
29350An -exec-until or similar CLI command was accomplished.
29351@item watchpoint-scope
29352A watchpoint has gone out of scope.
29353@item end-stepping-range
29354An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29355similar CLI command was accomplished.
29356@item exited-signalled
29357The inferior exited because of a signal.
29358@item exited
29359The inferior exited.
29360@item exited-normally
29361The inferior exited normally.
29362@item signal-received
29363A signal was received by the inferior.
36dfb11c
TT
29364@item solib-event
29365The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29366This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29367set or when a @code{catch load} or @code{catch unload} catchpoint is
29368in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29369@item fork
29370The inferior has forked. This is reported when @code{catch fork}
29371(@pxref{Set Catchpoints}) has been used.
29372@item vfork
29373The inferior has vforked. This is reported in when @code{catch vfork}
29374(@pxref{Set Catchpoints}) has been used.
29375@item syscall-entry
29376The inferior entered a system call. This is reported when @code{catch
29377syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29378@item syscall-return
36dfb11c
TT
29379The inferior returned from a system call. This is reported when
29380@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29381@item exec
29382The inferior called @code{exec}. This is reported when @code{catch exec}
29383(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29384@end table
29385
5d5658a1
PA
29386The @var{id} field identifies the global thread ID of the thread
29387that directly caused the stop -- for example by hitting a breakpoint.
29388Depending on whether all-stop
c3b108f7
VP
29389mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29390stop all threads, or only the thread that directly triggered the stop.
29391If all threads are stopped, the @var{stopped} field will have the
29392value of @code{"all"}. Otherwise, the value of the @var{stopped}
29393field will be a list of thread identifiers. Presently, this list will
29394always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29395several threads in the list. The @var{core} field reports the
29396processor core on which the stop event has happened. This field may be absent
29397if such information is not available.
c3b108f7 29398
a79b8f6e
VP
29399@item =thread-group-added,id="@var{id}"
29400@itemx =thread-group-removed,id="@var{id}"
29401A thread group was either added or removed. The @var{id} field
29402contains the @value{GDBN} identifier of the thread group. When a thread
29403group is added, it generally might not be associated with a running
29404process. When a thread group is removed, its id becomes invalid and
29405cannot be used in any way.
29406
29407@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29408A thread group became associated with a running program,
29409either because the program was just started or the thread group
29410was attached to a program. The @var{id} field contains the
29411@value{GDBN} identifier of the thread group. The @var{pid} field
29412contains process identifier, specific to the operating system.
29413
8cf64490 29414@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29415A thread group is no longer associated with a running program,
29416either because the program has exited, or because it was detached
c3b108f7 29417from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29418thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29419only when the inferior exited with some code.
c3b108f7
VP
29420
29421@item =thread-created,id="@var{id}",group-id="@var{gid}"
29422@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29423A thread either was created, or has exited. The @var{id} field
5d5658a1 29424contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29425field identifies the thread group this thread belongs to.
66bb093b 29426
4034d0ff
AT
29427@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29428Informs that the selected thread or frame were changed. This notification
29429is not emitted as result of the @code{-thread-select} or
29430@code{-stack-select-frame} commands, but is emitted whenever an MI command
29431that is not documented to change the selected thread and frame actually
29432changes them. In particular, invoking, directly or indirectly
29433(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29434will generate this notification. Changing the thread or frame from another
29435user interface (see @ref{Interpreters}) will also generate this notification.
29436
29437The @var{frame} field is only present if the newly selected thread is
29438stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29439
29440We suggest that in response to this notification, front ends
29441highlight the selected thread and cause subsequent commands to apply to
29442that thread.
29443
c86cf029
VP
29444@item =library-loaded,...
29445Reports that a new library file was loaded by the program. This
51457a05
MAL
29446notification has 5 fields---@var{id}, @var{target-name},
29447@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29448opaque identifier of the library. For remote debugging case,
29449@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29450library file on the target, and on the host respectively. For native
29451debugging, both those fields have the same value. The
f1cbe1d3
TT
29452@var{symbols-loaded} field is emitted only for backward compatibility
29453and should not be relied on to convey any useful information. The
29454@var{thread-group} field, if present, specifies the id of the thread
29455group in whose context the library was loaded. If the field is
29456absent, it means the library was loaded in the context of all present
51457a05
MAL
29457thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29458to this library.
c86cf029
VP
29459
29460@item =library-unloaded,...
134eb42c 29461Reports that a library was unloaded by the program. This notification
c86cf029 29462has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29463the same meaning as for the @code{=library-loaded} notification.
29464The @var{thread-group} field, if present, specifies the id of the
29465thread group in whose context the library was unloaded. If the field is
29466absent, it means the library was unloaded in the context of all present
29467thread groups.
c86cf029 29468
201b4506
YQ
29469@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29470@itemx =traceframe-changed,end
29471Reports that the trace frame was changed and its new number is
29472@var{tfnum}. The number of the tracepoint associated with this trace
29473frame is @var{tpnum}.
29474
134a2066 29475@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29476Reports that the new trace state variable @var{name} is created with
134a2066 29477initial value @var{initial}.
bb25a15c
YQ
29478
29479@item =tsv-deleted,name=@var{name}
29480@itemx =tsv-deleted
29481Reports that the trace state variable @var{name} is deleted or all
29482trace state variables are deleted.
29483
134a2066
YQ
29484@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29485Reports that the trace state variable @var{name} is modified with
29486the initial value @var{initial}. The current value @var{current} of
29487trace state variable is optional and is reported if the current
29488value of trace state variable is known.
29489
8d3788bd
VP
29490@item =breakpoint-created,bkpt=@{...@}
29491@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29492@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29493Reports that a breakpoint was created, modified, or deleted,
29494respectively. Only user-visible breakpoints are reported to the MI
29495user.
29496
29497The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29498breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29499@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29500
29501Note that if a breakpoint is emitted in the result record of a
29502command, then it will not also be emitted in an async record.
29503
38b022b4 29504@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29505@itemx =record-stopped,thread-group="@var{id}"
29506Execution log recording was either started or stopped on an
29507inferior. The @var{id} is the @value{GDBN} identifier of the thread
29508group corresponding to the affected inferior.
29509
38b022b4
SM
29510The @var{method} field indicates the method used to record execution. If the
29511method in use supports multiple recording formats, @var{format} will be present
8504e097 29512and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29513for existing method and format values.
29514
5b9afe8a
YQ
29515@item =cmd-param-changed,param=@var{param},value=@var{value}
29516Reports that a parameter of the command @code{set @var{param}} is
29517changed to @var{value}. In the multi-word @code{set} command,
29518the @var{param} is the whole parameter list to @code{set} command.
29519For example, In command @code{set check type on}, @var{param}
29520is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29521
29522@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29523Reports that bytes from @var{addr} to @var{data} + @var{len} were
29524written in an inferior. The @var{id} is the identifier of the
29525thread group corresponding to the affected inferior. The optional
29526@code{type="code"} part is reported if the memory written to holds
29527executable code.
82f68b1c
VP
29528@end table
29529
54516a0b
TT
29530@node GDB/MI Breakpoint Information
29531@subsection @sc{gdb/mi} Breakpoint Information
29532
29533When @value{GDBN} reports information about a breakpoint, a
29534tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29535following fields:
29536
29537@table @code
29538@item number
b4be1b06 29539The breakpoint number.
54516a0b
TT
29540
29541@item type
29542The type of the breakpoint. For ordinary breakpoints this will be
29543@samp{breakpoint}, but many values are possible.
29544
8ac3646f
TT
29545@item catch-type
29546If the type of the breakpoint is @samp{catchpoint}, then this
29547indicates the exact type of catchpoint.
29548
54516a0b
TT
29549@item disp
29550This is the breakpoint disposition---either @samp{del}, meaning that
29551the breakpoint will be deleted at the next stop, or @samp{keep},
29552meaning that the breakpoint will not be deleted.
29553
29554@item enabled
29555This indicates whether the breakpoint is enabled, in which case the
29556value is @samp{y}, or disabled, in which case the value is @samp{n}.
29557Note that this is not the same as the field @code{enable}.
29558
29559@item addr
29560The address of the breakpoint. This may be a hexidecimal number,
29561giving the address; or the string @samp{<PENDING>}, for a pending
29562breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29563multiple locations. This field will not be present if no address can
29564be determined. For example, a watchpoint does not have an address.
29565
aa7ca1bb
AH
29566@item addr_flags
29567Optional field containing any flags related to the address. These flags are
29568architecture-dependent; see @ref{Architectures} for their meaning for a
29569particular CPU.
29570
54516a0b
TT
29571@item func
29572If known, the function in which the breakpoint appears.
29573If not known, this field is not present.
29574
29575@item filename
29576The name of the source file which contains this function, if known.
29577If not known, this field is not present.
29578
29579@item fullname
29580The full file name of the source file which contains this function, if
29581known. If not known, this field is not present.
29582
29583@item line
29584The line number at which this breakpoint appears, if known.
29585If not known, this field is not present.
29586
29587@item at
29588If the source file is not known, this field may be provided. If
29589provided, this holds the address of the breakpoint, possibly followed
29590by a symbol name.
29591
29592@item pending
29593If this breakpoint is pending, this field is present and holds the
29594text used to set the breakpoint, as entered by the user.
29595
29596@item evaluated-by
29597Where this breakpoint's condition is evaluated, either @samp{host} or
29598@samp{target}.
29599
29600@item thread
29601If this is a thread-specific breakpoint, then this identifies the
29602thread in which the breakpoint can trigger.
29603
29604@item task
29605If this breakpoint is restricted to a particular Ada task, then this
29606field will hold the task identifier.
29607
29608@item cond
29609If the breakpoint is conditional, this is the condition expression.
29610
29611@item ignore
29612The ignore count of the breakpoint.
29613
29614@item enable
29615The enable count of the breakpoint.
29616
29617@item traceframe-usage
29618FIXME.
29619
29620@item static-tracepoint-marker-string-id
29621For a static tracepoint, the name of the static tracepoint marker.
29622
29623@item mask
29624For a masked watchpoint, this is the mask.
29625
29626@item pass
29627A tracepoint's pass count.
29628
29629@item original-location
29630The location of the breakpoint as originally specified by the user.
29631This field is optional.
29632
29633@item times
29634The number of times the breakpoint has been hit.
29635
29636@item installed
29637This field is only given for tracepoints. This is either @samp{y},
29638meaning that the tracepoint is installed, or @samp{n}, meaning that it
29639is not.
29640
29641@item what
29642Some extra data, the exact contents of which are type-dependent.
29643
b4be1b06
SM
29644@item locations
29645This field is present if the breakpoint has multiple locations. It is also
29646exceptionally present if the breakpoint is enabled and has a single, disabled
29647location.
29648
6b92c0d3 29649The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29650
29651@end table
29652
29653A location in a multi-location breakpoint is represented as a tuple with the
29654following fields:
29655
29656@table @code
29657
29658@item number
29659The location number as a dotted pair, like @samp{1.2}. The first digit is the
29660number of the parent breakpoint. The second digit is the number of the
29661location within that breakpoint.
29662
29663@item enabled
29664This indicates whether the location is enabled, in which case the
29665value is @samp{y}, or disabled, in which case the value is @samp{n}.
29666Note that this is not the same as the field @code{enable}.
29667
29668@item addr
29669The address of this location as an hexidecimal number.
29670
aa7ca1bb
AH
29671@item addr_flags
29672Optional field containing any flags related to the address. These flags are
29673architecture-dependent; see @ref{Architectures} for their meaning for a
29674particular CPU.
29675
b4be1b06
SM
29676@item func
29677If known, the function in which the location appears.
29678If not known, this field is not present.
29679
29680@item file
29681The name of the source file which contains this location, if known.
29682If not known, this field is not present.
29683
29684@item fullname
29685The full file name of the source file which contains this location, if
29686known. If not known, this field is not present.
29687
29688@item line
29689The line number at which this location appears, if known.
29690If not known, this field is not present.
29691
29692@item thread-groups
29693The thread groups this location is in.
29694
54516a0b
TT
29695@end table
29696
29697For example, here is what the output of @code{-break-insert}
29698(@pxref{GDB/MI Breakpoint Commands}) might be:
29699
29700@smallexample
29701-> -break-insert main
29702<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29703 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29704 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29705 times="0"@}
54516a0b
TT
29706<- (gdb)
29707@end smallexample
29708
c3b108f7
VP
29709@node GDB/MI Frame Information
29710@subsection @sc{gdb/mi} Frame Information
29711
29712Response from many MI commands includes an information about stack
29713frame. This information is a tuple that may have the following
29714fields:
29715
29716@table @code
29717@item level
29718The level of the stack frame. The innermost frame has the level of
29719zero. This field is always present.
29720
29721@item func
29722The name of the function corresponding to the frame. This field may
29723be absent if @value{GDBN} is unable to determine the function name.
29724
29725@item addr
29726The code address for the frame. This field is always present.
29727
aa7ca1bb
AH
29728@item addr_flags
29729Optional field containing any flags related to the address. These flags are
29730architecture-dependent; see @ref{Architectures} for their meaning for a
29731particular CPU.
29732
c3b108f7
VP
29733@item file
29734The name of the source files that correspond to the frame's code
29735address. This field may be absent.
29736
29737@item line
29738The source line corresponding to the frames' code address. This field
29739may be absent.
29740
29741@item from
29742The name of the binary file (either executable or shared library) the
29743corresponds to the frame's code address. This field may be absent.
29744
29745@end table
82f68b1c 29746
dc146f7c
VP
29747@node GDB/MI Thread Information
29748@subsection @sc{gdb/mi} Thread Information
29749
29750Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
29751uses a tuple with the following fields. The fields are always present unless
29752stated otherwise.
dc146f7c
VP
29753
29754@table @code
29755@item id
ebe553db 29756The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
29757
29758@item target-id
ebe553db 29759The target-specific string identifying the thread.
dc146f7c
VP
29760
29761@item details
29762Additional information about the thread provided by the target.
29763It is supposed to be human-readable and not interpreted by the
29764frontend. This field is optional.
29765
ebe553db
SM
29766@item name
29767The name of the thread. If the user specified a name using the
29768@code{thread name} command, then this name is given. Otherwise, if
29769@value{GDBN} can extract the thread name from the target, then that
29770name is given. If @value{GDBN} cannot find the thread name, then this
29771field is omitted.
29772
dc146f7c 29773@item state
ebe553db
SM
29774The execution state of the thread, either @samp{stopped} or @samp{running},
29775depending on whether the thread is presently running.
29776
29777@item frame
29778The stack frame currently executing in the thread. This field is only present
29779if the thread is stopped. Its format is documented in
29780@ref{GDB/MI Frame Information}.
dc146f7c
VP
29781
29782@item core
29783The value of this field is an integer number of the processor core the
29784thread was last seen on. This field is optional.
29785@end table
29786
956a9fb9
JB
29787@node GDB/MI Ada Exception Information
29788@subsection @sc{gdb/mi} Ada Exception Information
29789
29790Whenever a @code{*stopped} record is emitted because the program
29791stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29792@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
29793the @code{exception-name} field. Also, for exceptions that were raised
29794with an exception message, @value{GDBN} provides that message via
29795the @code{exception-message} field.
922fbb7b 29796
ef21caaf
NR
29797@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29798@node GDB/MI Simple Examples
29799@section Simple Examples of @sc{gdb/mi} Interaction
29800@cindex @sc{gdb/mi}, simple examples
29801
29802This subsection presents several simple examples of interaction using
29803the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29804following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29805the output received from @sc{gdb/mi}.
29806
d3e8051b 29807Note the line breaks shown in the examples are here only for
ef21caaf
NR
29808readability, they don't appear in the real output.
29809
79a6e687 29810@subheading Setting a Breakpoint
ef21caaf
NR
29811
29812Setting a breakpoint generates synchronous output which contains detailed
29813information of the breakpoint.
29814
29815@smallexample
29816-> -break-insert main
29817<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29818 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29819 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29820 times="0"@}
ef21caaf
NR
29821<- (gdb)
29822@end smallexample
29823
29824@subheading Program Execution
29825
29826Program execution generates asynchronous records and MI gives the
29827reason that execution stopped.
29828
29829@smallexample
29830-> -exec-run
29831<- ^running
29832<- (gdb)
a47ec5fe 29833<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
29834 frame=@{addr="0x08048564",func="main",
29835 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
29836 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29837 arch="i386:x86_64"@}
ef21caaf
NR
29838<- (gdb)
29839-> -exec-continue
29840<- ^running
29841<- (gdb)
29842<- *stopped,reason="exited-normally"
29843<- (gdb)
29844@end smallexample
29845
3f94c067 29846@subheading Quitting @value{GDBN}
ef21caaf 29847
3f94c067 29848Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
29849
29850@smallexample
29851-> (gdb)
29852<- -gdb-exit
29853<- ^exit
29854@end smallexample
29855
a6b29f87
VP
29856Please note that @samp{^exit} is printed immediately, but it might
29857take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29858performs necessary cleanups, including killing programs being debugged
29859or disconnecting from debug hardware, so the frontend should wait till
29860@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29861fails to exit in reasonable time.
29862
a2c02241 29863@subheading A Bad Command
ef21caaf
NR
29864
29865Here's what happens if you pass a non-existent command:
29866
29867@smallexample
29868-> -rubbish
29869<- ^error,msg="Undefined MI command: rubbish"
594fe323 29870<- (gdb)
ef21caaf
NR
29871@end smallexample
29872
29873
922fbb7b
AC
29874@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29875@node GDB/MI Command Description Format
29876@section @sc{gdb/mi} Command Description Format
29877
29878The remaining sections describe blocks of commands. Each block of
29879commands is laid out in a fashion similar to this section.
29880
922fbb7b
AC
29881@subheading Motivation
29882
29883The motivation for this collection of commands.
29884
29885@subheading Introduction
29886
29887A brief introduction to this collection of commands as a whole.
29888
29889@subheading Commands
29890
29891For each command in the block, the following is described:
29892
29893@subsubheading Synopsis
29894
29895@smallexample
29896 -command @var{args}@dots{}
29897@end smallexample
29898
922fbb7b
AC
29899@subsubheading Result
29900
265eeb58 29901@subsubheading @value{GDBN} Command
922fbb7b 29902
265eeb58 29903The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
29904
29905@subsubheading Example
29906
ef21caaf
NR
29907Example(s) formatted for readability. Some of the described commands have
29908not been implemented yet and these are labeled N.A.@: (not available).
29909
29910
922fbb7b 29911@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
29912@node GDB/MI Breakpoint Commands
29913@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
29914
29915@cindex breakpoint commands for @sc{gdb/mi}
29916@cindex @sc{gdb/mi}, breakpoint commands
29917This section documents @sc{gdb/mi} commands for manipulating
29918breakpoints.
29919
29920@subheading The @code{-break-after} Command
29921@findex -break-after
29922
29923@subsubheading Synopsis
29924
29925@smallexample
29926 -break-after @var{number} @var{count}
29927@end smallexample
29928
29929The breakpoint number @var{number} is not in effect until it has been
29930hit @var{count} times. To see how this is reflected in the output of
29931the @samp{-break-list} command, see the description of the
29932@samp{-break-list} command below.
29933
29934@subsubheading @value{GDBN} Command
29935
29936The corresponding @value{GDBN} command is @samp{ignore}.
29937
29938@subsubheading Example
29939
29940@smallexample
594fe323 29941(gdb)
922fbb7b 29942-break-insert main
a47ec5fe
AR
29943^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29944enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29945fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29946times="0"@}
594fe323 29947(gdb)
922fbb7b
AC
29948-break-after 1 3
29949~
29950^done
594fe323 29951(gdb)
922fbb7b
AC
29952-break-list
29953^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29954hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29955@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29956@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29957@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29958@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29959@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29960body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29961addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29962line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29963(gdb)
922fbb7b
AC
29964@end smallexample
29965
29966@ignore
29967@subheading The @code{-break-catch} Command
29968@findex -break-catch
48cb2d85 29969@end ignore
922fbb7b
AC
29970
29971@subheading The @code{-break-commands} Command
29972@findex -break-commands
922fbb7b 29973
48cb2d85
VP
29974@subsubheading Synopsis
29975
29976@smallexample
29977 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29978@end smallexample
29979
29980Specifies the CLI commands that should be executed when breakpoint
29981@var{number} is hit. The parameters @var{command1} to @var{commandN}
29982are the commands. If no command is specified, any previously-set
29983commands are cleared. @xref{Break Commands}. Typical use of this
29984functionality is tracing a program, that is, printing of values of
29985some variables whenever breakpoint is hit and then continuing.
29986
29987@subsubheading @value{GDBN} Command
29988
29989The corresponding @value{GDBN} command is @samp{commands}.
29990
29991@subsubheading Example
29992
29993@smallexample
29994(gdb)
29995-break-insert main
29996^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29997enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29998fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29999times="0"@}
48cb2d85
VP
30000(gdb)
30001-break-commands 1 "print v" "continue"
30002^done
30003(gdb)
30004@end smallexample
922fbb7b
AC
30005
30006@subheading The @code{-break-condition} Command
30007@findex -break-condition
30008
30009@subsubheading Synopsis
30010
30011@smallexample
30012 -break-condition @var{number} @var{expr}
30013@end smallexample
30014
30015Breakpoint @var{number} will stop the program only if the condition in
30016@var{expr} is true. The condition becomes part of the
30017@samp{-break-list} output (see the description of the @samp{-break-list}
30018command below).
30019
30020@subsubheading @value{GDBN} Command
30021
30022The corresponding @value{GDBN} command is @samp{condition}.
30023
30024@subsubheading Example
30025
30026@smallexample
594fe323 30027(gdb)
922fbb7b
AC
30028-break-condition 1 1
30029^done
594fe323 30030(gdb)
922fbb7b
AC
30031-break-list
30032^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30033hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30034@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30035@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30036@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30037@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30038@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30039body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30040addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30041line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 30042(gdb)
922fbb7b
AC
30043@end smallexample
30044
30045@subheading The @code{-break-delete} Command
30046@findex -break-delete
30047
30048@subsubheading Synopsis
30049
30050@smallexample
30051 -break-delete ( @var{breakpoint} )+
30052@end smallexample
30053
30054Delete the breakpoint(s) whose number(s) are specified in the argument
30055list. This is obviously reflected in the breakpoint list.
30056
79a6e687 30057@subsubheading @value{GDBN} Command
922fbb7b
AC
30058
30059The corresponding @value{GDBN} command is @samp{delete}.
30060
30061@subsubheading Example
30062
30063@smallexample
594fe323 30064(gdb)
922fbb7b
AC
30065-break-delete 1
30066^done
594fe323 30067(gdb)
922fbb7b
AC
30068-break-list
30069^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30070hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30071@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30072@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30073@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30074@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30075@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30076body=[]@}
594fe323 30077(gdb)
922fbb7b
AC
30078@end smallexample
30079
30080@subheading The @code{-break-disable} Command
30081@findex -break-disable
30082
30083@subsubheading Synopsis
30084
30085@smallexample
30086 -break-disable ( @var{breakpoint} )+
30087@end smallexample
30088
30089Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30090break list is now set to @samp{n} for the named @var{breakpoint}(s).
30091
30092@subsubheading @value{GDBN} Command
30093
30094The corresponding @value{GDBN} command is @samp{disable}.
30095
30096@subsubheading Example
30097
30098@smallexample
594fe323 30099(gdb)
922fbb7b
AC
30100-break-disable 2
30101^done
594fe323 30102(gdb)
922fbb7b
AC
30103-break-list
30104^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30105hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30106@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30107@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30108@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30109@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30110@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30111body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 30112addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30113line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30114(gdb)
922fbb7b
AC
30115@end smallexample
30116
30117@subheading The @code{-break-enable} Command
30118@findex -break-enable
30119
30120@subsubheading Synopsis
30121
30122@smallexample
30123 -break-enable ( @var{breakpoint} )+
30124@end smallexample
30125
30126Enable (previously disabled) @var{breakpoint}(s).
30127
30128@subsubheading @value{GDBN} Command
30129
30130The corresponding @value{GDBN} command is @samp{enable}.
30131
30132@subsubheading Example
30133
30134@smallexample
594fe323 30135(gdb)
922fbb7b
AC
30136-break-enable 2
30137^done
594fe323 30138(gdb)
922fbb7b
AC
30139-break-list
30140^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30141hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30142@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30143@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30144@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30145@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30146@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30147body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30148addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30149line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30150(gdb)
922fbb7b
AC
30151@end smallexample
30152
30153@subheading The @code{-break-info} Command
30154@findex -break-info
30155
30156@subsubheading Synopsis
30157
30158@smallexample
30159 -break-info @var{breakpoint}
30160@end smallexample
30161
30162@c REDUNDANT???
30163Get information about a single breakpoint.
30164
54516a0b
TT
30165The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30166Information}, for details on the format of each breakpoint in the
30167table.
30168
79a6e687 30169@subsubheading @value{GDBN} Command
922fbb7b
AC
30170
30171The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30172
30173@subsubheading Example
30174N.A.
30175
30176@subheading The @code{-break-insert} Command
30177@findex -break-insert
629500fa 30178@anchor{-break-insert}
922fbb7b
AC
30179
30180@subsubheading Synopsis
30181
30182@smallexample
18148017 30183 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 30184 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 30185 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
30186@end smallexample
30187
30188@noindent
afe8ab22 30189If specified, @var{location}, can be one of:
922fbb7b 30190
629500fa
KS
30191@table @var
30192@item linespec location
30193A linespec location. @xref{Linespec Locations}.
30194
30195@item explicit location
30196An explicit location. @sc{gdb/mi} explicit locations are
30197analogous to the CLI's explicit locations using the option names
30198listed below. @xref{Explicit Locations}.
30199
30200@table @samp
30201@item --source @var{filename}
30202The source file name of the location. This option requires the use
30203of either @samp{--function} or @samp{--line}.
30204
30205@item --function @var{function}
30206The name of a function or method.
922fbb7b 30207
629500fa
KS
30208@item --label @var{label}
30209The name of a label.
30210
30211@item --line @var{lineoffset}
30212An absolute or relative line offset from the start of the location.
30213@end table
30214
30215@item address location
30216An address location, *@var{address}. @xref{Address Locations}.
30217@end table
30218
30219@noindent
922fbb7b
AC
30220The possible optional parameters of this command are:
30221
30222@table @samp
30223@item -t
948d5102 30224Insert a temporary breakpoint.
922fbb7b
AC
30225@item -h
30226Insert a hardware breakpoint.
afe8ab22
VP
30227@item -f
30228If @var{location} cannot be parsed (for example if it
30229refers to unknown files or functions), create a pending
30230breakpoint. Without this flag, @value{GDBN} will report
30231an error, and won't create a breakpoint, if @var{location}
30232cannot be parsed.
41447f92
VP
30233@item -d
30234Create a disabled breakpoint.
18148017
VP
30235@item -a
30236Create a tracepoint. @xref{Tracepoints}. When this parameter
30237is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
30238@item -c @var{condition}
30239Make the breakpoint conditional on @var{condition}.
30240@item -i @var{ignore-count}
30241Initialize the @var{ignore-count}.
30242@item -p @var{thread-id}
5d5658a1
PA
30243Restrict the breakpoint to the thread with the specified global
30244@var{thread-id}.
922fbb7b
AC
30245@end table
30246
30247@subsubheading Result
30248
54516a0b
TT
30249@xref{GDB/MI Breakpoint Information}, for details on the format of the
30250resulting breakpoint.
922fbb7b
AC
30251
30252Note: this format is open to change.
30253@c An out-of-band breakpoint instead of part of the result?
30254
30255@subsubheading @value{GDBN} Command
30256
30257The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 30258@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
30259
30260@subsubheading Example
30261
30262@smallexample
594fe323 30263(gdb)
922fbb7b 30264-break-insert main
948d5102 30265^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30266fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30267times="0"@}
594fe323 30268(gdb)
922fbb7b 30269-break-insert -t foo
948d5102 30270^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30271fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30272times="0"@}
594fe323 30273(gdb)
922fbb7b
AC
30274-break-list
30275^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30276hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30277@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30278@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30279@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30280@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30281@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30282body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30283addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30284fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30285times="0"@},
922fbb7b 30286bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30287addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30288fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30289times="0"@}]@}
594fe323 30290(gdb)
496ee73e
KS
30291@c -break-insert -r foo.*
30292@c ~int foo(int, int);
30293@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30294@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30295@c times="0"@}
496ee73e 30296@c (gdb)
922fbb7b
AC
30297@end smallexample
30298
c5867ab6
HZ
30299@subheading The @code{-dprintf-insert} Command
30300@findex -dprintf-insert
30301
30302@subsubheading Synopsis
30303
30304@smallexample
30305 -dprintf-insert [ -t ] [ -f ] [ -d ]
30306 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30307 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30308 [ @var{argument} ]
30309@end smallexample
30310
30311@noindent
629500fa
KS
30312If supplied, @var{location} may be specified the same way as for
30313the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
30314
30315The possible optional parameters of this command are:
30316
30317@table @samp
30318@item -t
30319Insert a temporary breakpoint.
30320@item -f
30321If @var{location} cannot be parsed (for example, if it
30322refers to unknown files or functions), create a pending
30323breakpoint. Without this flag, @value{GDBN} will report
30324an error, and won't create a breakpoint, if @var{location}
30325cannot be parsed.
30326@item -d
30327Create a disabled breakpoint.
30328@item -c @var{condition}
30329Make the breakpoint conditional on @var{condition}.
30330@item -i @var{ignore-count}
30331Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30332to @var{ignore-count}.
30333@item -p @var{thread-id}
5d5658a1
PA
30334Restrict the breakpoint to the thread with the specified global
30335@var{thread-id}.
c5867ab6
HZ
30336@end table
30337
30338@subsubheading Result
30339
30340@xref{GDB/MI Breakpoint Information}, for details on the format of the
30341resulting breakpoint.
30342
30343@c An out-of-band breakpoint instead of part of the result?
30344
30345@subsubheading @value{GDBN} Command
30346
30347The corresponding @value{GDBN} command is @samp{dprintf}.
30348
30349@subsubheading Example
30350
30351@smallexample
30352(gdb)
303534-dprintf-insert foo "At foo entry\n"
303544^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30355addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30356fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30357times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30358original-location="foo"@}
30359(gdb)
303605-dprintf-insert 26 "arg=%d, g=%d\n" arg g
303615^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30362addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30363fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30364times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30365original-location="mi-dprintf.c:26"@}
30366(gdb)
30367@end smallexample
30368
922fbb7b
AC
30369@subheading The @code{-break-list} Command
30370@findex -break-list
30371
30372@subsubheading Synopsis
30373
30374@smallexample
30375 -break-list
30376@end smallexample
30377
30378Displays the list of inserted breakpoints, showing the following fields:
30379
30380@table @samp
30381@item Number
30382number of the breakpoint
30383@item Type
30384type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30385@item Disposition
30386should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30387or @samp{nokeep}
30388@item Enabled
30389is the breakpoint enabled or no: @samp{y} or @samp{n}
30390@item Address
30391memory location at which the breakpoint is set
30392@item What
30393logical location of the breakpoint, expressed by function name, file
30394name, line number
998580f1
MK
30395@item Thread-groups
30396list of thread groups to which this breakpoint applies
922fbb7b
AC
30397@item Times
30398number of times the breakpoint has been hit
30399@end table
30400
30401If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30402@code{body} field is an empty list.
30403
30404@subsubheading @value{GDBN} Command
30405
30406The corresponding @value{GDBN} command is @samp{info break}.
30407
30408@subsubheading Example
30409
30410@smallexample
594fe323 30411(gdb)
922fbb7b
AC
30412-break-list
30413^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30414hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30415@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30416@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30417@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30418@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30419@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30420body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30421addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30422times="0"@},
922fbb7b 30423bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30424addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30425line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30426(gdb)
922fbb7b
AC
30427@end smallexample
30428
30429Here's an example of the result when there are no breakpoints:
30430
30431@smallexample
594fe323 30432(gdb)
922fbb7b
AC
30433-break-list
30434^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30435hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30436@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30437@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30438@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30439@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30440@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30441body=[]@}
594fe323 30442(gdb)
922fbb7b
AC
30443@end smallexample
30444
18148017
VP
30445@subheading The @code{-break-passcount} Command
30446@findex -break-passcount
30447
30448@subsubheading Synopsis
30449
30450@smallexample
30451 -break-passcount @var{tracepoint-number} @var{passcount}
30452@end smallexample
30453
30454Set the passcount for tracepoint @var{tracepoint-number} to
30455@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30456is not a tracepoint, error is emitted. This corresponds to CLI
30457command @samp{passcount}.
30458
922fbb7b
AC
30459@subheading The @code{-break-watch} Command
30460@findex -break-watch
30461
30462@subsubheading Synopsis
30463
30464@smallexample
30465 -break-watch [ -a | -r ]
30466@end smallexample
30467
30468Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30469@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30470read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30471option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30472trigger only when the memory location is accessed for reading. Without
30473either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30474i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30475@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30476
30477Note that @samp{-break-list} will report a single list of watchpoints and
30478breakpoints inserted.
30479
30480@subsubheading @value{GDBN} Command
30481
30482The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30483@samp{rwatch}.
30484
30485@subsubheading Example
30486
30487Setting a watchpoint on a variable in the @code{main} function:
30488
30489@smallexample
594fe323 30490(gdb)
922fbb7b
AC
30491-break-watch x
30492^done,wpt=@{number="2",exp="x"@}
594fe323 30493(gdb)
922fbb7b
AC
30494-exec-continue
30495^running
0869d01b
NR
30496(gdb)
30497*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30498value=@{old="-268439212",new="55"@},
76ff342d 30499frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30500fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30501(gdb)
922fbb7b
AC
30502@end smallexample
30503
30504Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30505the program execution twice: first for the variable changing value, then
30506for the watchpoint going out of scope.
30507
30508@smallexample
594fe323 30509(gdb)
922fbb7b
AC
30510-break-watch C
30511^done,wpt=@{number="5",exp="C"@}
594fe323 30512(gdb)
922fbb7b
AC
30513-exec-continue
30514^running
0869d01b
NR
30515(gdb)
30516*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30517wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30518frame=@{func="callee4",args=[],
76ff342d 30519file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30520fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30521arch="i386:x86_64"@}
594fe323 30522(gdb)
922fbb7b
AC
30523-exec-continue
30524^running
0869d01b
NR
30525(gdb)
30526*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30527frame=@{func="callee3",args=[@{name="strarg",
30528value="0x11940 \"A string argument.\""@}],
76ff342d 30529file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30530fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30531arch="i386:x86_64"@}
594fe323 30532(gdb)
922fbb7b
AC
30533@end smallexample
30534
30535Listing breakpoints and watchpoints, at different points in the program
30536execution. Note that once the watchpoint goes out of scope, it is
30537deleted.
30538
30539@smallexample
594fe323 30540(gdb)
922fbb7b
AC
30541-break-watch C
30542^done,wpt=@{number="2",exp="C"@}
594fe323 30543(gdb)
922fbb7b
AC
30544-break-list
30545^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30546hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30547@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30548@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30549@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30550@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30551@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30552body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30553addr="0x00010734",func="callee4",
948d5102 30554file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30555fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30556times="1"@},
922fbb7b 30557bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30558enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30559(gdb)
922fbb7b
AC
30560-exec-continue
30561^running
0869d01b
NR
30562(gdb)
30563*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30564value=@{old="-276895068",new="3"@},
30565frame=@{func="callee4",args=[],
76ff342d 30566file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30567fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30568arch="i386:x86_64"@}
594fe323 30569(gdb)
922fbb7b
AC
30570-break-list
30571^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30572hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30573@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30574@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30575@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30576@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30577@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30578body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30579addr="0x00010734",func="callee4",
948d5102 30580file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30581fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30582times="1"@},
922fbb7b 30583bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30584enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30585(gdb)
922fbb7b
AC
30586-exec-continue
30587^running
30588^done,reason="watchpoint-scope",wpnum="2",
30589frame=@{func="callee3",args=[@{name="strarg",
30590value="0x11940 \"A string argument.\""@}],
76ff342d 30591file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30592fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30593arch="i386:x86_64"@}
594fe323 30594(gdb)
922fbb7b
AC
30595-break-list
30596^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30597hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30598@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30599@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30600@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30601@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30602@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30603body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30604addr="0x00010734",func="callee4",
948d5102
NR
30605file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30606fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30607thread-groups=["i1"],times="1"@}]@}
594fe323 30608(gdb)
922fbb7b
AC
30609@end smallexample
30610
3fa7bf06
MG
30611
30612@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30613@node GDB/MI Catchpoint Commands
30614@section @sc{gdb/mi} Catchpoint Commands
30615
30616This section documents @sc{gdb/mi} commands for manipulating
30617catchpoints.
30618
40555925
JB
30619@menu
30620* Shared Library GDB/MI Catchpoint Commands::
30621* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30622* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30623@end menu
30624
30625@node Shared Library GDB/MI Catchpoint Commands
30626@subsection Shared Library @sc{gdb/mi} Catchpoints
30627
3fa7bf06
MG
30628@subheading The @code{-catch-load} Command
30629@findex -catch-load
30630
30631@subsubheading Synopsis
30632
30633@smallexample
30634 -catch-load [ -t ] [ -d ] @var{regexp}
30635@end smallexample
30636
30637Add a catchpoint for library load events. If the @samp{-t} option is used,
30638the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30639Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30640in a disabled state. The @samp{regexp} argument is a regular
30641expression used to match the name of the loaded library.
30642
30643
30644@subsubheading @value{GDBN} Command
30645
30646The corresponding @value{GDBN} command is @samp{catch load}.
30647
30648@subsubheading Example
30649
30650@smallexample
30651-catch-load -t foo.so
30652^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30653what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30654(gdb)
30655@end smallexample
30656
30657
30658@subheading The @code{-catch-unload} Command
30659@findex -catch-unload
30660
30661@subsubheading Synopsis
30662
30663@smallexample
30664 -catch-unload [ -t ] [ -d ] @var{regexp}
30665@end smallexample
30666
30667Add a catchpoint for library unload events. If the @samp{-t} option is
30668used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30669Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30670created in a disabled state. The @samp{regexp} argument is a regular
30671expression used to match the name of the unloaded library.
30672
30673@subsubheading @value{GDBN} Command
30674
30675The corresponding @value{GDBN} command is @samp{catch unload}.
30676
30677@subsubheading Example
30678
30679@smallexample
30680-catch-unload -d bar.so
30681^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30682what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30683(gdb)
30684@end smallexample
30685
40555925
JB
30686@node Ada Exception GDB/MI Catchpoint Commands
30687@subsection Ada Exception @sc{gdb/mi} Catchpoints
30688
30689The following @sc{gdb/mi} commands can be used to create catchpoints
30690that stop the execution when Ada exceptions are being raised.
30691
30692@subheading The @code{-catch-assert} Command
30693@findex -catch-assert
30694
30695@subsubheading Synopsis
30696
30697@smallexample
30698 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30699@end smallexample
30700
30701Add a catchpoint for failed Ada assertions.
30702
30703The possible optional parameters for this command are:
30704
30705@table @samp
30706@item -c @var{condition}
30707Make the catchpoint conditional on @var{condition}.
30708@item -d
30709Create a disabled catchpoint.
30710@item -t
30711Create a temporary catchpoint.
30712@end table
30713
30714@subsubheading @value{GDBN} Command
30715
30716The corresponding @value{GDBN} command is @samp{catch assert}.
30717
30718@subsubheading Example
30719
30720@smallexample
30721-catch-assert
30722^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30723enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30724thread-groups=["i1"],times="0",
30725original-location="__gnat_debug_raise_assert_failure"@}
30726(gdb)
30727@end smallexample
30728
30729@subheading The @code{-catch-exception} Command
30730@findex -catch-exception
30731
30732@subsubheading Synopsis
30733
30734@smallexample
30735 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30736 [ -t ] [ -u ]
30737@end smallexample
30738
30739Add a catchpoint stopping when Ada exceptions are raised.
30740By default, the command stops the program when any Ada exception
30741gets raised. But it is also possible, by using some of the
30742optional parameters described below, to create more selective
30743catchpoints.
30744
30745The possible optional parameters for this command are:
30746
30747@table @samp
30748@item -c @var{condition}
30749Make the catchpoint conditional on @var{condition}.
30750@item -d
30751Create a disabled catchpoint.
30752@item -e @var{exception-name}
30753Only stop when @var{exception-name} is raised. This option cannot
30754be used combined with @samp{-u}.
30755@item -t
30756Create a temporary catchpoint.
30757@item -u
30758Stop only when an unhandled exception gets raised. This option
30759cannot be used combined with @samp{-e}.
30760@end table
30761
30762@subsubheading @value{GDBN} Command
30763
30764The corresponding @value{GDBN} commands are @samp{catch exception}
30765and @samp{catch exception unhandled}.
30766
30767@subsubheading Example
30768
30769@smallexample
30770-catch-exception -e Program_Error
30771^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30772enabled="y",addr="0x0000000000404874",
30773what="`Program_Error' Ada exception", thread-groups=["i1"],
30774times="0",original-location="__gnat_debug_raise_exception"@}
30775(gdb)
30776@end smallexample
3fa7bf06 30777
bea298f9
XR
30778@subheading The @code{-catch-handlers} Command
30779@findex -catch-handlers
30780
30781@subsubheading Synopsis
30782
30783@smallexample
30784 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30785 [ -t ]
30786@end smallexample
30787
30788Add a catchpoint stopping when Ada exceptions are handled.
30789By default, the command stops the program when any Ada exception
30790gets handled. But it is also possible, by using some of the
30791optional parameters described below, to create more selective
30792catchpoints.
30793
30794The possible optional parameters for this command are:
30795
30796@table @samp
30797@item -c @var{condition}
30798Make the catchpoint conditional on @var{condition}.
30799@item -d
30800Create a disabled catchpoint.
30801@item -e @var{exception-name}
30802Only stop when @var{exception-name} is handled.
30803@item -t
30804Create a temporary catchpoint.
30805@end table
30806
30807@subsubheading @value{GDBN} Command
30808
30809The corresponding @value{GDBN} command is @samp{catch handlers}.
30810
30811@subsubheading Example
30812
30813@smallexample
30814-catch-handlers -e Constraint_Error
30815^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30816enabled="y",addr="0x0000000000402f68",
30817what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30818times="0",original-location="__gnat_begin_handler"@}
30819(gdb)
30820@end smallexample
30821
30056ea0
AB
30822@node C++ Exception GDB/MI Catchpoint Commands
30823@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30824
30825The following @sc{gdb/mi} commands can be used to create catchpoints
30826that stop the execution when C@t{++} exceptions are being throw, rethrown,
30827or caught.
30828
30829@subheading The @code{-catch-throw} Command
30830@findex -catch-throw
30831
30832@subsubheading Synopsis
30833
30834@smallexample
30835 -catch-throw [ -t ] [ -r @var{regexp}]
30836@end smallexample
30837
30838Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30839given, then only exceptions whose type matches the regular expression
30840will be caught.
30841
30842If @samp{-t} is given, then the catchpoint is enabled only for one
30843stop, the catchpoint is automatically deleted after stopping once for
30844the event.
30845
30846@subsubheading @value{GDBN} Command
30847
30848The corresponding @value{GDBN} commands are @samp{catch throw}
30849and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30850
30851@subsubheading Example
30852
30853@smallexample
30854-catch-throw -r exception_type
cb1e4e32
PA
30855^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30856 what="exception throw",catch-type="throw",
30857 thread-groups=["i1"],
30056ea0
AB
30858 regexp="exception_type",times="0"@}
30859(gdb)
30860-exec-run
30861^running
30862(gdb)
30863~"\n"
30864~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30865 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30866*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30867 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30868 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30869 thread-id="1",stopped-threads="all",core="6"
30870(gdb)
30871@end smallexample
30872
30873@subheading The @code{-catch-rethrow} Command
30874@findex -catch-rethrow
30875
30876@subsubheading Synopsis
30877
30878@smallexample
30879 -catch-rethrow [ -t ] [ -r @var{regexp}]
30880@end smallexample
30881
30882Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30883then only exceptions whose type matches the regular expression will be
30884caught.
30885
30886If @samp{-t} is given, then the catchpoint is enabled only for one
30887stop, the catchpoint is automatically deleted after the first event is
30888caught.
30889
30890@subsubheading @value{GDBN} Command
30891
30892The corresponding @value{GDBN} commands are @samp{catch rethrow}
30893and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30894
30895@subsubheading Example
30896
30897@smallexample
30898-catch-rethrow -r exception_type
cb1e4e32
PA
30899^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30900 what="exception rethrow",catch-type="rethrow",
30901 thread-groups=["i1"],
30056ea0
AB
30902 regexp="exception_type",times="0"@}
30903(gdb)
30904-exec-run
30905^running
30906(gdb)
30907~"\n"
30908~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30909 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30910*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30911 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30912 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30913 thread-id="1",stopped-threads="all",core="6"
30914(gdb)
30915@end smallexample
30916
30917@subheading The @code{-catch-catch} Command
30918@findex -catch-catch
30919
30920@subsubheading Synopsis
30921
30922@smallexample
30923 -catch-catch [ -t ] [ -r @var{regexp}]
30924@end smallexample
30925
30926Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30927is given, then only exceptions whose type matches the regular
30928expression will be caught.
30929
30930If @samp{-t} is given, then the catchpoint is enabled only for one
30931stop, the catchpoint is automatically deleted after the first event is
30932caught.
30933
30934@subsubheading @value{GDBN} Command
30935
30936The corresponding @value{GDBN} commands are @samp{catch catch}
30937and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30938
30939@subsubheading Example
30940
30941@smallexample
30942-catch-catch -r exception_type
cb1e4e32
PA
30943^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30944 what="exception catch",catch-type="catch",
30945 thread-groups=["i1"],
30056ea0
AB
30946 regexp="exception_type",times="0"@}
30947(gdb)
30948-exec-run
30949^running
30950(gdb)
30951~"\n"
30952~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30953 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30954*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30955 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30956 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30957 thread-id="1",stopped-threads="all",core="6"
30958(gdb)
30959@end smallexample
30960
922fbb7b 30961@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30962@node GDB/MI Program Context
30963@section @sc{gdb/mi} Program Context
922fbb7b 30964
a2c02241
NR
30965@subheading The @code{-exec-arguments} Command
30966@findex -exec-arguments
922fbb7b 30967
922fbb7b
AC
30968
30969@subsubheading Synopsis
30970
30971@smallexample
a2c02241 30972 -exec-arguments @var{args}
922fbb7b
AC
30973@end smallexample
30974
a2c02241
NR
30975Set the inferior program arguments, to be used in the next
30976@samp{-exec-run}.
922fbb7b 30977
a2c02241 30978@subsubheading @value{GDBN} Command
922fbb7b 30979
a2c02241 30980The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 30981
a2c02241 30982@subsubheading Example
922fbb7b 30983
fbc5282e
MK
30984@smallexample
30985(gdb)
30986-exec-arguments -v word
30987^done
30988(gdb)
30989@end smallexample
922fbb7b 30990
a2c02241 30991
9901a55b 30992@ignore
a2c02241
NR
30993@subheading The @code{-exec-show-arguments} Command
30994@findex -exec-show-arguments
30995
30996@subsubheading Synopsis
30997
30998@smallexample
30999 -exec-show-arguments
31000@end smallexample
31001
31002Print the arguments of the program.
922fbb7b
AC
31003
31004@subsubheading @value{GDBN} Command
31005
a2c02241 31006The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
31007
31008@subsubheading Example
a2c02241 31009N.A.
9901a55b 31010@end ignore
922fbb7b 31011
922fbb7b 31012
a2c02241
NR
31013@subheading The @code{-environment-cd} Command
31014@findex -environment-cd
922fbb7b 31015
a2c02241 31016@subsubheading Synopsis
922fbb7b
AC
31017
31018@smallexample
a2c02241 31019 -environment-cd @var{pathdir}
922fbb7b
AC
31020@end smallexample
31021
a2c02241 31022Set @value{GDBN}'s working directory.
922fbb7b 31023
a2c02241 31024@subsubheading @value{GDBN} Command
922fbb7b 31025
a2c02241
NR
31026The corresponding @value{GDBN} command is @samp{cd}.
31027
31028@subsubheading Example
922fbb7b
AC
31029
31030@smallexample
594fe323 31031(gdb)
a2c02241
NR
31032-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31033^done
594fe323 31034(gdb)
922fbb7b
AC
31035@end smallexample
31036
31037
a2c02241
NR
31038@subheading The @code{-environment-directory} Command
31039@findex -environment-directory
922fbb7b
AC
31040
31041@subsubheading Synopsis
31042
31043@smallexample
a2c02241 31044 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31045@end smallexample
31046
a2c02241
NR
31047Add directories @var{pathdir} to beginning of search path for source files.
31048If the @samp{-r} option is used, the search path is reset to the default
31049search path. If directories @var{pathdir} are supplied in addition to the
31050@samp{-r} option, the search path is first reset and then addition
31051occurs as normal.
31052Multiple directories may be specified, separated by blanks. Specifying
31053multiple directories in a single command
31054results in the directories added to the beginning of the
31055search path in the same order they were presented in the command.
31056If blanks are needed as
31057part of a directory name, double-quotes should be used around
31058the name. In the command output, the path will show up separated
d3e8051b 31059by the system directory-separator character. The directory-separator
a2c02241
NR
31060character must not be used
31061in any directory name.
31062If no directories are specified, the current search path is displayed.
922fbb7b
AC
31063
31064@subsubheading @value{GDBN} Command
31065
a2c02241 31066The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
31067
31068@subsubheading Example
31069
922fbb7b 31070@smallexample
594fe323 31071(gdb)
a2c02241
NR
31072-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31073^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31074(gdb)
a2c02241
NR
31075-environment-directory ""
31076^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31077(gdb)
a2c02241
NR
31078-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31079^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 31080(gdb)
a2c02241
NR
31081-environment-directory -r
31082^done,source-path="$cdir:$cwd"
594fe323 31083(gdb)
922fbb7b
AC
31084@end smallexample
31085
31086
a2c02241
NR
31087@subheading The @code{-environment-path} Command
31088@findex -environment-path
922fbb7b
AC
31089
31090@subsubheading Synopsis
31091
31092@smallexample
a2c02241 31093 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31094@end smallexample
31095
a2c02241
NR
31096Add directories @var{pathdir} to beginning of search path for object files.
31097If the @samp{-r} option is used, the search path is reset to the original
31098search path that existed at gdb start-up. If directories @var{pathdir} are
31099supplied in addition to the
31100@samp{-r} option, the search path is first reset and then addition
31101occurs as normal.
31102Multiple directories may be specified, separated by blanks. Specifying
31103multiple directories in a single command
31104results in the directories added to the beginning of the
31105search path in the same order they were presented in the command.
31106If blanks are needed as
31107part of a directory name, double-quotes should be used around
31108the name. In the command output, the path will show up separated
d3e8051b 31109by the system directory-separator character. The directory-separator
a2c02241
NR
31110character must not be used
31111in any directory name.
31112If no directories are specified, the current path is displayed.
31113
922fbb7b
AC
31114
31115@subsubheading @value{GDBN} Command
31116
a2c02241 31117The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
31118
31119@subsubheading Example
31120
922fbb7b 31121@smallexample
594fe323 31122(gdb)
a2c02241
NR
31123-environment-path
31124^done,path="/usr/bin"
594fe323 31125(gdb)
a2c02241
NR
31126-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31127^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 31128(gdb)
a2c02241
NR
31129-environment-path -r /usr/local/bin
31130^done,path="/usr/local/bin:/usr/bin"
594fe323 31131(gdb)
922fbb7b
AC
31132@end smallexample
31133
31134
a2c02241
NR
31135@subheading The @code{-environment-pwd} Command
31136@findex -environment-pwd
922fbb7b
AC
31137
31138@subsubheading Synopsis
31139
31140@smallexample
a2c02241 31141 -environment-pwd
922fbb7b
AC
31142@end smallexample
31143
a2c02241 31144Show the current working directory.
922fbb7b 31145
79a6e687 31146@subsubheading @value{GDBN} Command
922fbb7b 31147
a2c02241 31148The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
31149
31150@subsubheading Example
31151
922fbb7b 31152@smallexample
594fe323 31153(gdb)
a2c02241
NR
31154-environment-pwd
31155^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 31156(gdb)
922fbb7b
AC
31157@end smallexample
31158
a2c02241
NR
31159@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31160@node GDB/MI Thread Commands
31161@section @sc{gdb/mi} Thread Commands
31162
31163
31164@subheading The @code{-thread-info} Command
31165@findex -thread-info
922fbb7b
AC
31166
31167@subsubheading Synopsis
31168
31169@smallexample
8e8901c5 31170 -thread-info [ @var{thread-id} ]
922fbb7b
AC
31171@end smallexample
31172
5d5658a1
PA
31173Reports information about either a specific thread, if the
31174@var{thread-id} parameter is present, or about all threads.
31175@var{thread-id} is the thread's global thread ID. When printing
31176information about all threads, also reports the global ID of the
31177current thread.
8e8901c5 31178
79a6e687 31179@subsubheading @value{GDBN} Command
922fbb7b 31180
8e8901c5
VP
31181The @samp{info thread} command prints the same information
31182about all threads.
922fbb7b 31183
4694da01 31184@subsubheading Result
922fbb7b 31185
ebe553db 31186The result contains the following attributes:
4694da01
TT
31187
31188@table @samp
ebe553db
SM
31189@item threads
31190A list of threads. The format of the elements of the list is described in
31191@ref{GDB/MI Thread Information}.
31192
31193@item current-thread-id
31194The global id of the currently selected thread. This field is omitted if there
31195is no selected thread (for example, when the selected inferior is not running,
31196and therefore has no threads) or if a @var{thread-id} argument was passed to
31197the command.
4694da01
TT
31198
31199@end table
31200
31201@subsubheading Example
31202
31203@smallexample
31204-thread-info
31205^done,threads=[
31206@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31207 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31208 args=[]@},state="running"@},
31209@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31210 frame=@{level="0",addr="0x0804891f",func="foo",
31211 args=[@{name="i",value="10"@}],
6d52907e 31212 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
31213 state="running"@}],
31214current-thread-id="1"
31215(gdb)
31216@end smallexample
31217
a2c02241
NR
31218@subheading The @code{-thread-list-ids} Command
31219@findex -thread-list-ids
922fbb7b 31220
a2c02241 31221@subsubheading Synopsis
922fbb7b 31222
a2c02241
NR
31223@smallexample
31224 -thread-list-ids
31225@end smallexample
922fbb7b 31226
5d5658a1
PA
31227Produces a list of the currently known global @value{GDBN} thread ids.
31228At the end of the list it also prints the total number of such
31229threads.
922fbb7b 31230
c3b108f7
VP
31231This command is retained for historical reasons, the
31232@code{-thread-info} command should be used instead.
31233
922fbb7b
AC
31234@subsubheading @value{GDBN} Command
31235
a2c02241 31236Part of @samp{info threads} supplies the same information.
922fbb7b
AC
31237
31238@subsubheading Example
31239
922fbb7b 31240@smallexample
594fe323 31241(gdb)
a2c02241
NR
31242-thread-list-ids
31243^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 31244current-thread-id="1",number-of-threads="3"
594fe323 31245(gdb)
922fbb7b
AC
31246@end smallexample
31247
a2c02241
NR
31248
31249@subheading The @code{-thread-select} Command
31250@findex -thread-select
922fbb7b
AC
31251
31252@subsubheading Synopsis
31253
31254@smallexample
5d5658a1 31255 -thread-select @var{thread-id}
922fbb7b
AC
31256@end smallexample
31257
5d5658a1
PA
31258Make thread with global thread number @var{thread-id} the current
31259thread. It prints the number of the new current thread, and the
31260topmost frame for that thread.
922fbb7b 31261
c3b108f7
VP
31262This command is deprecated in favor of explicitly using the
31263@samp{--thread} option to each command.
31264
922fbb7b
AC
31265@subsubheading @value{GDBN} Command
31266
a2c02241 31267The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31268
31269@subsubheading Example
922fbb7b
AC
31270
31271@smallexample
594fe323 31272(gdb)
a2c02241
NR
31273-exec-next
31274^running
594fe323 31275(gdb)
a2c02241
NR
31276*stopped,reason="end-stepping-range",thread-id="2",line="187",
31277file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31278(gdb)
a2c02241
NR
31279-thread-list-ids
31280^done,
31281thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31282number-of-threads="3"
594fe323 31283(gdb)
a2c02241
NR
31284-thread-select 3
31285^done,new-thread-id="3",
31286frame=@{level="0",func="vprintf",
31287args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31288@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31289(gdb)
922fbb7b
AC
31290@end smallexample
31291
5d77fe44
JB
31292@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31293@node GDB/MI Ada Tasking Commands
31294@section @sc{gdb/mi} Ada Tasking Commands
31295
31296@subheading The @code{-ada-task-info} Command
31297@findex -ada-task-info
31298
31299@subsubheading Synopsis
31300
31301@smallexample
31302 -ada-task-info [ @var{task-id} ]
31303@end smallexample
31304
31305Reports information about either a specific Ada task, if the
31306@var{task-id} parameter is present, or about all Ada tasks.
31307
31308@subsubheading @value{GDBN} Command
31309
31310The @samp{info tasks} command prints the same information
31311about all Ada tasks (@pxref{Ada Tasks}).
31312
31313@subsubheading Result
31314
31315The result is a table of Ada tasks. The following columns are
31316defined for each Ada task:
31317
31318@table @samp
31319@item current
31320This field exists only for the current thread. It has the value @samp{*}.
31321
31322@item id
31323The identifier that @value{GDBN} uses to refer to the Ada task.
31324
31325@item task-id
31326The identifier that the target uses to refer to the Ada task.
31327
31328@item thread-id
5d5658a1
PA
31329The global thread identifier of the thread corresponding to the Ada
31330task.
5d77fe44
JB
31331
31332This field should always exist, as Ada tasks are always implemented
31333on top of a thread. But if @value{GDBN} cannot find this corresponding
31334thread for any reason, the field is omitted.
31335
31336@item parent-id
31337This field exists only when the task was created by another task.
31338In this case, it provides the ID of the parent task.
31339
31340@item priority
31341The base priority of the task.
31342
31343@item state
31344The current state of the task. For a detailed description of the
31345possible states, see @ref{Ada Tasks}.
31346
31347@item name
31348The name of the task.
31349
31350@end table
31351
31352@subsubheading Example
31353
31354@smallexample
31355-ada-task-info
31356^done,tasks=@{nr_rows="3",nr_cols="8",
31357hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31358@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31359@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31360@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31361@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31362@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31363@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31364@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31365body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31366state="Child Termination Wait",name="main_task"@}]@}
31367(gdb)
31368@end smallexample
31369
a2c02241
NR
31370@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31371@node GDB/MI Program Execution
31372@section @sc{gdb/mi} Program Execution
922fbb7b 31373
ef21caaf 31374These are the asynchronous commands which generate the out-of-band
3f94c067 31375record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31376asynchronously with remote targets and this interaction is mimicked in
31377other cases.
922fbb7b 31378
922fbb7b
AC
31379@subheading The @code{-exec-continue} Command
31380@findex -exec-continue
31381
31382@subsubheading Synopsis
31383
31384@smallexample
540aa8e7 31385 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31386@end smallexample
31387
540aa8e7
MS
31388Resumes the execution of the inferior program, which will continue
31389to execute until it reaches a debugger stop event. If the
31390@samp{--reverse} option is specified, execution resumes in reverse until
31391it reaches a stop event. Stop events may include
31392@itemize @bullet
31393@item
31394breakpoints or watchpoints
31395@item
31396signals or exceptions
31397@item
31398the end of the process (or its beginning under @samp{--reverse})
31399@item
31400the end or beginning of a replay log if one is being used.
31401@end itemize
31402In all-stop mode (@pxref{All-Stop
31403Mode}), may resume only one thread, or all threads, depending on the
31404value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31405specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31406ignored in all-stop mode. If the @samp{--thread-group} options is
31407specified, then all threads in that thread group are resumed.
922fbb7b
AC
31408
31409@subsubheading @value{GDBN} Command
31410
31411The corresponding @value{GDBN} corresponding is @samp{continue}.
31412
31413@subsubheading Example
31414
31415@smallexample
31416-exec-continue
31417^running
594fe323 31418(gdb)
922fbb7b 31419@@Hello world
a47ec5fe
AR
31420*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31421func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31422line="13",arch="i386:x86_64"@}
594fe323 31423(gdb)
922fbb7b
AC
31424@end smallexample
31425
31426
31427@subheading The @code{-exec-finish} Command
31428@findex -exec-finish
31429
31430@subsubheading Synopsis
31431
31432@smallexample
540aa8e7 31433 -exec-finish [--reverse]
922fbb7b
AC
31434@end smallexample
31435
ef21caaf
NR
31436Resumes the execution of the inferior program until the current
31437function is exited. Displays the results returned by the function.
540aa8e7
MS
31438If the @samp{--reverse} option is specified, resumes the reverse
31439execution of the inferior program until the point where current
31440function was called.
922fbb7b
AC
31441
31442@subsubheading @value{GDBN} Command
31443
31444The corresponding @value{GDBN} command is @samp{finish}.
31445
31446@subsubheading Example
31447
31448Function returning @code{void}.
31449
31450@smallexample
31451-exec-finish
31452^running
594fe323 31453(gdb)
922fbb7b
AC
31454@@hello from foo
31455*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31456file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31457(gdb)
922fbb7b
AC
31458@end smallexample
31459
31460Function returning other than @code{void}. The name of the internal
31461@value{GDBN} variable storing the result is printed, together with the
31462value itself.
31463
31464@smallexample
31465-exec-finish
31466^running
594fe323 31467(gdb)
922fbb7b
AC
31468*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31469args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31470file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31471arch="i386:x86_64"@},
922fbb7b 31472gdb-result-var="$1",return-value="0"
594fe323 31473(gdb)
922fbb7b
AC
31474@end smallexample
31475
31476
31477@subheading The @code{-exec-interrupt} Command
31478@findex -exec-interrupt
31479
31480@subsubheading Synopsis
31481
31482@smallexample
c3b108f7 31483 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31484@end smallexample
31485
ef21caaf
NR
31486Interrupts the background execution of the target. Note how the token
31487associated with the stop message is the one for the execution command
31488that has been interrupted. The token for the interrupt itself only
31489appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31490interrupt a non-running program, an error message will be printed.
31491
c3b108f7
VP
31492Note that when asynchronous execution is enabled, this command is
31493asynchronous just like other execution commands. That is, first the
31494@samp{^done} response will be printed, and the target stop will be
31495reported after that using the @samp{*stopped} notification.
31496
31497In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31498All threads (in all inferiors) will be interrupted if the
31499@samp{--all} option is specified. If the @samp{--thread-group}
31500option is specified, all threads in that group will be interrupted.
c3b108f7 31501
922fbb7b
AC
31502@subsubheading @value{GDBN} Command
31503
31504The corresponding @value{GDBN} command is @samp{interrupt}.
31505
31506@subsubheading Example
31507
31508@smallexample
594fe323 31509(gdb)
922fbb7b
AC
31510111-exec-continue
31511111^running
31512
594fe323 31513(gdb)
922fbb7b
AC
31514222-exec-interrupt
31515222^done
594fe323 31516(gdb)
922fbb7b 31517111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31518frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31519fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31520(gdb)
922fbb7b 31521
594fe323 31522(gdb)
922fbb7b
AC
31523-exec-interrupt
31524^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31525(gdb)
922fbb7b
AC
31526@end smallexample
31527
83eba9b7
VP
31528@subheading The @code{-exec-jump} Command
31529@findex -exec-jump
31530
31531@subsubheading Synopsis
31532
31533@smallexample
31534 -exec-jump @var{location}
31535@end smallexample
31536
31537Resumes execution of the inferior program at the location specified by
31538parameter. @xref{Specify Location}, for a description of the
31539different forms of @var{location}.
31540
31541@subsubheading @value{GDBN} Command
31542
31543The corresponding @value{GDBN} command is @samp{jump}.
31544
31545@subsubheading Example
31546
31547@smallexample
31548-exec-jump foo.c:10
31549*running,thread-id="all"
31550^running
31551@end smallexample
31552
922fbb7b
AC
31553
31554@subheading The @code{-exec-next} Command
31555@findex -exec-next
31556
31557@subsubheading Synopsis
31558
31559@smallexample
540aa8e7 31560 -exec-next [--reverse]
922fbb7b
AC
31561@end smallexample
31562
ef21caaf
NR
31563Resumes execution of the inferior program, stopping when the beginning
31564of the next source line is reached.
922fbb7b 31565
540aa8e7
MS
31566If the @samp{--reverse} option is specified, resumes reverse execution
31567of the inferior program, stopping at the beginning of the previous
31568source line. If you issue this command on the first line of a
31569function, it will take you back to the caller of that function, to the
31570source line where the function was called.
31571
31572
922fbb7b
AC
31573@subsubheading @value{GDBN} Command
31574
31575The corresponding @value{GDBN} command is @samp{next}.
31576
31577@subsubheading Example
31578
31579@smallexample
31580-exec-next
31581^running
594fe323 31582(gdb)
922fbb7b 31583*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31584(gdb)
922fbb7b
AC
31585@end smallexample
31586
31587
31588@subheading The @code{-exec-next-instruction} Command
31589@findex -exec-next-instruction
31590
31591@subsubheading Synopsis
31592
31593@smallexample
540aa8e7 31594 -exec-next-instruction [--reverse]
922fbb7b
AC
31595@end smallexample
31596
ef21caaf
NR
31597Executes one machine instruction. If the instruction is a function
31598call, continues until the function returns. If the program stops at an
31599instruction in the middle of a source line, the address will be
31600printed as well.
922fbb7b 31601
540aa8e7
MS
31602If the @samp{--reverse} option is specified, resumes reverse execution
31603of the inferior program, stopping at the previous instruction. If the
31604previously executed instruction was a return from another function,
31605it will continue to execute in reverse until the call to that function
31606(from the current stack frame) is reached.
31607
922fbb7b
AC
31608@subsubheading @value{GDBN} Command
31609
31610The corresponding @value{GDBN} command is @samp{nexti}.
31611
31612@subsubheading Example
31613
31614@smallexample
594fe323 31615(gdb)
922fbb7b
AC
31616-exec-next-instruction
31617^running
31618
594fe323 31619(gdb)
922fbb7b
AC
31620*stopped,reason="end-stepping-range",
31621addr="0x000100d4",line="5",file="hello.c"
594fe323 31622(gdb)
922fbb7b
AC
31623@end smallexample
31624
31625
31626@subheading The @code{-exec-return} Command
31627@findex -exec-return
31628
31629@subsubheading Synopsis
31630
31631@smallexample
31632 -exec-return
31633@end smallexample
31634
31635Makes current function return immediately. Doesn't execute the inferior.
31636Displays the new current frame.
31637
31638@subsubheading @value{GDBN} Command
31639
31640The corresponding @value{GDBN} command is @samp{return}.
31641
31642@subsubheading Example
31643
31644@smallexample
594fe323 31645(gdb)
922fbb7b
AC
31646200-break-insert callee4
31647200^done,bkpt=@{number="1",addr="0x00010734",
31648file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31649(gdb)
922fbb7b
AC
31650000-exec-run
31651000^running
594fe323 31652(gdb)
a47ec5fe 31653000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31654frame=@{func="callee4",args=[],
76ff342d 31655file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31656fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31657arch="i386:x86_64"@}
594fe323 31658(gdb)
922fbb7b
AC
31659205-break-delete
31660205^done
594fe323 31661(gdb)
922fbb7b
AC
31662111-exec-return
31663111^done,frame=@{level="0",func="callee3",
31664args=[@{name="strarg",
31665value="0x11940 \"A string argument.\""@}],
76ff342d 31666file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31667fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31668arch="i386:x86_64"@}
594fe323 31669(gdb)
922fbb7b
AC
31670@end smallexample
31671
31672
31673@subheading The @code{-exec-run} Command
31674@findex -exec-run
31675
31676@subsubheading Synopsis
31677
31678@smallexample
5713b9b5 31679 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31680@end smallexample
31681
ef21caaf
NR
31682Starts execution of the inferior from the beginning. The inferior
31683executes until either a breakpoint is encountered or the program
31684exits. In the latter case the output will include an exit code, if
31685the program has exited exceptionally.
922fbb7b 31686
5713b9b5
JB
31687When neither the @samp{--all} nor the @samp{--thread-group} option
31688is specified, the current inferior is started. If the
a79b8f6e
VP
31689@samp{--thread-group} option is specified, it should refer to a thread
31690group of type @samp{process}, and that thread group will be started.
31691If the @samp{--all} option is specified, then all inferiors will be started.
31692
5713b9b5
JB
31693Using the @samp{--start} option instructs the debugger to stop
31694the execution at the start of the inferior's main subprogram,
31695following the same behavior as the @code{start} command
31696(@pxref{Starting}).
31697
922fbb7b
AC
31698@subsubheading @value{GDBN} Command
31699
31700The corresponding @value{GDBN} command is @samp{run}.
31701
ef21caaf 31702@subsubheading Examples
922fbb7b
AC
31703
31704@smallexample
594fe323 31705(gdb)
922fbb7b
AC
31706-break-insert main
31707^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31708(gdb)
922fbb7b
AC
31709-exec-run
31710^running
594fe323 31711(gdb)
a47ec5fe 31712*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31713frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31714fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31715(gdb)
922fbb7b
AC
31716@end smallexample
31717
ef21caaf
NR
31718@noindent
31719Program exited normally:
31720
31721@smallexample
594fe323 31722(gdb)
ef21caaf
NR
31723-exec-run
31724^running
594fe323 31725(gdb)
ef21caaf
NR
31726x = 55
31727*stopped,reason="exited-normally"
594fe323 31728(gdb)
ef21caaf
NR
31729@end smallexample
31730
31731@noindent
31732Program exited exceptionally:
31733
31734@smallexample
594fe323 31735(gdb)
ef21caaf
NR
31736-exec-run
31737^running
594fe323 31738(gdb)
ef21caaf
NR
31739x = 55
31740*stopped,reason="exited",exit-code="01"
594fe323 31741(gdb)
ef21caaf
NR
31742@end smallexample
31743
31744Another way the program can terminate is if it receives a signal such as
31745@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31746
31747@smallexample
594fe323 31748(gdb)
ef21caaf
NR
31749*stopped,reason="exited-signalled",signal-name="SIGINT",
31750signal-meaning="Interrupt"
31751@end smallexample
31752
922fbb7b 31753
a2c02241
NR
31754@c @subheading -exec-signal
31755
31756
31757@subheading The @code{-exec-step} Command
31758@findex -exec-step
922fbb7b
AC
31759
31760@subsubheading Synopsis
31761
31762@smallexample
540aa8e7 31763 -exec-step [--reverse]
922fbb7b
AC
31764@end smallexample
31765
a2c02241
NR
31766Resumes execution of the inferior program, stopping when the beginning
31767of the next source line is reached, if the next source line is not a
31768function call. If it is, stop at the first instruction of the called
540aa8e7
MS
31769function. If the @samp{--reverse} option is specified, resumes reverse
31770execution of the inferior program, stopping at the beginning of the
31771previously executed source line.
922fbb7b
AC
31772
31773@subsubheading @value{GDBN} Command
31774
a2c02241 31775The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
31776
31777@subsubheading Example
31778
31779Stepping into a function:
31780
31781@smallexample
31782-exec-step
31783^running
594fe323 31784(gdb)
922fbb7b
AC
31785*stopped,reason="end-stepping-range",
31786frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 31787@{name="b",value="0"@}],file="recursive2.c",
6d52907e 31788fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 31789(gdb)
922fbb7b
AC
31790@end smallexample
31791
31792Regular stepping:
31793
31794@smallexample
31795-exec-step
31796^running
594fe323 31797(gdb)
922fbb7b 31798*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 31799(gdb)
922fbb7b
AC
31800@end smallexample
31801
31802
31803@subheading The @code{-exec-step-instruction} Command
31804@findex -exec-step-instruction
31805
31806@subsubheading Synopsis
31807
31808@smallexample
540aa8e7 31809 -exec-step-instruction [--reverse]
922fbb7b
AC
31810@end smallexample
31811
540aa8e7
MS
31812Resumes the inferior which executes one machine instruction. If the
31813@samp{--reverse} option is specified, resumes reverse execution of the
31814inferior program, stopping at the previously executed instruction.
31815The output, once @value{GDBN} has stopped, will vary depending on
31816whether we have stopped in the middle of a source line or not. In the
31817former case, the address at which the program stopped will be printed
31818as well.
922fbb7b
AC
31819
31820@subsubheading @value{GDBN} Command
31821
31822The corresponding @value{GDBN} command is @samp{stepi}.
31823
31824@subsubheading Example
31825
31826@smallexample
594fe323 31827(gdb)
922fbb7b
AC
31828-exec-step-instruction
31829^running
31830
594fe323 31831(gdb)
922fbb7b 31832*stopped,reason="end-stepping-range",
76ff342d 31833frame=@{func="foo",args=[],file="try.c",
6d52907e 31834fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31835(gdb)
922fbb7b
AC
31836-exec-step-instruction
31837^running
31838
594fe323 31839(gdb)
922fbb7b 31840*stopped,reason="end-stepping-range",
76ff342d 31841frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 31842fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31843(gdb)
922fbb7b
AC
31844@end smallexample
31845
31846
31847@subheading The @code{-exec-until} Command
31848@findex -exec-until
31849
31850@subsubheading Synopsis
31851
31852@smallexample
31853 -exec-until [ @var{location} ]
31854@end smallexample
31855
ef21caaf
NR
31856Executes the inferior until the @var{location} specified in the
31857argument is reached. If there is no argument, the inferior executes
31858until a source line greater than the current one is reached. The
31859reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
31860
31861@subsubheading @value{GDBN} Command
31862
31863The corresponding @value{GDBN} command is @samp{until}.
31864
31865@subsubheading Example
31866
31867@smallexample
594fe323 31868(gdb)
922fbb7b
AC
31869-exec-until recursive2.c:6
31870^running
594fe323 31871(gdb)
922fbb7b
AC
31872x = 55
31873*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
31874file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31875arch="i386:x86_64"@}
594fe323 31876(gdb)
922fbb7b
AC
31877@end smallexample
31878
31879@ignore
31880@subheading -file-clear
31881Is this going away????
31882@end ignore
31883
351ff01a 31884@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31885@node GDB/MI Stack Manipulation
31886@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 31887
1e611234
PM
31888@subheading The @code{-enable-frame-filters} Command
31889@findex -enable-frame-filters
31890
31891@smallexample
31892-enable-frame-filters
31893@end smallexample
31894
31895@value{GDBN} allows Python-based frame filters to affect the output of
31896the MI commands relating to stack traces. As there is no way to
31897implement this in a fully backward-compatible way, a front end must
31898request that this functionality be enabled.
31899
31900Once enabled, this feature cannot be disabled.
31901
31902Note that if Python support has not been compiled into @value{GDBN},
31903this command will still succeed (and do nothing).
922fbb7b 31904
a2c02241
NR
31905@subheading The @code{-stack-info-frame} Command
31906@findex -stack-info-frame
922fbb7b
AC
31907
31908@subsubheading Synopsis
31909
31910@smallexample
a2c02241 31911 -stack-info-frame
922fbb7b
AC
31912@end smallexample
31913
a2c02241 31914Get info on the selected frame.
922fbb7b
AC
31915
31916@subsubheading @value{GDBN} Command
31917
a2c02241
NR
31918The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31919(without arguments).
922fbb7b
AC
31920
31921@subsubheading Example
31922
31923@smallexample
594fe323 31924(gdb)
a2c02241
NR
31925-stack-info-frame
31926^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31927file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31928fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31929arch="i386:x86_64"@}
594fe323 31930(gdb)
922fbb7b
AC
31931@end smallexample
31932
a2c02241
NR
31933@subheading The @code{-stack-info-depth} Command
31934@findex -stack-info-depth
922fbb7b
AC
31935
31936@subsubheading Synopsis
31937
31938@smallexample
a2c02241 31939 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
31940@end smallexample
31941
a2c02241
NR
31942Return the depth of the stack. If the integer argument @var{max-depth}
31943is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
31944
31945@subsubheading @value{GDBN} Command
31946
a2c02241 31947There's no equivalent @value{GDBN} command.
922fbb7b
AC
31948
31949@subsubheading Example
31950
a2c02241
NR
31951For a stack with frame levels 0 through 11:
31952
922fbb7b 31953@smallexample
594fe323 31954(gdb)
a2c02241
NR
31955-stack-info-depth
31956^done,depth="12"
594fe323 31957(gdb)
a2c02241
NR
31958-stack-info-depth 4
31959^done,depth="4"
594fe323 31960(gdb)
a2c02241
NR
31961-stack-info-depth 12
31962^done,depth="12"
594fe323 31963(gdb)
a2c02241
NR
31964-stack-info-depth 11
31965^done,depth="11"
594fe323 31966(gdb)
a2c02241
NR
31967-stack-info-depth 13
31968^done,depth="12"
594fe323 31969(gdb)
922fbb7b
AC
31970@end smallexample
31971
1e611234 31972@anchor{-stack-list-arguments}
a2c02241
NR
31973@subheading The @code{-stack-list-arguments} Command
31974@findex -stack-list-arguments
922fbb7b
AC
31975
31976@subsubheading Synopsis
31977
31978@smallexample
6211c335 31979 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 31980 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
31981@end smallexample
31982
a2c02241
NR
31983Display a list of the arguments for the frames between @var{low-frame}
31984and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
31985@var{high-frame} are not provided, list the arguments for the whole
31986call stack. If the two arguments are equal, show the single frame
31987at the corresponding level. It is an error if @var{low-frame} is
31988larger than the actual number of frames. On the other hand,
31989@var{high-frame} may be larger than the actual number of frames, in
31990which case only existing frames will be returned.
a2c02241 31991
3afae151
VP
31992If @var{print-values} is 0 or @code{--no-values}, print only the names of
31993the variables; if it is 1 or @code{--all-values}, print also their
31994values; and if it is 2 or @code{--simple-values}, print the name,
31995type and value for simple data types, and the name and type for arrays,
1e611234
PM
31996structures and unions. If the option @code{--no-frame-filters} is
31997supplied, then Python frame filters will not be executed.
31998
6211c335
YQ
31999If the @code{--skip-unavailable} option is specified, arguments that
32000are not available are not listed. Partially available arguments
32001are still displayed, however.
922fbb7b 32002
b3372f91
VP
32003Use of this command to obtain arguments in a single frame is
32004deprecated in favor of the @samp{-stack-list-variables} command.
32005
922fbb7b
AC
32006@subsubheading @value{GDBN} Command
32007
a2c02241
NR
32008@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32009@samp{gdb_get_args} command which partially overlaps with the
32010functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
32011
32012@subsubheading Example
922fbb7b 32013
a2c02241 32014@smallexample
594fe323 32015(gdb)
a2c02241
NR
32016-stack-list-frames
32017^done,
32018stack=[
32019frame=@{level="0",addr="0x00010734",func="callee4",
32020file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32021fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32022arch="i386:x86_64"@},
a2c02241
NR
32023frame=@{level="1",addr="0x0001076c",func="callee3",
32024file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32025fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32026arch="i386:x86_64"@},
a2c02241
NR
32027frame=@{level="2",addr="0x0001078c",func="callee2",
32028file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32029fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32030arch="i386:x86_64"@},
a2c02241
NR
32031frame=@{level="3",addr="0x000107b4",func="callee1",
32032file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32033fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32034arch="i386:x86_64"@},
a2c02241
NR
32035frame=@{level="4",addr="0x000107e0",func="main",
32036file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32037fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32038arch="i386:x86_64"@}]
594fe323 32039(gdb)
a2c02241
NR
32040-stack-list-arguments 0
32041^done,
32042stack-args=[
32043frame=@{level="0",args=[]@},
32044frame=@{level="1",args=[name="strarg"]@},
32045frame=@{level="2",args=[name="intarg",name="strarg"]@},
32046frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32047frame=@{level="4",args=[]@}]
594fe323 32048(gdb)
a2c02241
NR
32049-stack-list-arguments 1
32050^done,
32051stack-args=[
32052frame=@{level="0",args=[]@},
32053frame=@{level="1",
32054 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32055frame=@{level="2",args=[
32056@{name="intarg",value="2"@},
32057@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32058@{frame=@{level="3",args=[
32059@{name="intarg",value="2"@},
32060@{name="strarg",value="0x11940 \"A string argument.\""@},
32061@{name="fltarg",value="3.5"@}]@},
32062frame=@{level="4",args=[]@}]
594fe323 32063(gdb)
a2c02241
NR
32064-stack-list-arguments 0 2 2
32065^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 32066(gdb)
a2c02241
NR
32067-stack-list-arguments 1 2 2
32068^done,stack-args=[frame=@{level="2",
32069args=[@{name="intarg",value="2"@},
32070@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 32071(gdb)
a2c02241
NR
32072@end smallexample
32073
32074@c @subheading -stack-list-exception-handlers
922fbb7b 32075
a2c02241 32076
1e611234 32077@anchor{-stack-list-frames}
a2c02241
NR
32078@subheading The @code{-stack-list-frames} Command
32079@findex -stack-list-frames
1abaf70c
BR
32080
32081@subsubheading Synopsis
32082
32083@smallexample
1e611234 32084 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
32085@end smallexample
32086
a2c02241
NR
32087List the frames currently on the stack. For each frame it displays the
32088following info:
32089
32090@table @samp
32091@item @var{level}
d3e8051b 32092The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
32093@item @var{addr}
32094The @code{$pc} value for that frame.
32095@item @var{func}
32096Function name.
32097@item @var{file}
32098File name of the source file where the function lives.
7d288aaa
TT
32099@item @var{fullname}
32100The full file name of the source file where the function lives.
a2c02241
NR
32101@item @var{line}
32102Line number corresponding to the @code{$pc}.
7d288aaa
TT
32103@item @var{from}
32104The shared library where this function is defined. This is only given
32105if the frame's function is not known.
6d52907e
JV
32106@item @var{arch}
32107Frame's architecture.
a2c02241
NR
32108@end table
32109
32110If invoked without arguments, this command prints a backtrace for the
32111whole stack. If given two integer arguments, it shows the frames whose
32112levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
32113are equal, it shows the single frame at the corresponding level. It is
32114an error if @var{low-frame} is larger than the actual number of
a5451f4e 32115frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
32116actual number of frames, in which case only existing frames will be
32117returned. If the option @code{--no-frame-filters} is supplied, then
32118Python frame filters will not be executed.
1abaf70c
BR
32119
32120@subsubheading @value{GDBN} Command
32121
a2c02241 32122The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
32123
32124@subsubheading Example
32125
a2c02241
NR
32126Full stack backtrace:
32127
1abaf70c 32128@smallexample
594fe323 32129(gdb)
a2c02241
NR
32130-stack-list-frames
32131^done,stack=
32132[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
32133 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32134 arch="i386:x86_64"@},
a2c02241 32135frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
32136 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32137 arch="i386:x86_64"@},
a2c02241 32138frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
32139 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32140 arch="i386:x86_64"@},
a2c02241 32141frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32142 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32143 arch="i386:x86_64"@},
a2c02241 32144frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32145 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32146 arch="i386:x86_64"@},
a2c02241 32147frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32148 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32149 arch="i386:x86_64"@},
a2c02241 32150frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
32151 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32152 arch="i386:x86_64"@},
a2c02241 32153frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
32154 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32155 arch="i386:x86_64"@},
a2c02241 32156frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
32157 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32158 arch="i386:x86_64"@},
a2c02241 32159frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
32160 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32161 arch="i386:x86_64"@},
a2c02241 32162frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
32163 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32164 arch="i386:x86_64"@},
a2c02241 32165frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
32166 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32167 arch="i386:x86_64"@}]
594fe323 32168(gdb)
1abaf70c
BR
32169@end smallexample
32170
a2c02241 32171Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 32172
a2c02241 32173@smallexample
594fe323 32174(gdb)
a2c02241
NR
32175-stack-list-frames 3 5
32176^done,stack=
32177[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32178 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32179 arch="i386:x86_64"@},
a2c02241 32180frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32181 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32182 arch="i386:x86_64"@},
a2c02241 32183frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32184 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32185 arch="i386:x86_64"@}]
594fe323 32186(gdb)
a2c02241 32187@end smallexample
922fbb7b 32188
a2c02241 32189Show a single frame:
922fbb7b
AC
32190
32191@smallexample
594fe323 32192(gdb)
a2c02241
NR
32193-stack-list-frames 3 3
32194^done,stack=
32195[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32196 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32197 arch="i386:x86_64"@}]
594fe323 32198(gdb)
922fbb7b
AC
32199@end smallexample
32200
922fbb7b 32201
a2c02241
NR
32202@subheading The @code{-stack-list-locals} Command
32203@findex -stack-list-locals
1e611234 32204@anchor{-stack-list-locals}
57c22c6c 32205
a2c02241 32206@subsubheading Synopsis
922fbb7b
AC
32207
32208@smallexample
6211c335 32209 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
32210@end smallexample
32211
a2c02241
NR
32212Display the local variable names for the selected frame. If
32213@var{print-values} is 0 or @code{--no-values}, print only the names of
32214the variables; if it is 1 or @code{--all-values}, print also their
32215values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32216type and value for simple data types, and the name and type for arrays,
a2c02241
NR
32217structures and unions. In this last case, a frontend can immediately
32218display the value of simple data types and create variable objects for
d3e8051b 32219other data types when the user wishes to explore their values in
1e611234
PM
32220more detail. If the option @code{--no-frame-filters} is supplied, then
32221Python frame filters will not be executed.
922fbb7b 32222
6211c335
YQ
32223If the @code{--skip-unavailable} option is specified, local variables
32224that are not available are not listed. Partially available local
32225variables are still displayed, however.
32226
b3372f91
VP
32227This command is deprecated in favor of the
32228@samp{-stack-list-variables} command.
32229
922fbb7b
AC
32230@subsubheading @value{GDBN} Command
32231
a2c02241 32232@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
32233
32234@subsubheading Example
922fbb7b
AC
32235
32236@smallexample
594fe323 32237(gdb)
a2c02241
NR
32238-stack-list-locals 0
32239^done,locals=[name="A",name="B",name="C"]
594fe323 32240(gdb)
a2c02241
NR
32241-stack-list-locals --all-values
32242^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32243 @{name="C",value="@{1, 2, 3@}"@}]
32244-stack-list-locals --simple-values
32245^done,locals=[@{name="A",type="int",value="1"@},
32246 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 32247(gdb)
922fbb7b
AC
32248@end smallexample
32249
1e611234 32250@anchor{-stack-list-variables}
b3372f91
VP
32251@subheading The @code{-stack-list-variables} Command
32252@findex -stack-list-variables
32253
32254@subsubheading Synopsis
32255
32256@smallexample
6211c335 32257 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
32258@end smallexample
32259
32260Display the names of local variables and function arguments for the selected frame. If
32261@var{print-values} is 0 or @code{--no-values}, print only the names of
32262the variables; if it is 1 or @code{--all-values}, print also their
32263values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32264type and value for simple data types, and the name and type for arrays,
1e611234
PM
32265structures and unions. If the option @code{--no-frame-filters} is
32266supplied, then Python frame filters will not be executed.
b3372f91 32267
6211c335
YQ
32268If the @code{--skip-unavailable} option is specified, local variables
32269and arguments that are not available are not listed. Partially
32270available arguments and local variables are still displayed, however.
32271
b3372f91
VP
32272@subsubheading Example
32273
32274@smallexample
32275(gdb)
32276-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32277^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32278(gdb)
32279@end smallexample
32280
922fbb7b 32281
a2c02241
NR
32282@subheading The @code{-stack-select-frame} Command
32283@findex -stack-select-frame
922fbb7b
AC
32284
32285@subsubheading Synopsis
32286
32287@smallexample
a2c02241 32288 -stack-select-frame @var{framenum}
922fbb7b
AC
32289@end smallexample
32290
a2c02241
NR
32291Change the selected frame. Select a different frame @var{framenum} on
32292the stack.
922fbb7b 32293
c3b108f7
VP
32294This command in deprecated in favor of passing the @samp{--frame}
32295option to every command.
32296
922fbb7b
AC
32297@subsubheading @value{GDBN} Command
32298
a2c02241
NR
32299The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32300@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32301
32302@subsubheading Example
32303
32304@smallexample
594fe323 32305(gdb)
a2c02241 32306-stack-select-frame 2
922fbb7b 32307^done
594fe323 32308(gdb)
922fbb7b
AC
32309@end smallexample
32310
32311@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32312@node GDB/MI Variable Objects
32313@section @sc{gdb/mi} Variable Objects
922fbb7b 32314
a1b5960f 32315@ignore
922fbb7b 32316
a2c02241 32317@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32318
a2c02241
NR
32319For the implementation of a variable debugger window (locals, watched
32320expressions, etc.), we are proposing the adaptation of the existing code
32321used by @code{Insight}.
922fbb7b 32322
a2c02241 32323The two main reasons for that are:
922fbb7b 32324
a2c02241
NR
32325@enumerate 1
32326@item
32327It has been proven in practice (it is already on its second generation).
922fbb7b 32328
a2c02241
NR
32329@item
32330It will shorten development time (needless to say how important it is
32331now).
32332@end enumerate
922fbb7b 32333
a2c02241
NR
32334The original interface was designed to be used by Tcl code, so it was
32335slightly changed so it could be used through @sc{gdb/mi}. This section
32336describes the @sc{gdb/mi} operations that will be available and gives some
32337hints about their use.
922fbb7b 32338
a2c02241
NR
32339@emph{Note}: In addition to the set of operations described here, we
32340expect the @sc{gui} implementation of a variable window to require, at
32341least, the following operations:
922fbb7b 32342
a2c02241
NR
32343@itemize @bullet
32344@item @code{-gdb-show} @code{output-radix}
32345@item @code{-stack-list-arguments}
32346@item @code{-stack-list-locals}
32347@item @code{-stack-select-frame}
32348@end itemize
922fbb7b 32349
a1b5960f
VP
32350@end ignore
32351
c8b2f53c 32352@subheading Introduction to Variable Objects
922fbb7b 32353
a2c02241 32354@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32355
32356Variable objects are "object-oriented" MI interface for examining and
32357changing values of expressions. Unlike some other MI interfaces that
32358work with expressions, variable objects are specifically designed for
32359simple and efficient presentation in the frontend. A variable object
32360is identified by string name. When a variable object is created, the
32361frontend specifies the expression for that variable object. The
32362expression can be a simple variable, or it can be an arbitrary complex
32363expression, and can even involve CPU registers. After creating a
32364variable object, the frontend can invoke other variable object
32365operations---for example to obtain or change the value of a variable
32366object, or to change display format.
32367
32368Variable objects have hierarchical tree structure. Any variable object
32369that corresponds to a composite type, such as structure in C, has
32370a number of child variable objects, for example corresponding to each
32371element of a structure. A child variable object can itself have
32372children, recursively. Recursion ends when we reach
25d5ea92
VP
32373leaf variable objects, which always have built-in types. Child variable
32374objects are created only by explicit request, so if a frontend
32375is not interested in the children of a particular variable object, no
32376child will be created.
c8b2f53c
VP
32377
32378For a leaf variable object it is possible to obtain its value as a
32379string, or set the value from a string. String value can be also
32380obtained for a non-leaf variable object, but it's generally a string
32381that only indicates the type of the object, and does not list its
32382contents. Assignment to a non-leaf variable object is not allowed.
32383
32384A frontend does not need to read the values of all variable objects each time
32385the program stops. Instead, MI provides an update command that lists all
32386variable objects whose values has changed since the last update
32387operation. This considerably reduces the amount of data that must
25d5ea92
VP
32388be transferred to the frontend. As noted above, children variable
32389objects are created on demand, and only leaf variable objects have a
32390real value. As result, gdb will read target memory only for leaf
32391variables that frontend has created.
32392
32393The automatic update is not always desirable. For example, a frontend
32394might want to keep a value of some expression for future reference,
32395and never update it. For another example, fetching memory is
32396relatively slow for embedded targets, so a frontend might want
32397to disable automatic update for the variables that are either not
32398visible on the screen, or ``closed''. This is possible using so
32399called ``frozen variable objects''. Such variable objects are never
32400implicitly updated.
922fbb7b 32401
c3b108f7
VP
32402Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32403fixed variable object, the expression is parsed when the variable
32404object is created, including associating identifiers to specific
32405variables. The meaning of expression never changes. For a floating
32406variable object the values of variables whose names appear in the
32407expressions are re-evaluated every time in the context of the current
32408frame. Consider this example:
32409
32410@smallexample
32411void do_work(...)
32412@{
32413 struct work_state state;
32414
32415 if (...)
32416 do_work(...);
32417@}
32418@end smallexample
32419
32420If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32421this function, and we enter the recursive call, the variable
c3b108f7
VP
32422object will report the value of @code{state} in the top-level
32423@code{do_work} invocation. On the other hand, a floating variable
32424object will report the value of @code{state} in the current frame.
32425
32426If an expression specified when creating a fixed variable object
32427refers to a local variable, the variable object becomes bound to the
32428thread and frame in which the variable object is created. When such
32429variable object is updated, @value{GDBN} makes sure that the
32430thread/frame combination the variable object is bound to still exists,
32431and re-evaluates the variable object in context of that thread/frame.
32432
a2c02241
NR
32433The following is the complete set of @sc{gdb/mi} operations defined to
32434access this functionality:
922fbb7b 32435
a2c02241
NR
32436@multitable @columnfractions .4 .6
32437@item @strong{Operation}
32438@tab @strong{Description}
922fbb7b 32439
0cc7d26f
TT
32440@item @code{-enable-pretty-printing}
32441@tab enable Python-based pretty-printing
a2c02241
NR
32442@item @code{-var-create}
32443@tab create a variable object
32444@item @code{-var-delete}
22d8a470 32445@tab delete the variable object and/or its children
a2c02241
NR
32446@item @code{-var-set-format}
32447@tab set the display format of this variable
32448@item @code{-var-show-format}
32449@tab show the display format of this variable
32450@item @code{-var-info-num-children}
32451@tab tells how many children this object has
32452@item @code{-var-list-children}
32453@tab return a list of the object's children
32454@item @code{-var-info-type}
32455@tab show the type of this variable object
32456@item @code{-var-info-expression}
02142340
VP
32457@tab print parent-relative expression that this variable object represents
32458@item @code{-var-info-path-expression}
32459@tab print full expression that this variable object represents
a2c02241
NR
32460@item @code{-var-show-attributes}
32461@tab is this variable editable? does it exist here?
32462@item @code{-var-evaluate-expression}
32463@tab get the value of this variable
32464@item @code{-var-assign}
32465@tab set the value of this variable
32466@item @code{-var-update}
32467@tab update the variable and its children
25d5ea92 32468@item @code{-var-set-frozen}
6b92c0d3 32469@tab set frozenness attribute
0cc7d26f
TT
32470@item @code{-var-set-update-range}
32471@tab set range of children to display on update
a2c02241 32472@end multitable
922fbb7b 32473
a2c02241
NR
32474In the next subsection we describe each operation in detail and suggest
32475how it can be used.
922fbb7b 32476
a2c02241 32477@subheading Description And Use of Operations on Variable Objects
922fbb7b 32478
0cc7d26f
TT
32479@subheading The @code{-enable-pretty-printing} Command
32480@findex -enable-pretty-printing
32481
32482@smallexample
32483-enable-pretty-printing
32484@end smallexample
32485
32486@value{GDBN} allows Python-based visualizers to affect the output of the
32487MI variable object commands. However, because there was no way to
32488implement this in a fully backward-compatible way, a front end must
32489request that this functionality be enabled.
32490
32491Once enabled, this feature cannot be disabled.
32492
32493Note that if Python support has not been compiled into @value{GDBN},
32494this command will still succeed (and do nothing).
32495
f43030c4
TT
32496This feature is currently (as of @value{GDBN} 7.0) experimental, and
32497may work differently in future versions of @value{GDBN}.
32498
a2c02241
NR
32499@subheading The @code{-var-create} Command
32500@findex -var-create
ef21caaf 32501
a2c02241 32502@subsubheading Synopsis
ef21caaf 32503
a2c02241
NR
32504@smallexample
32505 -var-create @{@var{name} | "-"@}
c3b108f7 32506 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32507@end smallexample
32508
32509This operation creates a variable object, which allows the monitoring of
32510a variable, the result of an expression, a memory cell or a CPU
32511register.
ef21caaf 32512
a2c02241
NR
32513The @var{name} parameter is the string by which the object can be
32514referenced. It must be unique. If @samp{-} is specified, the varobj
32515system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32516unique provided that one does not specify @var{name} of that format.
a2c02241 32517The command fails if a duplicate name is found.
ef21caaf 32518
a2c02241
NR
32519The frame under which the expression should be evaluated can be
32520specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32521frame should be used. A @samp{@@} indicates that a floating variable
32522object must be created.
922fbb7b 32523
a2c02241
NR
32524@var{expression} is any expression valid on the current language set (must not
32525begin with a @samp{*}), or one of the following:
922fbb7b 32526
a2c02241
NR
32527@itemize @bullet
32528@item
32529@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32530
a2c02241
NR
32531@item
32532@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32533
a2c02241
NR
32534@item
32535@samp{$@var{regname}} --- a CPU register name
32536@end itemize
922fbb7b 32537
0cc7d26f
TT
32538@cindex dynamic varobj
32539A varobj's contents may be provided by a Python-based pretty-printer. In this
32540case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32541have slightly different semantics in some cases. If the
32542@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32543will never create a dynamic varobj. This ensures backward
32544compatibility for existing clients.
32545
a2c02241 32546@subsubheading Result
922fbb7b 32547
0cc7d26f
TT
32548This operation returns attributes of the newly-created varobj. These
32549are:
32550
32551@table @samp
32552@item name
32553The name of the varobj.
32554
32555@item numchild
32556The number of children of the varobj. This number is not necessarily
32557reliable for a dynamic varobj. Instead, you must examine the
32558@samp{has_more} attribute.
32559
32560@item value
32561The varobj's scalar value. For a varobj whose type is some sort of
32562aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32563will not be interesting.
32564
32565@item type
32566The varobj's type. This is a string representation of the type, as
8264ba82
AG
32567would be printed by the @value{GDBN} CLI. If @samp{print object}
32568(@pxref{Print Settings, set print object}) is set to @code{on}, the
32569@emph{actual} (derived) type of the object is shown rather than the
32570@emph{declared} one.
0cc7d26f
TT
32571
32572@item thread-id
32573If a variable object is bound to a specific thread, then this is the
5d5658a1 32574thread's global identifier.
0cc7d26f
TT
32575
32576@item has_more
32577For a dynamic varobj, this indicates whether there appear to be any
32578children available. For a non-dynamic varobj, this will be 0.
32579
32580@item dynamic
32581This attribute will be present and have the value @samp{1} if the
32582varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32583then this attribute will not be present.
32584
32585@item displayhint
32586A dynamic varobj can supply a display hint to the front end. The
32587value comes directly from the Python pretty-printer object's
4c374409 32588@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32589@end table
32590
32591Typical output will look like this:
922fbb7b
AC
32592
32593@smallexample
0cc7d26f
TT
32594 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32595 has_more="@var{has_more}"
dcaaae04
NR
32596@end smallexample
32597
a2c02241
NR
32598
32599@subheading The @code{-var-delete} Command
32600@findex -var-delete
922fbb7b
AC
32601
32602@subsubheading Synopsis
32603
32604@smallexample
22d8a470 32605 -var-delete [ -c ] @var{name}
922fbb7b
AC
32606@end smallexample
32607
a2c02241 32608Deletes a previously created variable object and all of its children.
22d8a470 32609With the @samp{-c} option, just deletes the children.
922fbb7b 32610
a2c02241 32611Returns an error if the object @var{name} is not found.
922fbb7b 32612
922fbb7b 32613
a2c02241
NR
32614@subheading The @code{-var-set-format} Command
32615@findex -var-set-format
922fbb7b 32616
a2c02241 32617@subsubheading Synopsis
922fbb7b
AC
32618
32619@smallexample
a2c02241 32620 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32621@end smallexample
32622
a2c02241
NR
32623Sets the output format for the value of the object @var{name} to be
32624@var{format-spec}.
32625
de051565 32626@anchor{-var-set-format}
a2c02241
NR
32627The syntax for the @var{format-spec} is as follows:
32628
32629@smallexample
32630 @var{format-spec} @expansion{}
1c35a88f 32631 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32632@end smallexample
32633
c8b2f53c
VP
32634The natural format is the default format choosen automatically
32635based on the variable type (like decimal for an @code{int}, hex
32636for pointers, etc.).
32637
1c35a88f
LM
32638The zero-hexadecimal format has a representation similar to hexadecimal
32639but with padding zeroes to the left of the value. For example, a 32-bit
32640hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32641zero-hexadecimal format.
32642
c8b2f53c
VP
32643For a variable with children, the format is set only on the
32644variable itself, and the children are not affected.
a2c02241
NR
32645
32646@subheading The @code{-var-show-format} Command
32647@findex -var-show-format
922fbb7b
AC
32648
32649@subsubheading Synopsis
32650
32651@smallexample
a2c02241 32652 -var-show-format @var{name}
922fbb7b
AC
32653@end smallexample
32654
a2c02241 32655Returns the format used to display the value of the object @var{name}.
922fbb7b 32656
a2c02241
NR
32657@smallexample
32658 @var{format} @expansion{}
32659 @var{format-spec}
32660@end smallexample
922fbb7b 32661
922fbb7b 32662
a2c02241
NR
32663@subheading The @code{-var-info-num-children} Command
32664@findex -var-info-num-children
32665
32666@subsubheading Synopsis
32667
32668@smallexample
32669 -var-info-num-children @var{name}
32670@end smallexample
32671
32672Returns the number of children of a variable object @var{name}:
32673
32674@smallexample
32675 numchild=@var{n}
32676@end smallexample
32677
0cc7d26f
TT
32678Note that this number is not completely reliable for a dynamic varobj.
32679It will return the current number of children, but more children may
32680be available.
32681
a2c02241
NR
32682
32683@subheading The @code{-var-list-children} Command
32684@findex -var-list-children
32685
32686@subsubheading Synopsis
32687
32688@smallexample
0cc7d26f 32689 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32690@end smallexample
b569d230 32691@anchor{-var-list-children}
a2c02241
NR
32692
32693Return a list of the children of the specified variable object and
32694create variable objects for them, if they do not already exist. With
f5011d11 32695a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32696@code{--no-values}, print only the names of the variables; if
32697@var{print-values} is 1 or @code{--all-values}, also print their
32698values; and if it is 2 or @code{--simple-values} print the name and
32699value for simple data types and just the name for arrays, structures
32700and unions.
922fbb7b 32701
0cc7d26f
TT
32702@var{from} and @var{to}, if specified, indicate the range of children
32703to report. If @var{from} or @var{to} is less than zero, the range is
32704reset and all children will be reported. Otherwise, children starting
32705at @var{from} (zero-based) and up to and excluding @var{to} will be
32706reported.
32707
32708If a child range is requested, it will only affect the current call to
32709@code{-var-list-children}, but not future calls to @code{-var-update}.
32710For this, you must instead use @code{-var-set-update-range}. The
32711intent of this approach is to enable a front end to implement any
32712update approach it likes; for example, scrolling a view may cause the
32713front end to request more children with @code{-var-list-children}, and
32714then the front end could call @code{-var-set-update-range} with a
32715different range to ensure that future updates are restricted to just
32716the visible items.
32717
b569d230
EZ
32718For each child the following results are returned:
32719
32720@table @var
32721
32722@item name
32723Name of the variable object created for this child.
32724
32725@item exp
32726The expression to be shown to the user by the front end to designate this child.
32727For example this may be the name of a structure member.
32728
0cc7d26f
TT
32729For a dynamic varobj, this value cannot be used to form an
32730expression. There is no way to do this at all with a dynamic varobj.
32731
b569d230
EZ
32732For C/C@t{++} structures there are several pseudo children returned to
32733designate access qualifiers. For these pseudo children @var{exp} is
32734@samp{public}, @samp{private}, or @samp{protected}. In this case the
32735type and value are not present.
32736
0cc7d26f
TT
32737A dynamic varobj will not report the access qualifying
32738pseudo-children, regardless of the language. This information is not
32739available at all with a dynamic varobj.
32740
b569d230 32741@item numchild
0cc7d26f
TT
32742Number of children this child has. For a dynamic varobj, this will be
327430.
b569d230
EZ
32744
32745@item type
8264ba82
AG
32746The type of the child. If @samp{print object}
32747(@pxref{Print Settings, set print object}) is set to @code{on}, the
32748@emph{actual} (derived) type of the object is shown rather than the
32749@emph{declared} one.
b569d230
EZ
32750
32751@item value
32752If values were requested, this is the value.
32753
32754@item thread-id
5d5658a1
PA
32755If this variable object is associated with a thread, this is the
32756thread's global thread id. Otherwise this result is not present.
b569d230
EZ
32757
32758@item frozen
32759If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 32760
9df9dbe0
YQ
32761@item displayhint
32762A dynamic varobj can supply a display hint to the front end. The
32763value comes directly from the Python pretty-printer object's
32764@code{display_hint} method. @xref{Pretty Printing API}.
32765
c78feb39
YQ
32766@item dynamic
32767This attribute will be present and have the value @samp{1} if the
32768varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32769then this attribute will not be present.
32770
b569d230
EZ
32771@end table
32772
0cc7d26f
TT
32773The result may have its own attributes:
32774
32775@table @samp
32776@item displayhint
32777A dynamic varobj can supply a display hint to the front end. The
32778value comes directly from the Python pretty-printer object's
4c374409 32779@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32780
32781@item has_more
32782This is an integer attribute which is nonzero if there are children
32783remaining after the end of the selected range.
32784@end table
32785
922fbb7b
AC
32786@subsubheading Example
32787
32788@smallexample
594fe323 32789(gdb)
a2c02241 32790 -var-list-children n
b569d230 32791 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32792 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 32793(gdb)
a2c02241 32794 -var-list-children --all-values n
b569d230 32795 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32796 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
32797@end smallexample
32798
922fbb7b 32799
a2c02241
NR
32800@subheading The @code{-var-info-type} Command
32801@findex -var-info-type
922fbb7b 32802
a2c02241
NR
32803@subsubheading Synopsis
32804
32805@smallexample
32806 -var-info-type @var{name}
32807@end smallexample
32808
32809Returns the type of the specified variable @var{name}. The type is
32810returned as a string in the same format as it is output by the
32811@value{GDBN} CLI:
32812
32813@smallexample
32814 type=@var{typename}
32815@end smallexample
32816
32817
32818@subheading The @code{-var-info-expression} Command
32819@findex -var-info-expression
922fbb7b
AC
32820
32821@subsubheading Synopsis
32822
32823@smallexample
a2c02241 32824 -var-info-expression @var{name}
922fbb7b
AC
32825@end smallexample
32826
02142340
VP
32827Returns a string that is suitable for presenting this
32828variable object in user interface. The string is generally
32829not valid expression in the current language, and cannot be evaluated.
32830
32831For example, if @code{a} is an array, and variable object
32832@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 32833
a2c02241 32834@smallexample
02142340
VP
32835(gdb) -var-info-expression A.1
32836^done,lang="C",exp="1"
a2c02241 32837@end smallexample
922fbb7b 32838
a2c02241 32839@noindent
fa4d0c40
YQ
32840Here, the value of @code{lang} is the language name, which can be
32841found in @ref{Supported Languages}.
02142340
VP
32842
32843Note that the output of the @code{-var-list-children} command also
32844includes those expressions, so the @code{-var-info-expression} command
32845is of limited use.
32846
32847@subheading The @code{-var-info-path-expression} Command
32848@findex -var-info-path-expression
32849
32850@subsubheading Synopsis
32851
32852@smallexample
32853 -var-info-path-expression @var{name}
32854@end smallexample
32855
32856Returns an expression that can be evaluated in the current
32857context and will yield the same value that a variable object has.
32858Compare this with the @code{-var-info-expression} command, which
32859result can be used only for UI presentation. Typical use of
32860the @code{-var-info-path-expression} command is creating a
32861watchpoint from a variable object.
32862
0cc7d26f
TT
32863This command is currently not valid for children of a dynamic varobj,
32864and will give an error when invoked on one.
32865
02142340
VP
32866For example, suppose @code{C} is a C@t{++} class, derived from class
32867@code{Base}, and that the @code{Base} class has a member called
32868@code{m_size}. Assume a variable @code{c} is has the type of
32869@code{C} and a variable object @code{C} was created for variable
32870@code{c}. Then, we'll get this output:
32871@smallexample
32872(gdb) -var-info-path-expression C.Base.public.m_size
32873^done,path_expr=((Base)c).m_size)
32874@end smallexample
922fbb7b 32875
a2c02241
NR
32876@subheading The @code{-var-show-attributes} Command
32877@findex -var-show-attributes
922fbb7b 32878
a2c02241 32879@subsubheading Synopsis
922fbb7b 32880
a2c02241
NR
32881@smallexample
32882 -var-show-attributes @var{name}
32883@end smallexample
922fbb7b 32884
a2c02241 32885List attributes of the specified variable object @var{name}:
922fbb7b
AC
32886
32887@smallexample
a2c02241 32888 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
32889@end smallexample
32890
a2c02241
NR
32891@noindent
32892where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32893
32894@subheading The @code{-var-evaluate-expression} Command
32895@findex -var-evaluate-expression
32896
32897@subsubheading Synopsis
32898
32899@smallexample
de051565 32900 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
32901@end smallexample
32902
32903Evaluates the expression that is represented by the specified variable
de051565
MK
32904object and returns its value as a string. The format of the string
32905can be specified with the @samp{-f} option. The possible values of
32906this option are the same as for @code{-var-set-format}
32907(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32908the current display format will be used. The current display format
32909can be changed using the @code{-var-set-format} command.
a2c02241
NR
32910
32911@smallexample
32912 value=@var{value}
32913@end smallexample
32914
32915Note that one must invoke @code{-var-list-children} for a variable
32916before the value of a child variable can be evaluated.
32917
32918@subheading The @code{-var-assign} Command
32919@findex -var-assign
32920
32921@subsubheading Synopsis
32922
32923@smallexample
32924 -var-assign @var{name} @var{expression}
32925@end smallexample
32926
32927Assigns the value of @var{expression} to the variable object specified
32928by @var{name}. The object must be @samp{editable}. If the variable's
32929value is altered by the assign, the variable will show up in any
32930subsequent @code{-var-update} list.
32931
32932@subsubheading Example
922fbb7b
AC
32933
32934@smallexample
594fe323 32935(gdb)
a2c02241
NR
32936-var-assign var1 3
32937^done,value="3"
594fe323 32938(gdb)
a2c02241
NR
32939-var-update *
32940^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 32941(gdb)
922fbb7b
AC
32942@end smallexample
32943
a2c02241
NR
32944@subheading The @code{-var-update} Command
32945@findex -var-update
32946
32947@subsubheading Synopsis
32948
32949@smallexample
32950 -var-update [@var{print-values}] @{@var{name} | "*"@}
32951@end smallexample
32952
c8b2f53c
VP
32953Reevaluate the expressions corresponding to the variable object
32954@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
32955list of variable objects whose values have changed; @var{name} must
32956be a root variable object. Here, ``changed'' means that the result of
32957@code{-var-evaluate-expression} before and after the
32958@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
32959object names, all existing variable objects are updated, except
32960for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 32961@var{print-values} determines whether both names and values, or just
de051565 32962names are printed. The possible values of this option are the same
36ece8b3
NR
32963as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32964recommended to use the @samp{--all-values} option, to reduce the
32965number of MI commands needed on each program stop.
c8b2f53c 32966
c3b108f7
VP
32967With the @samp{*} parameter, if a variable object is bound to a
32968currently running thread, it will not be updated, without any
32969diagnostic.
a2c02241 32970
0cc7d26f
TT
32971If @code{-var-set-update-range} was previously used on a varobj, then
32972only the selected range of children will be reported.
922fbb7b 32973
0cc7d26f
TT
32974@code{-var-update} reports all the changed varobjs in a tuple named
32975@samp{changelist}.
32976
32977Each item in the change list is itself a tuple holding:
32978
32979@table @samp
32980@item name
32981The name of the varobj.
32982
32983@item value
32984If values were requested for this update, then this field will be
32985present and will hold the value of the varobj.
922fbb7b 32986
0cc7d26f 32987@item in_scope
9f708cb2 32988@anchor{-var-update}
0cc7d26f 32989This field is a string which may take one of three values:
36ece8b3
NR
32990
32991@table @code
32992@item "true"
32993The variable object's current value is valid.
32994
32995@item "false"
32996The variable object does not currently hold a valid value but it may
32997hold one in the future if its associated expression comes back into
32998scope.
32999
33000@item "invalid"
33001The variable object no longer holds a valid value.
33002This can occur when the executable file being debugged has changed,
33003either through recompilation or by using the @value{GDBN} @code{file}
33004command. The front end should normally choose to delete these variable
33005objects.
33006@end table
33007
33008In the future new values may be added to this list so the front should
33009be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33010
0cc7d26f
TT
33011@item type_changed
33012This is only present if the varobj is still valid. If the type
33013changed, then this will be the string @samp{true}; otherwise it will
33014be @samp{false}.
33015
7191c139
JB
33016When a varobj's type changes, its children are also likely to have
33017become incorrect. Therefore, the varobj's children are automatically
33018deleted when this attribute is @samp{true}. Also, the varobj's update
33019range, when set using the @code{-var-set-update-range} command, is
33020unset.
33021
0cc7d26f
TT
33022@item new_type
33023If the varobj's type changed, then this field will be present and will
33024hold the new type.
33025
33026@item new_num_children
33027For a dynamic varobj, if the number of children changed, or if the
33028type changed, this will be the new number of children.
33029
33030The @samp{numchild} field in other varobj responses is generally not
33031valid for a dynamic varobj -- it will show the number of children that
33032@value{GDBN} knows about, but because dynamic varobjs lazily
33033instantiate their children, this will not reflect the number of
33034children which may be available.
33035
33036The @samp{new_num_children} attribute only reports changes to the
33037number of children known by @value{GDBN}. This is the only way to
33038detect whether an update has removed children (which necessarily can
33039only happen at the end of the update range).
33040
33041@item displayhint
33042The display hint, if any.
33043
33044@item has_more
33045This is an integer value, which will be 1 if there are more children
33046available outside the varobj's update range.
33047
33048@item dynamic
33049This attribute will be present and have the value @samp{1} if the
33050varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33051then this attribute will not be present.
33052
33053@item new_children
33054If new children were added to a dynamic varobj within the selected
33055update range (as set by @code{-var-set-update-range}), then they will
33056be listed in this attribute.
33057@end table
33058
33059@subsubheading Example
33060
33061@smallexample
33062(gdb)
33063-var-assign var1 3
33064^done,value="3"
33065(gdb)
33066-var-update --all-values var1
33067^done,changelist=[@{name="var1",value="3",in_scope="true",
33068type_changed="false"@}]
33069(gdb)
33070@end smallexample
33071
25d5ea92
VP
33072@subheading The @code{-var-set-frozen} Command
33073@findex -var-set-frozen
9f708cb2 33074@anchor{-var-set-frozen}
25d5ea92
VP
33075
33076@subsubheading Synopsis
33077
33078@smallexample
9f708cb2 33079 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
33080@end smallexample
33081
9f708cb2 33082Set the frozenness flag on the variable object @var{name}. The
25d5ea92 33083@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 33084frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 33085frozen, then neither itself, nor any of its children, are
9f708cb2 33086implicitly updated by @code{-var-update} of
25d5ea92
VP
33087a parent variable or by @code{-var-update *}. Only
33088@code{-var-update} of the variable itself will update its value and
33089values of its children. After a variable object is unfrozen, it is
33090implicitly updated by all subsequent @code{-var-update} operations.
33091Unfreezing a variable does not update it, only subsequent
33092@code{-var-update} does.
33093
33094@subsubheading Example
33095
33096@smallexample
33097(gdb)
33098-var-set-frozen V 1
33099^done
33100(gdb)
33101@end smallexample
33102
0cc7d26f
TT
33103@subheading The @code{-var-set-update-range} command
33104@findex -var-set-update-range
33105@anchor{-var-set-update-range}
33106
33107@subsubheading Synopsis
33108
33109@smallexample
33110 -var-set-update-range @var{name} @var{from} @var{to}
33111@end smallexample
33112
33113Set the range of children to be returned by future invocations of
33114@code{-var-update}.
33115
33116@var{from} and @var{to} indicate the range of children to report. If
33117@var{from} or @var{to} is less than zero, the range is reset and all
33118children will be reported. Otherwise, children starting at @var{from}
33119(zero-based) and up to and excluding @var{to} will be reported.
33120
33121@subsubheading Example
33122
33123@smallexample
33124(gdb)
33125-var-set-update-range V 1 2
33126^done
33127@end smallexample
33128
b6313243
TT
33129@subheading The @code{-var-set-visualizer} command
33130@findex -var-set-visualizer
33131@anchor{-var-set-visualizer}
33132
33133@subsubheading Synopsis
33134
33135@smallexample
33136 -var-set-visualizer @var{name} @var{visualizer}
33137@end smallexample
33138
33139Set a visualizer for the variable object @var{name}.
33140
33141@var{visualizer} is the visualizer to use. The special value
33142@samp{None} means to disable any visualizer in use.
33143
33144If not @samp{None}, @var{visualizer} must be a Python expression.
33145This expression must evaluate to a callable object which accepts a
33146single argument. @value{GDBN} will call this object with the value of
33147the varobj @var{name} as an argument (this is done so that the same
33148Python pretty-printing code can be used for both the CLI and MI).
33149When called, this object must return an object which conforms to the
4c374409 33150pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
33151
33152The pre-defined function @code{gdb.default_visualizer} may be used to
33153select a visualizer by following the built-in process
33154(@pxref{Selecting Pretty-Printers}). This is done automatically when
33155a varobj is created, and so ordinarily is not needed.
33156
33157This feature is only available if Python support is enabled. The MI
d192b373 33158command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
33159can be used to check this.
33160
33161@subsubheading Example
33162
33163Resetting the visualizer:
33164
33165@smallexample
33166(gdb)
33167-var-set-visualizer V None
33168^done
33169@end smallexample
33170
33171Reselecting the default (type-based) visualizer:
33172
33173@smallexample
33174(gdb)
33175-var-set-visualizer V gdb.default_visualizer
33176^done
33177@end smallexample
33178
33179Suppose @code{SomeClass} is a visualizer class. A lambda expression
33180can be used to instantiate this class for a varobj:
33181
33182@smallexample
33183(gdb)
33184-var-set-visualizer V "lambda val: SomeClass()"
33185^done
33186@end smallexample
25d5ea92 33187
a2c02241
NR
33188@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33189@node GDB/MI Data Manipulation
33190@section @sc{gdb/mi} Data Manipulation
922fbb7b 33191
a2c02241
NR
33192@cindex data manipulation, in @sc{gdb/mi}
33193@cindex @sc{gdb/mi}, data manipulation
33194This section describes the @sc{gdb/mi} commands that manipulate data:
33195examine memory and registers, evaluate expressions, etc.
33196
a86c90e6
SM
33197For details about what an addressable memory unit is,
33198@pxref{addressable memory unit}.
33199
a2c02241
NR
33200@c REMOVED FROM THE INTERFACE.
33201@c @subheading -data-assign
33202@c Change the value of a program variable. Plenty of side effects.
79a6e687 33203@c @subsubheading GDB Command
a2c02241
NR
33204@c set variable
33205@c @subsubheading Example
33206@c N.A.
33207
33208@subheading The @code{-data-disassemble} Command
33209@findex -data-disassemble
922fbb7b
AC
33210
33211@subsubheading Synopsis
33212
33213@smallexample
a2c02241
NR
33214 -data-disassemble
33215 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 33216 | [ -a @var{addr} ]
a2c02241
NR
33217 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33218 -- @var{mode}
922fbb7b
AC
33219@end smallexample
33220
a2c02241
NR
33221@noindent
33222Where:
33223
33224@table @samp
33225@item @var{start-addr}
33226is the beginning address (or @code{$pc})
33227@item @var{end-addr}
33228is the end address
26fb3983
JV
33229@item @var{addr}
33230is an address anywhere within (or the name of) the function to
33231disassemble. If an address is specified, the whole function
33232surrounding that address will be disassembled. If a name is
33233specified, the whole function with that name will be disassembled.
a2c02241
NR
33234@item @var{filename}
33235is the name of the file to disassemble
33236@item @var{linenum}
33237is the line number to disassemble around
33238@item @var{lines}
d3e8051b 33239is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
33240the whole function will be disassembled, in case no @var{end-addr} is
33241specified. If @var{end-addr} is specified as a non-zero value, and
33242@var{lines} is lower than the number of disassembly lines between
33243@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33244displayed; if @var{lines} is higher than the number of lines between
33245@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33246are displayed.
33247@item @var{mode}
6ff0ba5f
DE
33248is one of:
33249@itemize @bullet
33250@item 0 disassembly only
33251@item 1 mixed source and disassembly (deprecated)
33252@item 2 disassembly with raw opcodes
33253@item 3 mixed source and disassembly with raw opcodes (deprecated)
33254@item 4 mixed source and disassembly
33255@item 5 mixed source and disassembly with raw opcodes
33256@end itemize
33257
33258Modes 1 and 3 are deprecated. The output is ``source centric''
33259which hasn't proved useful in practice.
33260@xref{Machine Code}, for a discussion of the difference between
33261@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
33262@end table
33263
33264@subsubheading Result
33265
ed8a1c2d
AB
33266The result of the @code{-data-disassemble} command will be a list named
33267@samp{asm_insns}, the contents of this list depend on the @var{mode}
33268used with the @code{-data-disassemble} command.
a2c02241 33269
ed8a1c2d
AB
33270For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33271following fields:
33272
33273@table @code
33274@item address
33275The address at which this instruction was disassembled.
33276
33277@item func-name
33278The name of the function this instruction is within.
33279
33280@item offset
33281The decimal offset in bytes from the start of @samp{func-name}.
33282
33283@item inst
33284The text disassembly for this @samp{address}.
33285
33286@item opcodes
6ff0ba5f 33287This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33288bytes for the @samp{inst} field.
33289
33290@end table
33291
6ff0ba5f 33292For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33293@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33294
ed8a1c2d
AB
33295@table @code
33296@item line
33297The line number within @samp{file}.
33298
33299@item file
33300The file name from the compilation unit. This might be an absolute
33301file name or a relative file name depending on the compile command
33302used.
33303
33304@item fullname
f35a17b5
JK
33305Absolute file name of @samp{file}. It is converted to a canonical form
33306using the source file search path
33307(@pxref{Source Path, ,Specifying Source Directories})
33308and after resolving all the symbolic links.
33309
33310If the source file is not found this field will contain the path as
33311present in the debug information.
ed8a1c2d
AB
33312
33313@item line_asm_insn
33314This is a list of tuples containing the disassembly for @samp{line} in
33315@samp{file}. The fields of each tuple are the same as for
33316@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33317@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33318@samp{opcodes}.
33319
33320@end table
33321
33322Note that whatever included in the @samp{inst} field, is not
33323manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33324adjust its format.
922fbb7b
AC
33325
33326@subsubheading @value{GDBN} Command
33327
ed8a1c2d 33328The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33329
33330@subsubheading Example
33331
a2c02241
NR
33332Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33333
922fbb7b 33334@smallexample
594fe323 33335(gdb)
a2c02241
NR
33336-data-disassemble -s $pc -e "$pc + 20" -- 0
33337^done,
33338asm_insns=[
33339@{address="0x000107c0",func-name="main",offset="4",
33340inst="mov 2, %o0"@},
33341@{address="0x000107c4",func-name="main",offset="8",
33342inst="sethi %hi(0x11800), %o2"@},
33343@{address="0x000107c8",func-name="main",offset="12",
33344inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33345@{address="0x000107cc",func-name="main",offset="16",
33346inst="sethi %hi(0x11800), %o2"@},
33347@{address="0x000107d0",func-name="main",offset="20",
33348inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33349(gdb)
a2c02241
NR
33350@end smallexample
33351
33352Disassemble the whole @code{main} function. Line 32 is part of
33353@code{main}.
33354
33355@smallexample
33356-data-disassemble -f basics.c -l 32 -- 0
33357^done,asm_insns=[
33358@{address="0x000107bc",func-name="main",offset="0",
33359inst="save %sp, -112, %sp"@},
33360@{address="0x000107c0",func-name="main",offset="4",
33361inst="mov 2, %o0"@},
33362@{address="0x000107c4",func-name="main",offset="8",
33363inst="sethi %hi(0x11800), %o2"@},
33364[@dots{}]
33365@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33366@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33367(gdb)
922fbb7b
AC
33368@end smallexample
33369
a2c02241 33370Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33371
a2c02241 33372@smallexample
594fe323 33373(gdb)
a2c02241
NR
33374-data-disassemble -f basics.c -l 32 -n 3 -- 0
33375^done,asm_insns=[
33376@{address="0x000107bc",func-name="main",offset="0",
33377inst="save %sp, -112, %sp"@},
33378@{address="0x000107c0",func-name="main",offset="4",
33379inst="mov 2, %o0"@},
33380@{address="0x000107c4",func-name="main",offset="8",
33381inst="sethi %hi(0x11800), %o2"@}]
594fe323 33382(gdb)
a2c02241
NR
33383@end smallexample
33384
33385Disassemble 3 instructions from the start of @code{main} in mixed mode:
33386
33387@smallexample
594fe323 33388(gdb)
a2c02241
NR
33389-data-disassemble -f basics.c -l 32 -n 3 -- 1
33390^done,asm_insns=[
33391src_and_asm_line=@{line="31",
ed8a1c2d
AB
33392file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33393fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33394line_asm_insn=[@{address="0x000107bc",
33395func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33396src_and_asm_line=@{line="32",
ed8a1c2d
AB
33397file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33398fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33399line_asm_insn=[@{address="0x000107c0",
33400func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33401@{address="0x000107c4",func-name="main",offset="8",
33402inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33403(gdb)
a2c02241
NR
33404@end smallexample
33405
33406
33407@subheading The @code{-data-evaluate-expression} Command
33408@findex -data-evaluate-expression
922fbb7b
AC
33409
33410@subsubheading Synopsis
33411
33412@smallexample
a2c02241 33413 -data-evaluate-expression @var{expr}
922fbb7b
AC
33414@end smallexample
33415
a2c02241
NR
33416Evaluate @var{expr} as an expression. The expression could contain an
33417inferior function call. The function call will execute synchronously.
33418If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33419
33420@subsubheading @value{GDBN} Command
33421
a2c02241
NR
33422The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33423@samp{call}. In @code{gdbtk} only, there's a corresponding
33424@samp{gdb_eval} command.
922fbb7b
AC
33425
33426@subsubheading Example
33427
a2c02241
NR
33428In the following example, the numbers that precede the commands are the
33429@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33430Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33431output.
33432
922fbb7b 33433@smallexample
a2c02241
NR
33434211-data-evaluate-expression A
33435211^done,value="1"
594fe323 33436(gdb)
a2c02241
NR
33437311-data-evaluate-expression &A
33438311^done,value="0xefffeb7c"
594fe323 33439(gdb)
a2c02241
NR
33440411-data-evaluate-expression A+3
33441411^done,value="4"
594fe323 33442(gdb)
a2c02241
NR
33443511-data-evaluate-expression "A + 3"
33444511^done,value="4"
594fe323 33445(gdb)
a2c02241 33446@end smallexample
922fbb7b
AC
33447
33448
a2c02241
NR
33449@subheading The @code{-data-list-changed-registers} Command
33450@findex -data-list-changed-registers
922fbb7b
AC
33451
33452@subsubheading Synopsis
33453
33454@smallexample
a2c02241 33455 -data-list-changed-registers
922fbb7b
AC
33456@end smallexample
33457
a2c02241 33458Display a list of the registers that have changed.
922fbb7b
AC
33459
33460@subsubheading @value{GDBN} Command
33461
a2c02241
NR
33462@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33463has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33464
33465@subsubheading Example
922fbb7b 33466
a2c02241 33467On a PPC MBX board:
922fbb7b
AC
33468
33469@smallexample
594fe323 33470(gdb)
a2c02241
NR
33471-exec-continue
33472^running
922fbb7b 33473
594fe323 33474(gdb)
a47ec5fe
AR
33475*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33476func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33477line="5",arch="powerpc"@}
594fe323 33478(gdb)
a2c02241
NR
33479-data-list-changed-registers
33480^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33481"10","11","13","14","15","16","17","18","19","20","21","22","23",
33482"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33483(gdb)
a2c02241 33484@end smallexample
922fbb7b
AC
33485
33486
a2c02241
NR
33487@subheading The @code{-data-list-register-names} Command
33488@findex -data-list-register-names
922fbb7b
AC
33489
33490@subsubheading Synopsis
33491
33492@smallexample
a2c02241 33493 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33494@end smallexample
33495
a2c02241
NR
33496Show a list of register names for the current target. If no arguments
33497are given, it shows a list of the names of all the registers. If
33498integer numbers are given as arguments, it will print a list of the
33499names of the registers corresponding to the arguments. To ensure
33500consistency between a register name and its number, the output list may
33501include empty register names.
922fbb7b
AC
33502
33503@subsubheading @value{GDBN} Command
33504
a2c02241
NR
33505@value{GDBN} does not have a command which corresponds to
33506@samp{-data-list-register-names}. In @code{gdbtk} there is a
33507corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33508
33509@subsubheading Example
922fbb7b 33510
a2c02241
NR
33511For the PPC MBX board:
33512@smallexample
594fe323 33513(gdb)
a2c02241
NR
33514-data-list-register-names
33515^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33516"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33517"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33518"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33519"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33520"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33521"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33522(gdb)
a2c02241
NR
33523-data-list-register-names 1 2 3
33524^done,register-names=["r1","r2","r3"]
594fe323 33525(gdb)
a2c02241 33526@end smallexample
922fbb7b 33527
a2c02241
NR
33528@subheading The @code{-data-list-register-values} Command
33529@findex -data-list-register-values
922fbb7b
AC
33530
33531@subsubheading Synopsis
33532
33533@smallexample
c898adb7
YQ
33534 -data-list-register-values
33535 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33536@end smallexample
33537
697aa1b7
EZ
33538Display the registers' contents. The format according to which the
33539registers' contents are to be returned is given by @var{fmt}, followed
33540by an optional list of numbers specifying the registers to display. A
33541missing list of numbers indicates that the contents of all the
33542registers must be returned. The @code{--skip-unavailable} option
33543indicates that only the available registers are to be returned.
a2c02241
NR
33544
33545Allowed formats for @var{fmt} are:
33546
33547@table @code
33548@item x
33549Hexadecimal
33550@item o
33551Octal
33552@item t
33553Binary
33554@item d
33555Decimal
33556@item r
33557Raw
33558@item N
33559Natural
33560@end table
922fbb7b
AC
33561
33562@subsubheading @value{GDBN} Command
33563
a2c02241
NR
33564The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33565all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33566
33567@subsubheading Example
922fbb7b 33568
a2c02241
NR
33569For a PPC MBX board (note: line breaks are for readability only, they
33570don't appear in the actual output):
33571
33572@smallexample
594fe323 33573(gdb)
a2c02241
NR
33574-data-list-register-values r 64 65
33575^done,register-values=[@{number="64",value="0xfe00a300"@},
33576@{number="65",value="0x00029002"@}]
594fe323 33577(gdb)
a2c02241
NR
33578-data-list-register-values x
33579^done,register-values=[@{number="0",value="0xfe0043c8"@},
33580@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33581@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33582@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33583@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33584@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33585@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33586@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33587@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33588@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33589@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33590@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33591@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33592@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33593@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33594@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33595@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33596@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33597@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33598@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33599@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33600@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33601@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33602@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33603@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33604@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33605@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33606@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33607@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33608@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33609@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33610@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33611@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33612@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33613@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33614@{number="69",value="0x20002b03"@}]
594fe323 33615(gdb)
a2c02241 33616@end smallexample
922fbb7b 33617
a2c02241
NR
33618
33619@subheading The @code{-data-read-memory} Command
33620@findex -data-read-memory
922fbb7b 33621
8dedea02
VP
33622This command is deprecated, use @code{-data-read-memory-bytes} instead.
33623
922fbb7b
AC
33624@subsubheading Synopsis
33625
33626@smallexample
a2c02241
NR
33627 -data-read-memory [ -o @var{byte-offset} ]
33628 @var{address} @var{word-format} @var{word-size}
33629 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33630@end smallexample
33631
a2c02241
NR
33632@noindent
33633where:
922fbb7b 33634
a2c02241
NR
33635@table @samp
33636@item @var{address}
33637An expression specifying the address of the first memory word to be
33638read. Complex expressions containing embedded white space should be
33639quoted using the C convention.
922fbb7b 33640
a2c02241
NR
33641@item @var{word-format}
33642The format to be used to print the memory words. The notation is the
33643same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33644,Output Formats}).
922fbb7b 33645
a2c02241
NR
33646@item @var{word-size}
33647The size of each memory word in bytes.
922fbb7b 33648
a2c02241
NR
33649@item @var{nr-rows}
33650The number of rows in the output table.
922fbb7b 33651
a2c02241
NR
33652@item @var{nr-cols}
33653The number of columns in the output table.
922fbb7b 33654
a2c02241
NR
33655@item @var{aschar}
33656If present, indicates that each row should include an @sc{ascii} dump. The
33657value of @var{aschar} is used as a padding character when a byte is not a
33658member of the printable @sc{ascii} character set (printable @sc{ascii}
33659characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33660
a2c02241
NR
33661@item @var{byte-offset}
33662An offset to add to the @var{address} before fetching memory.
33663@end table
922fbb7b 33664
a2c02241
NR
33665This command displays memory contents as a table of @var{nr-rows} by
33666@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33667@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33668(returned as @samp{total-bytes}). Should less than the requested number
33669of bytes be returned by the target, the missing words are identified
33670using @samp{N/A}. The number of bytes read from the target is returned
33671in @samp{nr-bytes} and the starting address used to read memory in
33672@samp{addr}.
33673
33674The address of the next/previous row or page is available in
33675@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33676@samp{prev-page}.
922fbb7b
AC
33677
33678@subsubheading @value{GDBN} Command
33679
a2c02241
NR
33680The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33681@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33682
33683@subsubheading Example
32e7087d 33684
a2c02241
NR
33685Read six bytes of memory starting at @code{bytes+6} but then offset by
33686@code{-6} bytes. Format as three rows of two columns. One byte per
33687word. Display each word in hex.
32e7087d
JB
33688
33689@smallexample
594fe323 33690(gdb)
a2c02241
NR
336919-data-read-memory -o -6 -- bytes+6 x 1 3 2
336929^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33693next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33694prev-page="0x0000138a",memory=[
33695@{addr="0x00001390",data=["0x00","0x01"]@},
33696@{addr="0x00001392",data=["0x02","0x03"]@},
33697@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33698(gdb)
32e7087d
JB
33699@end smallexample
33700
a2c02241
NR
33701Read two bytes of memory starting at address @code{shorts + 64} and
33702display as a single word formatted in decimal.
32e7087d 33703
32e7087d 33704@smallexample
594fe323 33705(gdb)
a2c02241
NR
337065-data-read-memory shorts+64 d 2 1 1
337075^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33708next-row="0x00001512",prev-row="0x0000150e",
33709next-page="0x00001512",prev-page="0x0000150e",memory=[
33710@{addr="0x00001510",data=["128"]@}]
594fe323 33711(gdb)
32e7087d
JB
33712@end smallexample
33713
a2c02241
NR
33714Read thirty two bytes of memory starting at @code{bytes+16} and format
33715as eight rows of four columns. Include a string encoding with @samp{x}
33716used as the non-printable character.
922fbb7b
AC
33717
33718@smallexample
594fe323 33719(gdb)
a2c02241
NR
337204-data-read-memory bytes+16 x 1 8 4 x
337214^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33722next-row="0x000013c0",prev-row="0x0000139c",
33723next-page="0x000013c0",prev-page="0x00001380",memory=[
33724@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33725@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33726@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33727@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33728@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33729@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33730@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33731@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33732(gdb)
922fbb7b
AC
33733@end smallexample
33734
8dedea02
VP
33735@subheading The @code{-data-read-memory-bytes} Command
33736@findex -data-read-memory-bytes
33737
33738@subsubheading Synopsis
33739
33740@smallexample
a86c90e6 33741 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33742 @var{address} @var{count}
33743@end smallexample
33744
33745@noindent
33746where:
33747
33748@table @samp
33749@item @var{address}
a86c90e6
SM
33750An expression specifying the address of the first addressable memory unit
33751to be read. Complex expressions containing embedded white space should be
8dedea02
VP
33752quoted using the C convention.
33753
33754@item @var{count}
a86c90e6
SM
33755The number of addressable memory units to read. This should be an integer
33756literal.
8dedea02 33757
a86c90e6
SM
33758@item @var{offset}
33759The offset relative to @var{address} at which to start reading. This
33760should be an integer literal. This option is provided so that a frontend
33761is not required to first evaluate address and then perform address
33762arithmetics itself.
8dedea02
VP
33763
33764@end table
33765
33766This command attempts to read all accessible memory regions in the
33767specified range. First, all regions marked as unreadable in the memory
33768map (if one is defined) will be skipped. @xref{Memory Region
33769Attributes}. Second, @value{GDBN} will attempt to read the remaining
33770regions. For each one, if reading full region results in an errors,
33771@value{GDBN} will try to read a subset of the region.
33772
a86c90e6
SM
33773In general, every single memory unit in the region may be readable or not,
33774and the only way to read every readable unit is to try a read at
8dedea02 33775every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 33776attempt to read all accessible memory units at either beginning or the end
8dedea02 33777of the region, using a binary division scheme. This heuristic works
6b92c0d3 33778well for reading across a memory map boundary. Note that if a region
8dedea02
VP
33779has a readable range that is neither at the beginning or the end,
33780@value{GDBN} will not read it.
33781
33782The result record (@pxref{GDB/MI Result Records}) that is output of
33783the command includes a field named @samp{memory} whose content is a
33784list of tuples. Each tuple represent a successfully read memory block
33785and has the following fields:
33786
33787@table @code
33788@item begin
33789The start address of the memory block, as hexadecimal literal.
33790
33791@item end
33792The end address of the memory block, as hexadecimal literal.
33793
33794@item offset
33795The offset of the memory block, as hexadecimal literal, relative to
33796the start address passed to @code{-data-read-memory-bytes}.
33797
33798@item contents
33799The contents of the memory block, in hex.
33800
33801@end table
33802
33803
33804
33805@subsubheading @value{GDBN} Command
33806
33807The corresponding @value{GDBN} command is @samp{x}.
33808
33809@subsubheading Example
33810
33811@smallexample
33812(gdb)
33813-data-read-memory-bytes &a 10
33814^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33815 end="0xbffff15e",
33816 contents="01000000020000000300"@}]
33817(gdb)
33818@end smallexample
33819
33820
33821@subheading The @code{-data-write-memory-bytes} Command
33822@findex -data-write-memory-bytes
33823
33824@subsubheading Synopsis
33825
33826@smallexample
33827 -data-write-memory-bytes @var{address} @var{contents}
62747a60 33828 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
33829@end smallexample
33830
33831@noindent
33832where:
33833
33834@table @samp
33835@item @var{address}
a86c90e6
SM
33836An expression specifying the address of the first addressable memory unit
33837to be written. Complex expressions containing embedded white space should
33838be quoted using the C convention.
8dedea02
VP
33839
33840@item @var{contents}
a86c90e6
SM
33841The hex-encoded data to write. It is an error if @var{contents} does
33842not represent an integral number of addressable memory units.
8dedea02 33843
62747a60 33844@item @var{count}
a86c90e6
SM
33845Optional argument indicating the number of addressable memory units to be
33846written. If @var{count} is greater than @var{contents}' length,
33847@value{GDBN} will repeatedly write @var{contents} until it fills
33848@var{count} memory units.
62747a60 33849
8dedea02
VP
33850@end table
33851
33852@subsubheading @value{GDBN} Command
33853
33854There's no corresponding @value{GDBN} command.
33855
33856@subsubheading Example
33857
33858@smallexample
33859(gdb)
33860-data-write-memory-bytes &a "aabbccdd"
33861^done
33862(gdb)
33863@end smallexample
33864
62747a60
TT
33865@smallexample
33866(gdb)
33867-data-write-memory-bytes &a "aabbccdd" 16e
33868^done
33869(gdb)
33870@end smallexample
8dedea02 33871
a2c02241
NR
33872@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33873@node GDB/MI Tracepoint Commands
33874@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 33875
18148017
VP
33876The commands defined in this section implement MI support for
33877tracepoints. For detailed introduction, see @ref{Tracepoints}.
33878
33879@subheading The @code{-trace-find} Command
33880@findex -trace-find
33881
33882@subsubheading Synopsis
33883
33884@smallexample
33885 -trace-find @var{mode} [@var{parameters}@dots{}]
33886@end smallexample
33887
33888Find a trace frame using criteria defined by @var{mode} and
33889@var{parameters}. The following table lists permissible
33890modes and their parameters. For details of operation, see @ref{tfind}.
33891
33892@table @samp
33893
33894@item none
33895No parameters are required. Stops examining trace frames.
33896
33897@item frame-number
33898An integer is required as parameter. Selects tracepoint frame with
33899that index.
33900
33901@item tracepoint-number
33902An integer is required as parameter. Finds next
33903trace frame that corresponds to tracepoint with the specified number.
33904
33905@item pc
33906An address is required as parameter. Finds
33907next trace frame that corresponds to any tracepoint at the specified
33908address.
33909
33910@item pc-inside-range
33911Two addresses are required as parameters. Finds next trace
33912frame that corresponds to a tracepoint at an address inside the
33913specified range. Both bounds are considered to be inside the range.
33914
33915@item pc-outside-range
33916Two addresses are required as parameters. Finds
33917next trace frame that corresponds to a tracepoint at an address outside
33918the specified range. Both bounds are considered to be inside the range.
33919
33920@item line
33921Line specification is required as parameter. @xref{Specify Location}.
33922Finds next trace frame that corresponds to a tracepoint at
33923the specified location.
33924
33925@end table
33926
33927If @samp{none} was passed as @var{mode}, the response does not
33928have fields. Otherwise, the response may have the following fields:
33929
33930@table @samp
33931@item found
33932This field has either @samp{0} or @samp{1} as the value, depending
33933on whether a matching tracepoint was found.
33934
33935@item traceframe
33936The index of the found traceframe. This field is present iff
33937the @samp{found} field has value of @samp{1}.
33938
33939@item tracepoint
33940The index of the found tracepoint. This field is present iff
33941the @samp{found} field has value of @samp{1}.
33942
33943@item frame
33944The information about the frame corresponding to the found trace
33945frame. This field is present only if a trace frame was found.
cd64ee31 33946@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
33947
33948@end table
33949
7d13fe92
SS
33950@subsubheading @value{GDBN} Command
33951
33952The corresponding @value{GDBN} command is @samp{tfind}.
33953
18148017
VP
33954@subheading -trace-define-variable
33955@findex -trace-define-variable
33956
33957@subsubheading Synopsis
33958
33959@smallexample
33960 -trace-define-variable @var{name} [ @var{value} ]
33961@end smallexample
33962
33963Create trace variable @var{name} if it does not exist. If
33964@var{value} is specified, sets the initial value of the specified
33965trace variable to that value. Note that the @var{name} should start
33966with the @samp{$} character.
33967
7d13fe92
SS
33968@subsubheading @value{GDBN} Command
33969
33970The corresponding @value{GDBN} command is @samp{tvariable}.
33971
dc673c81
YQ
33972@subheading The @code{-trace-frame-collected} Command
33973@findex -trace-frame-collected
33974
33975@subsubheading Synopsis
33976
33977@smallexample
33978 -trace-frame-collected
33979 [--var-print-values @var{var_pval}]
33980 [--comp-print-values @var{comp_pval}]
33981 [--registers-format @var{regformat}]
33982 [--memory-contents]
33983@end smallexample
33984
33985This command returns the set of collected objects, register names,
33986trace state variable names, memory ranges and computed expressions
33987that have been collected at a particular trace frame. The optional
33988parameters to the command affect the output format in different ways.
33989See the output description table below for more details.
33990
33991The reported names can be used in the normal manner to create
33992varobjs and inspect the objects themselves. The items returned by
33993this command are categorized so that it is clear which is a variable,
33994which is a register, which is a trace state variable, which is a
33995memory range and which is a computed expression.
33996
33997For instance, if the actions were
33998@smallexample
33999collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34000collect *(int*)0xaf02bef0@@40
34001@end smallexample
34002
34003@noindent
34004the object collected in its entirety would be @code{myVar}. The
34005object @code{myArray} would be partially collected, because only the
34006element at index @code{myIndex} would be collected. The remaining
34007objects would be computed expressions.
34008
34009An example output would be:
34010
34011@smallexample
34012(gdb)
34013-trace-frame-collected
34014^done,
34015 explicit-variables=[@{name="myVar",value="1"@}],
34016 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34017 @{name="myObj.field",value="0"@},
34018 @{name="myPtr->field",value="1"@},
34019 @{name="myCount + 2",value="3"@},
34020 @{name="$tvar1 + 1",value="43970027"@}],
34021 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34022 @{number="1",value="0x0"@},
34023 @{number="2",value="0x4"@},
34024 ...
34025 @{number="125",value="0x0"@}],
34026 tvars=[@{name="$tvar1",current="43970026"@}],
34027 memory=[@{address="0x0000000000602264",length="4"@},
34028 @{address="0x0000000000615bc0",length="4"@}]
34029(gdb)
34030@end smallexample
34031
34032Where:
34033
34034@table @code
34035@item explicit-variables
34036The set of objects that have been collected in their entirety (as
34037opposed to collecting just a few elements of an array or a few struct
34038members). For each object, its name and value are printed.
34039The @code{--var-print-values} option affects how or whether the value
34040field is output. If @var{var_pval} is 0, then print only the names;
34041if it is 1, print also their values; and if it is 2, print the name,
34042type and value for simple data types, and the name and type for
34043arrays, structures and unions.
34044
34045@item computed-expressions
34046The set of computed expressions that have been collected at the
34047current trace frame. The @code{--comp-print-values} option affects
34048this set like the @code{--var-print-values} option affects the
34049@code{explicit-variables} set. See above.
34050
34051@item registers
34052The registers that have been collected at the current trace frame.
34053For each register collected, the name and current value are returned.
34054The value is formatted according to the @code{--registers-format}
34055option. See the @command{-data-list-register-values} command for a
34056list of the allowed formats. The default is @samp{x}.
34057
34058@item tvars
34059The trace state variables that have been collected at the current
34060trace frame. For each trace state variable collected, the name and
34061current value are returned.
34062
34063@item memory
34064The set of memory ranges that have been collected at the current trace
34065frame. Its content is a list of tuples. Each tuple represents a
34066collected memory range and has the following fields:
34067
34068@table @code
34069@item address
34070The start address of the memory range, as hexadecimal literal.
34071
34072@item length
34073The length of the memory range, as decimal literal.
34074
34075@item contents
34076The contents of the memory block, in hex. This field is only present
34077if the @code{--memory-contents} option is specified.
34078
34079@end table
34080
34081@end table
34082
34083@subsubheading @value{GDBN} Command
34084
34085There is no corresponding @value{GDBN} command.
34086
34087@subsubheading Example
34088
18148017
VP
34089@subheading -trace-list-variables
34090@findex -trace-list-variables
922fbb7b 34091
18148017 34092@subsubheading Synopsis
922fbb7b 34093
18148017
VP
34094@smallexample
34095 -trace-list-variables
34096@end smallexample
922fbb7b 34097
18148017
VP
34098Return a table of all defined trace variables. Each element of the
34099table has the following fields:
922fbb7b 34100
18148017
VP
34101@table @samp
34102@item name
34103The name of the trace variable. This field is always present.
922fbb7b 34104
18148017
VP
34105@item initial
34106The initial value. This is a 64-bit signed integer. This
34107field is always present.
922fbb7b 34108
18148017
VP
34109@item current
34110The value the trace variable has at the moment. This is a 64-bit
34111signed integer. This field is absent iff current value is
34112not defined, for example if the trace was never run, or is
34113presently running.
922fbb7b 34114
18148017 34115@end table
922fbb7b 34116
7d13fe92
SS
34117@subsubheading @value{GDBN} Command
34118
34119The corresponding @value{GDBN} command is @samp{tvariables}.
34120
18148017 34121@subsubheading Example
922fbb7b 34122
18148017
VP
34123@smallexample
34124(gdb)
34125-trace-list-variables
34126^done,trace-variables=@{nr_rows="1",nr_cols="3",
34127hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34128 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34129 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34130body=[variable=@{name="$trace_timestamp",initial="0"@}
34131 variable=@{name="$foo",initial="10",current="15"@}]@}
34132(gdb)
34133@end smallexample
922fbb7b 34134
18148017
VP
34135@subheading -trace-save
34136@findex -trace-save
922fbb7b 34137
18148017
VP
34138@subsubheading Synopsis
34139
34140@smallexample
99e61eda 34141 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
34142@end smallexample
34143
34144Saves the collected trace data to @var{filename}. Without the
34145@samp{-r} option, the data is downloaded from the target and saved
34146in a local file. With the @samp{-r} option the target is asked
34147to perform the save.
34148
99e61eda
SM
34149By default, this command will save the trace in the tfile format. You can
34150supply the optional @samp{-ctf} argument to save it the CTF format. See
34151@ref{Trace Files} for more information about CTF.
34152
7d13fe92
SS
34153@subsubheading @value{GDBN} Command
34154
34155The corresponding @value{GDBN} command is @samp{tsave}.
34156
18148017
VP
34157
34158@subheading -trace-start
34159@findex -trace-start
34160
34161@subsubheading Synopsis
34162
34163@smallexample
34164 -trace-start
34165@end smallexample
922fbb7b 34166
be06ba8c 34167Starts a tracing experiment. The result of this command does not
18148017 34168have any fields.
922fbb7b 34169
7d13fe92
SS
34170@subsubheading @value{GDBN} Command
34171
34172The corresponding @value{GDBN} command is @samp{tstart}.
34173
18148017
VP
34174@subheading -trace-status
34175@findex -trace-status
922fbb7b 34176
18148017
VP
34177@subsubheading Synopsis
34178
34179@smallexample
34180 -trace-status
34181@end smallexample
34182
a97153c7 34183Obtains the status of a tracing experiment. The result may include
18148017
VP
34184the following fields:
34185
34186@table @samp
34187
34188@item supported
34189May have a value of either @samp{0}, when no tracing operations are
34190supported, @samp{1}, when all tracing operations are supported, or
34191@samp{file} when examining trace file. In the latter case, examining
34192of trace frame is possible but new tracing experiement cannot be
34193started. This field is always present.
34194
34195@item running
34196May have a value of either @samp{0} or @samp{1} depending on whether
34197tracing experiement is in progress on target. This field is present
34198if @samp{supported} field is not @samp{0}.
34199
34200@item stop-reason
34201Report the reason why the tracing was stopped last time. This field
34202may be absent iff tracing was never stopped on target yet. The
34203value of @samp{request} means the tracing was stopped as result of
34204the @code{-trace-stop} command. The value of @samp{overflow} means
34205the tracing buffer is full. The value of @samp{disconnection} means
34206tracing was automatically stopped when @value{GDBN} has disconnected.
34207The value of @samp{passcount} means tracing was stopped when a
34208tracepoint was passed a maximal number of times for that tracepoint.
34209This field is present if @samp{supported} field is not @samp{0}.
34210
34211@item stopping-tracepoint
34212The number of tracepoint whose passcount as exceeded. This field is
34213present iff the @samp{stop-reason} field has the value of
34214@samp{passcount}.
34215
34216@item frames
87290684
SS
34217@itemx frames-created
34218The @samp{frames} field is a count of the total number of trace frames
34219in the trace buffer, while @samp{frames-created} is the total created
34220during the run, including ones that were discarded, such as when a
34221circular trace buffer filled up. Both fields are optional.
18148017
VP
34222
34223@item buffer-size
34224@itemx buffer-free
34225These fields tell the current size of the tracing buffer and the
87290684 34226remaining space. These fields are optional.
18148017 34227
a97153c7
PA
34228@item circular
34229The value of the circular trace buffer flag. @code{1} means that the
34230trace buffer is circular and old trace frames will be discarded if
34231necessary to make room, @code{0} means that the trace buffer is linear
34232and may fill up.
34233
34234@item disconnected
34235The value of the disconnected tracing flag. @code{1} means that
34236tracing will continue after @value{GDBN} disconnects, @code{0} means
34237that the trace run will stop.
34238
f5911ea1
HAQ
34239@item trace-file
34240The filename of the trace file being examined. This field is
34241optional, and only present when examining a trace file.
34242
18148017
VP
34243@end table
34244
7d13fe92
SS
34245@subsubheading @value{GDBN} Command
34246
34247The corresponding @value{GDBN} command is @samp{tstatus}.
34248
18148017
VP
34249@subheading -trace-stop
34250@findex -trace-stop
34251
34252@subsubheading Synopsis
34253
34254@smallexample
34255 -trace-stop
34256@end smallexample
922fbb7b 34257
18148017
VP
34258Stops a tracing experiment. The result of this command has the same
34259fields as @code{-trace-status}, except that the @samp{supported} and
34260@samp{running} fields are not output.
922fbb7b 34261
7d13fe92
SS
34262@subsubheading @value{GDBN} Command
34263
34264The corresponding @value{GDBN} command is @samp{tstop}.
34265
922fbb7b 34266
a2c02241
NR
34267@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34268@node GDB/MI Symbol Query
34269@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34270
34271
9901a55b 34272@ignore
a2c02241
NR
34273@subheading The @code{-symbol-info-address} Command
34274@findex -symbol-info-address
922fbb7b
AC
34275
34276@subsubheading Synopsis
34277
34278@smallexample
a2c02241 34279 -symbol-info-address @var{symbol}
922fbb7b
AC
34280@end smallexample
34281
a2c02241 34282Describe where @var{symbol} is stored.
922fbb7b
AC
34283
34284@subsubheading @value{GDBN} Command
34285
a2c02241 34286The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34287
34288@subsubheading Example
34289N.A.
34290
34291
a2c02241
NR
34292@subheading The @code{-symbol-info-file} Command
34293@findex -symbol-info-file
922fbb7b
AC
34294
34295@subsubheading Synopsis
34296
34297@smallexample
a2c02241 34298 -symbol-info-file
922fbb7b
AC
34299@end smallexample
34300
a2c02241 34301Show the file for the symbol.
922fbb7b 34302
a2c02241 34303@subsubheading @value{GDBN} Command
922fbb7b 34304
a2c02241
NR
34305There's no equivalent @value{GDBN} command. @code{gdbtk} has
34306@samp{gdb_find_file}.
922fbb7b
AC
34307
34308@subsubheading Example
34309N.A.
7dc42066
AB
34310@end ignore
34311
34312@subheading The @code{-symbol-info-functions} Command
34313@findex -symbol-info-functions
34314@anchor{-symbol-info-functions}
34315
34316@subsubheading Synopsis
34317
34318@smallexample
34319 -symbol-info-functions [--include-nondebug]
34320 [--type @var{type_regexp}]
34321 [--name @var{name_regexp}]
c2512106 34322 [--max-results @var{limit}]
7dc42066
AB
34323@end smallexample
34324
34325@noindent
34326Return a list containing the names and types for all global functions
34327taken from the debug information. The functions are grouped by source
34328file, and shown with the line number on which each function is
34329defined.
922fbb7b 34330
7dc42066
AB
34331The @code{--include-nondebug} option causes the output to include
34332code symbols from the symbol table.
922fbb7b 34333
7dc42066
AB
34334The options @code{--type} and @code{--name} allow the symbols returned
34335to be filtered based on either the name of the function, or the type
34336signature of the function.
34337
c2512106
AB
34338The option @code{--max-results} restricts the command to return no
34339more than @var{limit} results. If exactly @var{limit} results are
34340returned then there might be additional results available if a higher
34341limit is used.
34342
7dc42066
AB
34343@subsubheading @value{GDBN} Command
34344
34345The corresponding @value{GDBN} command is @samp{info functions}.
34346
34347@subsubheading Example
34348@smallexample
34349@group
34350(gdb)
34351-symbol-info-functions
34352^done,symbols=
34353 @{debug=
34354 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34355 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34356 symbols=[@{line="36", name="f4", type="void (int *)",
34357 description="void f4(int *);"@},
34358 @{line="42", name="main", type="int ()",
34359 description="int main();"@},
34360 @{line="30", name="f1", type="my_int_t (int, int)",
34361 description="static my_int_t f1(int, int);"@}]@},
34362 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34363 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34364 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34365 description="float f2(another_float_t);"@},
34366 @{line="39", name="f3", type="int (another_int_t)",
34367 description="int f3(another_int_t);"@},
34368 @{line="27", name="f1", type="another_float_t (int)",
34369 description="static another_float_t f1(int);"@}]@}]@}
34370@end group
34371@group
34372(gdb)
34373-symbol-info-functions --name f1
34374^done,symbols=
34375 @{debug=
34376 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34377 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34378 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34379 description="static my_int_t f1(int, int);"@}]@},
34380 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34381 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34382 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34383 description="static another_float_t f1(int);"@}]@}]@}
34384@end group
34385@group
34386(gdb)
34387-symbol-info-functions --type void
34388^done,symbols=
34389 @{debug=
34390 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34391 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34392 symbols=[@{line="36", name="f4", type="void (int *)",
34393 description="void f4(int *);"@}]@}]@}
34394@end group
34395@group
34396(gdb)
34397-symbol-info-functions --include-nondebug
34398^done,symbols=
34399 @{debug=
34400 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34401 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34402 symbols=[@{line="36", name="f4", type="void (int *)",
34403 description="void f4(int *);"@},
34404 @{line="42", name="main", type="int ()",
34405 description="int main();"@},
34406 @{line="30", name="f1", type="my_int_t (int, int)",
34407 description="static my_int_t f1(int, int);"@}]@},
34408 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34409 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34410 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34411 description="float f2(another_float_t);"@},
34412 @{line="39", name="f3", type="int (another_int_t)",
34413 description="int f3(another_int_t);"@},
34414 @{line="27", name="f1", type="another_float_t (int)",
34415 description="static another_float_t f1(int);"@}]@}],
34416 nondebug=
34417 [@{address="0x0000000000400398",name="_init"@},
34418 @{address="0x00000000004003b0",name="_start"@},
34419 ...
34420 ]@}
34421@end group
34422@end smallexample
34423
293b38d6
AB
34424@subheading The @code{-symbol-info-module-functions} Command
34425@findex -symbol-info-module-functions
34426@anchor{-symbol-info-module-functions}
34427
34428@subsubheading Synopsis
34429
34430@smallexample
34431 -symbol-info-module-functions [--module @var{module_regexp}]
34432 [--name @var{name_regexp}]
34433 [--type @var{type_regexp}]
34434@end smallexample
34435
34436@noindent
34437Return a list containing the names of all known functions within all
34438know Fortran modules. The functions are grouped by source file and
34439containing module, and shown with the line number on which each
34440function is defined.
34441
34442The option @code{--module} only returns results for modules matching
34443@var{module_regexp}. The option @code{--name} only returns functions
34444whose name matches @var{name_regexp}, and @code{--type} only returns
34445functions whose type matches @var{type_regexp}.
34446
34447@subsubheading @value{GDBN} Command
34448
34449The corresponding @value{GDBN} command is @samp{info module functions}.
34450
34451@subsubheading Example
34452
34453@smallexample
34454@group
34455(gdb)
34456-symbol-info-module-functions
34457^done,symbols=
34458 [@{module="mod1",
34459 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34460 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34461 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34462 description="void mod1::check_all(void);"@}]@}]@},
34463 @{module="mod2",
34464 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34465 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34466 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34467 description="void mod2::check_var_i(void);"@}]@}]@},
34468 @{module="mod3",
34469 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34470 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34471 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34472 description="void mod3::check_all(void);"@},
34473 @{line="27",name="mod3::check_mod2",type="void (void)",
34474 description="void mod3::check_mod2(void);"@}]@}]@},
34475 @{module="modmany",
34476 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34477 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34478 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34479 description="void modmany::check_some(void);"@}]@}]@},
34480 @{module="moduse",
34481 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34482 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34483 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34484 description="void moduse::check_all(void);"@},
34485 @{line="49",name="moduse::check_var_x",type="void (void)",
34486 description="void moduse::check_var_x(void);"@}]@}]@}]
34487@end group
34488@end smallexample
34489
34490@subheading The @code{-symbol-info-module-variables} Command
34491@findex -symbol-info-module-variables
34492@anchor{-symbol-info-module-variables}
34493
34494@subsubheading Synopsis
34495
34496@smallexample
34497 -symbol-info-module-variables [--module @var{module_regexp}]
34498 [--name @var{name_regexp}]
34499 [--type @var{type_regexp}]
34500@end smallexample
34501
34502@noindent
34503Return a list containing the names of all known variables within all
34504know Fortran modules. The variables are grouped by source file and
34505containing module, and shown with the line number on which each
34506variable is defined.
34507
34508The option @code{--module} only returns results for modules matching
34509@var{module_regexp}. The option @code{--name} only returns variables
34510whose name matches @var{name_regexp}, and @code{--type} only returns
34511variables whose type matches @var{type_regexp}.
34512
34513@subsubheading @value{GDBN} Command
34514
34515The corresponding @value{GDBN} command is @samp{info module variables}.
34516
34517@subsubheading Example
34518
34519@smallexample
34520@group
34521(gdb)
34522-symbol-info-module-variables
34523^done,symbols=
34524 [@{module="mod1",
34525 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34526 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34527 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34528 description="integer(kind=4) mod1::var_const;"@},
34529 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34530 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34531 @{module="mod2",
34532 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34533 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34534 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34535 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34536 @{module="mod3",
34537 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34538 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34539 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34540 description="integer(kind=4) mod3::mod1;"@},
34541 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34542 description="integer(kind=4) mod3::mod2;"@},
34543 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34544 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34545 @{module="modmany",
34546 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34547 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34548 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34549 description="integer(kind=4) modmany::var_a;"@},
34550 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34551 description="integer(kind=4) modmany::var_b;"@},
34552 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34553 description="integer(kind=4) modmany::var_c;"@},
34554 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34555 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34556 @{module="moduse",
34557 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34558 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34559 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34560 description="integer(kind=4) moduse::var_x;"@},
34561 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34562 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34563@end group
34564@end smallexample
34565
db5960b4
AB
34566@subheading The @code{-symbol-info-modules} Command
34567@findex -symbol-info-modules
34568@anchor{-symbol-info-modules}
34569
34570@subsubheading Synopsis
34571
34572@smallexample
34573 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34574 [--max-results @var{limit}]
34575
db5960b4
AB
34576@end smallexample
34577
34578@noindent
34579Return a list containing the names of all known Fortran modules. The
34580modules are grouped by source file, and shown with the line number on
34581which each modules is defined.
34582
34583The option @code{--name} allows the modules returned to be filtered
34584based the name of the module.
34585
c2512106
AB
34586The option @code{--max-results} restricts the command to return no
34587more than @var{limit} results. If exactly @var{limit} results are
34588returned then there might be additional results available if a higher
34589limit is used.
34590
db5960b4
AB
34591@subsubheading @value{GDBN} Command
34592
34593The corresponding @value{GDBN} command is @samp{info modules}.
34594
34595@subsubheading Example
34596@smallexample
34597@group
34598(gdb)
34599-symbol-info-modules
34600^done,symbols=
34601 @{debug=
34602 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34603 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34604 symbols=[@{line="16",name="mod1"@},
34605 @{line="22",name="mod2"@}]@},
34606 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34607 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34608 symbols=[@{line="16",name="mod3"@},
34609 @{line="22",name="modmany"@},
34610 @{line="26",name="moduse"@}]@}]@}
34611@end group
34612@group
34613(gdb)
34614-symbol-info-modules --name mod[123]
34615^done,symbols=
34616 @{debug=
34617 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34618 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34619 symbols=[@{line="16",name="mod1"@},
34620 @{line="22",name="mod2"@}]@},
34621 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34622 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34623 symbols=[@{line="16",name="mod3"@}]@}]@}
34624@end group
34625@end smallexample
34626
7dc42066
AB
34627@subheading The @code{-symbol-info-types} Command
34628@findex -symbol-info-types
34629@anchor{-symbol-info-types}
922fbb7b
AC
34630
34631@subsubheading Synopsis
34632
34633@smallexample
7dc42066 34634 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34635 [--max-results @var{limit}]
34636
922fbb7b
AC
34637@end smallexample
34638
7dc42066
AB
34639@noindent
34640Return a list of all defined types. The types are grouped by source
34641file, and shown with the line number on which each user defined type
34642is defined. Some base types are not defined in the source code but
34643are added to the debug information by the compiler, for example
34644@code{int}, @code{float}, etc.; these types do not have an associated
34645line number.
34646
34647The option @code{--name} allows the list of types returned to be
34648filtered by name.
922fbb7b 34649
c2512106
AB
34650The option @code{--max-results} restricts the command to return no
34651more than @var{limit} results. If exactly @var{limit} results are
34652returned then there might be additional results available if a higher
34653limit is used.
34654
922fbb7b
AC
34655@subsubheading @value{GDBN} Command
34656
7dc42066 34657The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34658
34659@subsubheading Example
7dc42066
AB
34660@smallexample
34661@group
34662(gdb)
34663-symbol-info-types
34664^done,symbols=
34665 @{debug=
34666 [@{filename="gdb.mi/mi-sym-info-1.c",
34667 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34668 symbols=[@{name="float"@},
34669 @{name="int"@},
34670 @{line="27",name="typedef int my_int_t;"@}]@},
34671 @{filename="gdb.mi/mi-sym-info-2.c",
34672 fullname="/project/gdb.mi/mi-sym-info-2.c",
34673 symbols=[@{line="24",name="typedef float another_float_t;"@},
34674 @{line="23",name="typedef int another_int_t;"@},
34675 @{name="float"@},
34676 @{name="int"@}]@}]@}
34677@end group
34678@group
34679(gdb)
34680-symbol-info-types --name _int_
34681^done,symbols=
34682 @{debug=
34683 [@{filename="gdb.mi/mi-sym-info-1.c",
34684 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34685 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34686 @{filename="gdb.mi/mi-sym-info-2.c",
34687 fullname="/project/gdb.mi/mi-sym-info-2.c",
34688 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34689@end group
34690@end smallexample
34691
34692@subheading The @code{-symbol-info-variables} Command
34693@findex -symbol-info-variables
34694@anchor{-symbol-info-variables}
34695
34696@subsubheading Synopsis
34697
34698@smallexample
34699 -symbol-info-variables [--include-nondebug]
34700 [--type @var{type_regexp}]
34701 [--name @var{name_regexp}]
c2512106
AB
34702 [--max-results @var{limit}]
34703
7dc42066
AB
34704@end smallexample
34705
34706@noindent
34707Return a list containing the names and types for all global variables
34708taken from the debug information. The variables are grouped by source
34709file, and shown with the line number on which each variable is
34710defined.
34711
34712The @code{--include-nondebug} option causes the output to include
34713data symbols from the symbol table.
34714
34715The options @code{--type} and @code{--name} allow the symbols returned
34716to be filtered based on either the name of the variable, or the type
34717of the variable.
34718
c2512106
AB
34719The option @code{--max-results} restricts the command to return no
34720more than @var{limit} results. If exactly @var{limit} results are
34721returned then there might be additional results available if a higher
34722limit is used.
34723
7dc42066 34724@subsubheading @value{GDBN} Command
922fbb7b 34725
7dc42066 34726The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34727
7dc42066
AB
34728@subsubheading Example
34729@smallexample
34730@group
34731(gdb)
34732-symbol-info-variables
34733^done,symbols=
34734 @{debug=
34735 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34736 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34737 symbols=[@{line="25",name="global_f1",type="float",
34738 description="static float global_f1;"@},
34739 @{line="24",name="global_i1",type="int",
34740 description="static int global_i1;"@}]@},
34741 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34742 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34743 symbols=[@{line="21",name="global_f2",type="int",
34744 description="int global_f2;"@},
34745 @{line="20",name="global_i2",type="int",
34746 description="int global_i2;"@},
34747 @{line="19",name="global_f1",type="float",
34748 description="static float global_f1;"@},
34749 @{line="18",name="global_i1",type="int",
34750 description="static int global_i1;"@}]@}]@}
34751@end group
34752@group
34753(gdb)
34754-symbol-info-variables --name f1
34755^done,symbols=
34756 @{debug=
34757 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34758 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34759 symbols=[@{line="25",name="global_f1",type="float",
34760 description="static float global_f1;"@}]@},
34761 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34762 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34763 symbols=[@{line="19",name="global_f1",type="float",
34764 description="static float global_f1;"@}]@}]@}
34765@end group
34766@group
34767(gdb)
34768-symbol-info-variables --type float
34769^done,symbols=
34770 @{debug=
34771 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34772 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34773 symbols=[@{line="25",name="global_f1",type="float",
34774 description="static float global_f1;"@}]@},
34775 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34776 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34777 symbols=[@{line="19",name="global_f1",type="float",
34778 description="static float global_f1;"@}]@}]@}
34779@end group
34780@group
34781(gdb)
34782-symbol-info-variables --include-nondebug
34783^done,symbols=
34784 @{debug=
34785 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34786 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34787 symbols=[@{line="25",name="global_f1",type="float",
34788 description="static float global_f1;"@},
34789 @{line="24",name="global_i1",type="int",
34790 description="static int global_i1;"@}]@},
34791 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34792 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34793 symbols=[@{line="21",name="global_f2",type="int",
34794 description="int global_f2;"@},
34795 @{line="20",name="global_i2",type="int",
34796 description="int global_i2;"@},
34797 @{line="19",name="global_f1",type="float",
34798 description="static float global_f1;"@},
34799 @{line="18",name="global_i1",type="int",
34800 description="static int global_i1;"@}]@}],
34801 nondebug=
34802 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34803 @{address="0x00000000004005d8",name="__dso_handle"@}
34804 ...
34805 ]@}
34806@end group
34807@end smallexample
34808
34809@ignore
a2c02241
NR
34810@subheading The @code{-symbol-info-line} Command
34811@findex -symbol-info-line
922fbb7b
AC
34812
34813@subsubheading Synopsis
34814
34815@smallexample
a2c02241 34816 -symbol-info-line
922fbb7b
AC
34817@end smallexample
34818
a2c02241 34819Show the core addresses of the code for a source line.
922fbb7b 34820
a2c02241 34821@subsubheading @value{GDBN} Command
922fbb7b 34822
a2c02241
NR
34823The corresponding @value{GDBN} command is @samp{info line}.
34824@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
34825
34826@subsubheading Example
a2c02241 34827N.A.
922fbb7b
AC
34828
34829
a2c02241
NR
34830@subheading The @code{-symbol-info-symbol} Command
34831@findex -symbol-info-symbol
07f31aa6
DJ
34832
34833@subsubheading Synopsis
34834
a2c02241
NR
34835@smallexample
34836 -symbol-info-symbol @var{addr}
34837@end smallexample
07f31aa6 34838
a2c02241 34839Describe what symbol is at location @var{addr}.
07f31aa6 34840
a2c02241 34841@subsubheading @value{GDBN} Command
07f31aa6 34842
a2c02241 34843The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
34844
34845@subsubheading Example
a2c02241 34846N.A.
07f31aa6
DJ
34847
34848
a2c02241
NR
34849@subheading The @code{-symbol-list-functions} Command
34850@findex -symbol-list-functions
922fbb7b
AC
34851
34852@subsubheading Synopsis
34853
34854@smallexample
a2c02241 34855 -symbol-list-functions
922fbb7b
AC
34856@end smallexample
34857
a2c02241 34858List the functions in the executable.
922fbb7b
AC
34859
34860@subsubheading @value{GDBN} Command
34861
a2c02241
NR
34862@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34863@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34864
34865@subsubheading Example
a2c02241 34866N.A.
9901a55b 34867@end ignore
922fbb7b
AC
34868
34869
a2c02241
NR
34870@subheading The @code{-symbol-list-lines} Command
34871@findex -symbol-list-lines
922fbb7b
AC
34872
34873@subsubheading Synopsis
34874
34875@smallexample
a2c02241 34876 -symbol-list-lines @var{filename}
922fbb7b
AC
34877@end smallexample
34878
a2c02241
NR
34879Print the list of lines that contain code and their associated program
34880addresses for the given source filename. The entries are sorted in
34881ascending PC order.
922fbb7b
AC
34882
34883@subsubheading @value{GDBN} Command
34884
a2c02241 34885There is no corresponding @value{GDBN} command.
922fbb7b
AC
34886
34887@subsubheading Example
a2c02241 34888@smallexample
594fe323 34889(gdb)
a2c02241
NR
34890-symbol-list-lines basics.c
34891^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 34892(gdb)
a2c02241 34893@end smallexample
922fbb7b
AC
34894
34895
9901a55b 34896@ignore
a2c02241
NR
34897@subheading The @code{-symbol-list-types} Command
34898@findex -symbol-list-types
922fbb7b
AC
34899
34900@subsubheading Synopsis
34901
34902@smallexample
a2c02241 34903 -symbol-list-types
922fbb7b
AC
34904@end smallexample
34905
a2c02241 34906List all the type names.
922fbb7b
AC
34907
34908@subsubheading @value{GDBN} Command
34909
a2c02241
NR
34910The corresponding commands are @samp{info types} in @value{GDBN},
34911@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34912
34913@subsubheading Example
34914N.A.
34915
34916
a2c02241
NR
34917@subheading The @code{-symbol-list-variables} Command
34918@findex -symbol-list-variables
922fbb7b
AC
34919
34920@subsubheading Synopsis
34921
34922@smallexample
a2c02241 34923 -symbol-list-variables
922fbb7b
AC
34924@end smallexample
34925
a2c02241 34926List all the global and static variable names.
922fbb7b
AC
34927
34928@subsubheading @value{GDBN} Command
34929
a2c02241 34930@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34931
34932@subsubheading Example
34933N.A.
34934
34935
a2c02241
NR
34936@subheading The @code{-symbol-locate} Command
34937@findex -symbol-locate
922fbb7b
AC
34938
34939@subsubheading Synopsis
34940
34941@smallexample
a2c02241 34942 -symbol-locate
922fbb7b
AC
34943@end smallexample
34944
922fbb7b
AC
34945@subsubheading @value{GDBN} Command
34946
a2c02241 34947@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
34948
34949@subsubheading Example
34950N.A.
34951
34952
a2c02241
NR
34953@subheading The @code{-symbol-type} Command
34954@findex -symbol-type
922fbb7b
AC
34955
34956@subsubheading Synopsis
34957
34958@smallexample
a2c02241 34959 -symbol-type @var{variable}
922fbb7b
AC
34960@end smallexample
34961
a2c02241 34962Show type of @var{variable}.
922fbb7b 34963
a2c02241 34964@subsubheading @value{GDBN} Command
922fbb7b 34965
a2c02241
NR
34966The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34967@samp{gdb_obj_variable}.
34968
34969@subsubheading Example
34970N.A.
9901a55b 34971@end ignore
a2c02241
NR
34972
34973
34974@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34975@node GDB/MI File Commands
34976@section @sc{gdb/mi} File Commands
34977
34978This section describes the GDB/MI commands to specify executable file names
34979and to read in and obtain symbol table information.
34980
34981@subheading The @code{-file-exec-and-symbols} Command
34982@findex -file-exec-and-symbols
34983
34984@subsubheading Synopsis
922fbb7b
AC
34985
34986@smallexample
a2c02241 34987 -file-exec-and-symbols @var{file}
922fbb7b
AC
34988@end smallexample
34989
a2c02241
NR
34990Specify the executable file to be debugged. This file is the one from
34991which the symbol table is also read. If no file is specified, the
34992command clears the executable and symbol information. If breakpoints
34993are set when using this command with no arguments, @value{GDBN} will produce
34994error messages. Otherwise, no output is produced, except a completion
34995notification.
34996
922fbb7b
AC
34997@subsubheading @value{GDBN} Command
34998
a2c02241 34999The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
35000
35001@subsubheading Example
35002
35003@smallexample
594fe323 35004(gdb)
a2c02241
NR
35005-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35006^done
594fe323 35007(gdb)
922fbb7b
AC
35008@end smallexample
35009
922fbb7b 35010
a2c02241
NR
35011@subheading The @code{-file-exec-file} Command
35012@findex -file-exec-file
922fbb7b
AC
35013
35014@subsubheading Synopsis
35015
35016@smallexample
a2c02241 35017 -file-exec-file @var{file}
922fbb7b
AC
35018@end smallexample
35019
a2c02241
NR
35020Specify the executable file to be debugged. Unlike
35021@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35022from this file. If used without argument, @value{GDBN} clears the information
35023about the executable file. No output is produced, except a completion
35024notification.
922fbb7b 35025
a2c02241
NR
35026@subsubheading @value{GDBN} Command
35027
35028The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
35029
35030@subsubheading Example
a2c02241
NR
35031
35032@smallexample
594fe323 35033(gdb)
a2c02241
NR
35034-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35035^done
594fe323 35036(gdb)
a2c02241 35037@end smallexample
922fbb7b
AC
35038
35039
9901a55b 35040@ignore
a2c02241
NR
35041@subheading The @code{-file-list-exec-sections} Command
35042@findex -file-list-exec-sections
922fbb7b
AC
35043
35044@subsubheading Synopsis
35045
35046@smallexample
a2c02241 35047 -file-list-exec-sections
922fbb7b
AC
35048@end smallexample
35049
a2c02241
NR
35050List the sections of the current executable file.
35051
922fbb7b
AC
35052@subsubheading @value{GDBN} Command
35053
a2c02241
NR
35054The @value{GDBN} command @samp{info file} shows, among the rest, the same
35055information as this command. @code{gdbtk} has a corresponding command
35056@samp{gdb_load_info}.
922fbb7b
AC
35057
35058@subsubheading Example
35059N.A.
9901a55b 35060@end ignore
922fbb7b
AC
35061
35062
a2c02241
NR
35063@subheading The @code{-file-list-exec-source-file} Command
35064@findex -file-list-exec-source-file
922fbb7b
AC
35065
35066@subsubheading Synopsis
35067
35068@smallexample
a2c02241 35069 -file-list-exec-source-file
922fbb7b
AC
35070@end smallexample
35071
a2c02241 35072List the line number, the current source file, and the absolute path
44288b44
NR
35073to the current source file for the current executable. The macro
35074information field has a value of @samp{1} or @samp{0} depending on
35075whether or not the file includes preprocessor macro information.
922fbb7b
AC
35076
35077@subsubheading @value{GDBN} Command
35078
a2c02241 35079The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
35080
35081@subsubheading Example
35082
922fbb7b 35083@smallexample
594fe323 35084(gdb)
a2c02241 35085123-file-list-exec-source-file
44288b44 35086123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 35087(gdb)
922fbb7b
AC
35088@end smallexample
35089
35090
a2c02241
NR
35091@subheading The @code{-file-list-exec-source-files} Command
35092@findex -file-list-exec-source-files
922fbb7b
AC
35093
35094@subsubheading Synopsis
35095
35096@smallexample
a2c02241 35097 -file-list-exec-source-files
922fbb7b
AC
35098@end smallexample
35099
a2c02241
NR
35100List the source files for the current executable.
35101
f35a17b5
JK
35102It will always output both the filename and fullname (absolute file
35103name) of a source file.
922fbb7b
AC
35104
35105@subsubheading @value{GDBN} Command
35106
a2c02241
NR
35107The @value{GDBN} equivalent is @samp{info sources}.
35108@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
35109
35110@subsubheading Example
922fbb7b 35111@smallexample
594fe323 35112(gdb)
a2c02241
NR
35113-file-list-exec-source-files
35114^done,files=[
35115@{file=foo.c,fullname=/home/foo.c@},
35116@{file=/home/bar.c,fullname=/home/bar.c@},
35117@{file=gdb_could_not_find_fullpath.c@}]
594fe323 35118(gdb)
922fbb7b
AC
35119@end smallexample
35120
a2c02241
NR
35121@subheading The @code{-file-list-shared-libraries} Command
35122@findex -file-list-shared-libraries
922fbb7b 35123
a2c02241 35124@subsubheading Synopsis
922fbb7b 35125
a2c02241 35126@smallexample
51457a05 35127 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 35128@end smallexample
922fbb7b 35129
a2c02241 35130List the shared libraries in the program.
51457a05
MAL
35131With a regular expression @var{regexp}, only those libraries whose
35132names match @var{regexp} are listed.
922fbb7b 35133
a2c02241 35134@subsubheading @value{GDBN} Command
922fbb7b 35135
51457a05
MAL
35136The corresponding @value{GDBN} command is @samp{info shared}. The fields
35137have a similar meaning to the @code{=library-loaded} notification.
35138The @code{ranges} field specifies the multiple segments belonging to this
35139library. Each range has the following fields:
35140
35141@table @samp
35142@item from
35143The address defining the inclusive lower bound of the segment.
35144@item to
35145The address defining the exclusive upper bound of the segment.
35146@end table
922fbb7b 35147
a2c02241 35148@subsubheading Example
51457a05
MAL
35149@smallexample
35150(gdb)
35151-file-list-exec-source-files
35152^done,shared-libraries=[
35153@{id="/lib/libfoo.so",target-name="/lib/libfoo.so",host-name="/lib/libfoo.so",symbols-loaded="1",thread-group="i1",ranges=[@{from="0x72815989",to="0x728162c0"@}]@},
35154@{id="/lib/libbar.so",target-name="/lib/libbar.so",host-name="/lib/libbar.so",symbols-loaded="1",thread-group="i1",ranges=[@{from="0x76ee48c0",to="0x76ee9160"@}]@}]
35155(gdb)
35156@end smallexample
922fbb7b
AC
35157
35158
51457a05 35159@ignore
a2c02241
NR
35160@subheading The @code{-file-list-symbol-files} Command
35161@findex -file-list-symbol-files
922fbb7b 35162
a2c02241 35163@subsubheading Synopsis
922fbb7b 35164
a2c02241
NR
35165@smallexample
35166 -file-list-symbol-files
35167@end smallexample
922fbb7b 35168
a2c02241 35169List symbol files.
922fbb7b 35170
a2c02241 35171@subsubheading @value{GDBN} Command
922fbb7b 35172
a2c02241 35173The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 35174
a2c02241
NR
35175@subsubheading Example
35176N.A.
9901a55b 35177@end ignore
922fbb7b 35178
922fbb7b 35179
a2c02241
NR
35180@subheading The @code{-file-symbol-file} Command
35181@findex -file-symbol-file
922fbb7b 35182
a2c02241 35183@subsubheading Synopsis
922fbb7b 35184
a2c02241
NR
35185@smallexample
35186 -file-symbol-file @var{file}
35187@end smallexample
922fbb7b 35188
a2c02241
NR
35189Read symbol table info from the specified @var{file} argument. When
35190used without arguments, clears @value{GDBN}'s symbol table info. No output is
35191produced, except for a completion notification.
922fbb7b 35192
a2c02241 35193@subsubheading @value{GDBN} Command
922fbb7b 35194
a2c02241 35195The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 35196
a2c02241 35197@subsubheading Example
922fbb7b 35198
a2c02241 35199@smallexample
594fe323 35200(gdb)
a2c02241
NR
35201-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35202^done
594fe323 35203(gdb)
a2c02241 35204@end smallexample
922fbb7b 35205
a2c02241 35206@ignore
a2c02241
NR
35207@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35208@node GDB/MI Memory Overlay Commands
35209@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 35210
a2c02241 35211The memory overlay commands are not implemented.
922fbb7b 35212
a2c02241 35213@c @subheading -overlay-auto
922fbb7b 35214
a2c02241 35215@c @subheading -overlay-list-mapping-state
922fbb7b 35216
a2c02241 35217@c @subheading -overlay-list-overlays
922fbb7b 35218
a2c02241 35219@c @subheading -overlay-map
922fbb7b 35220
a2c02241 35221@c @subheading -overlay-off
922fbb7b 35222
a2c02241 35223@c @subheading -overlay-on
922fbb7b 35224
a2c02241 35225@c @subheading -overlay-unmap
922fbb7b 35226
a2c02241
NR
35227@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35228@node GDB/MI Signal Handling Commands
35229@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 35230
a2c02241 35231Signal handling commands are not implemented.
922fbb7b 35232
a2c02241 35233@c @subheading -signal-handle
922fbb7b 35234
a2c02241 35235@c @subheading -signal-list-handle-actions
922fbb7b 35236
a2c02241
NR
35237@c @subheading -signal-list-signal-types
35238@end ignore
922fbb7b 35239
922fbb7b 35240
a2c02241
NR
35241@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35242@node GDB/MI Target Manipulation
35243@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
35244
35245
a2c02241
NR
35246@subheading The @code{-target-attach} Command
35247@findex -target-attach
922fbb7b
AC
35248
35249@subsubheading Synopsis
35250
35251@smallexample
c3b108f7 35252 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
35253@end smallexample
35254
c3b108f7
VP
35255Attach to a process @var{pid} or a file @var{file} outside of
35256@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35257group, the id previously returned by
35258@samp{-list-thread-groups --available} must be used.
922fbb7b 35259
79a6e687 35260@subsubheading @value{GDBN} Command
922fbb7b 35261
a2c02241 35262The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 35263
a2c02241 35264@subsubheading Example
b56e7235
VP
35265@smallexample
35266(gdb)
35267-target-attach 34
35268=thread-created,id="1"
5ae4183a 35269*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35270^done
35271(gdb)
35272@end smallexample
a2c02241 35273
9901a55b 35274@ignore
a2c02241
NR
35275@subheading The @code{-target-compare-sections} Command
35276@findex -target-compare-sections
922fbb7b
AC
35277
35278@subsubheading Synopsis
35279
35280@smallexample
a2c02241 35281 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35282@end smallexample
35283
a2c02241
NR
35284Compare data of section @var{section} on target to the exec file.
35285Without the argument, all sections are compared.
922fbb7b 35286
a2c02241 35287@subsubheading @value{GDBN} Command
922fbb7b 35288
a2c02241 35289The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35290
a2c02241
NR
35291@subsubheading Example
35292N.A.
9901a55b 35293@end ignore
a2c02241
NR
35294
35295
35296@subheading The @code{-target-detach} Command
35297@findex -target-detach
922fbb7b
AC
35298
35299@subsubheading Synopsis
35300
35301@smallexample
c3b108f7 35302 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35303@end smallexample
35304
a2c02241 35305Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35306If either @var{pid} or @var{gid} is specified, detaches from either
35307the specified process, or specified thread group. There's no output.
a2c02241 35308
79a6e687 35309@subsubheading @value{GDBN} Command
a2c02241
NR
35310
35311The corresponding @value{GDBN} command is @samp{detach}.
35312
35313@subsubheading Example
922fbb7b
AC
35314
35315@smallexample
594fe323 35316(gdb)
a2c02241
NR
35317-target-detach
35318^done
594fe323 35319(gdb)
922fbb7b
AC
35320@end smallexample
35321
35322
a2c02241
NR
35323@subheading The @code{-target-disconnect} Command
35324@findex -target-disconnect
922fbb7b
AC
35325
35326@subsubheading Synopsis
35327
123dc839 35328@smallexample
a2c02241 35329 -target-disconnect
123dc839 35330@end smallexample
922fbb7b 35331
a2c02241
NR
35332Disconnect from the remote target. There's no output and the target is
35333generally not resumed.
35334
79a6e687 35335@subsubheading @value{GDBN} Command
a2c02241
NR
35336
35337The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35338
35339@subsubheading Example
922fbb7b
AC
35340
35341@smallexample
594fe323 35342(gdb)
a2c02241
NR
35343-target-disconnect
35344^done
594fe323 35345(gdb)
922fbb7b
AC
35346@end smallexample
35347
35348
a2c02241
NR
35349@subheading The @code{-target-download} Command
35350@findex -target-download
922fbb7b
AC
35351
35352@subsubheading Synopsis
35353
35354@smallexample
a2c02241 35355 -target-download
922fbb7b
AC
35356@end smallexample
35357
a2c02241
NR
35358Loads the executable onto the remote target.
35359It prints out an update message every half second, which includes the fields:
35360
35361@table @samp
35362@item section
35363The name of the section.
35364@item section-sent
35365The size of what has been sent so far for that section.
35366@item section-size
35367The size of the section.
35368@item total-sent
35369The total size of what was sent so far (the current and the previous sections).
35370@item total-size
35371The size of the overall executable to download.
35372@end table
35373
35374@noindent
35375Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35376@sc{gdb/mi} Output Syntax}).
35377
35378In addition, it prints the name and size of the sections, as they are
35379downloaded. These messages include the following fields:
35380
35381@table @samp
35382@item section
35383The name of the section.
35384@item section-size
35385The size of the section.
35386@item total-size
35387The size of the overall executable to download.
35388@end table
35389
35390@noindent
35391At the end, a summary is printed.
35392
35393@subsubheading @value{GDBN} Command
35394
35395The corresponding @value{GDBN} command is @samp{load}.
35396
35397@subsubheading Example
35398
35399Note: each status message appears on a single line. Here the messages
35400have been broken down so that they can fit onto a page.
922fbb7b
AC
35401
35402@smallexample
594fe323 35403(gdb)
a2c02241
NR
35404-target-download
35405+download,@{section=".text",section-size="6668",total-size="9880"@}
35406+download,@{section=".text",section-sent="512",section-size="6668",
35407total-sent="512",total-size="9880"@}
35408+download,@{section=".text",section-sent="1024",section-size="6668",
35409total-sent="1024",total-size="9880"@}
35410+download,@{section=".text",section-sent="1536",section-size="6668",
35411total-sent="1536",total-size="9880"@}
35412+download,@{section=".text",section-sent="2048",section-size="6668",
35413total-sent="2048",total-size="9880"@}
35414+download,@{section=".text",section-sent="2560",section-size="6668",
35415total-sent="2560",total-size="9880"@}
35416+download,@{section=".text",section-sent="3072",section-size="6668",
35417total-sent="3072",total-size="9880"@}
35418+download,@{section=".text",section-sent="3584",section-size="6668",
35419total-sent="3584",total-size="9880"@}
35420+download,@{section=".text",section-sent="4096",section-size="6668",
35421total-sent="4096",total-size="9880"@}
35422+download,@{section=".text",section-sent="4608",section-size="6668",
35423total-sent="4608",total-size="9880"@}
35424+download,@{section=".text",section-sent="5120",section-size="6668",
35425total-sent="5120",total-size="9880"@}
35426+download,@{section=".text",section-sent="5632",section-size="6668",
35427total-sent="5632",total-size="9880"@}
35428+download,@{section=".text",section-sent="6144",section-size="6668",
35429total-sent="6144",total-size="9880"@}
35430+download,@{section=".text",section-sent="6656",section-size="6668",
35431total-sent="6656",total-size="9880"@}
35432+download,@{section=".init",section-size="28",total-size="9880"@}
35433+download,@{section=".fini",section-size="28",total-size="9880"@}
35434+download,@{section=".data",section-size="3156",total-size="9880"@}
35435+download,@{section=".data",section-sent="512",section-size="3156",
35436total-sent="7236",total-size="9880"@}
35437+download,@{section=".data",section-sent="1024",section-size="3156",
35438total-sent="7748",total-size="9880"@}
35439+download,@{section=".data",section-sent="1536",section-size="3156",
35440total-sent="8260",total-size="9880"@}
35441+download,@{section=".data",section-sent="2048",section-size="3156",
35442total-sent="8772",total-size="9880"@}
35443+download,@{section=".data",section-sent="2560",section-size="3156",
35444total-sent="9284",total-size="9880"@}
35445+download,@{section=".data",section-sent="3072",section-size="3156",
35446total-sent="9796",total-size="9880"@}
35447^done,address="0x10004",load-size="9880",transfer-rate="6586",
35448write-rate="429"
594fe323 35449(gdb)
922fbb7b
AC
35450@end smallexample
35451
35452
9901a55b 35453@ignore
a2c02241
NR
35454@subheading The @code{-target-exec-status} Command
35455@findex -target-exec-status
922fbb7b
AC
35456
35457@subsubheading Synopsis
35458
35459@smallexample
a2c02241 35460 -target-exec-status
922fbb7b
AC
35461@end smallexample
35462
a2c02241
NR
35463Provide information on the state of the target (whether it is running or
35464not, for instance).
922fbb7b 35465
a2c02241 35466@subsubheading @value{GDBN} Command
922fbb7b 35467
a2c02241
NR
35468There's no equivalent @value{GDBN} command.
35469
35470@subsubheading Example
35471N.A.
922fbb7b 35472
a2c02241
NR
35473
35474@subheading The @code{-target-list-available-targets} Command
35475@findex -target-list-available-targets
922fbb7b
AC
35476
35477@subsubheading Synopsis
35478
35479@smallexample
a2c02241 35480 -target-list-available-targets
922fbb7b
AC
35481@end smallexample
35482
a2c02241 35483List the possible targets to connect to.
922fbb7b 35484
a2c02241 35485@subsubheading @value{GDBN} Command
922fbb7b 35486
a2c02241 35487The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35488
a2c02241
NR
35489@subsubheading Example
35490N.A.
35491
35492
35493@subheading The @code{-target-list-current-targets} Command
35494@findex -target-list-current-targets
922fbb7b
AC
35495
35496@subsubheading Synopsis
35497
35498@smallexample
a2c02241 35499 -target-list-current-targets
922fbb7b
AC
35500@end smallexample
35501
a2c02241 35502Describe the current target.
922fbb7b 35503
a2c02241 35504@subsubheading @value{GDBN} Command
922fbb7b 35505
a2c02241
NR
35506The corresponding information is printed by @samp{info file} (among
35507other things).
922fbb7b 35508
a2c02241
NR
35509@subsubheading Example
35510N.A.
35511
35512
35513@subheading The @code{-target-list-parameters} Command
35514@findex -target-list-parameters
922fbb7b
AC
35515
35516@subsubheading Synopsis
35517
35518@smallexample
a2c02241 35519 -target-list-parameters
922fbb7b
AC
35520@end smallexample
35521
a2c02241 35522@c ????
9901a55b 35523@end ignore
a2c02241
NR
35524
35525@subsubheading @value{GDBN} Command
35526
35527No equivalent.
922fbb7b
AC
35528
35529@subsubheading Example
a2c02241
NR
35530N.A.
35531
78cbbba8
LM
35532@subheading The @code{-target-flash-erase} Command
35533@findex -target-flash-erase
35534
35535@subsubheading Synopsis
35536
35537@smallexample
35538 -target-flash-erase
35539@end smallexample
35540
35541Erases all known flash memory regions on the target.
35542
35543The corresponding @value{GDBN} command is @samp{flash-erase}.
35544
35545The output is a list of flash regions that have been erased, with starting
35546addresses and memory region sizes.
35547
35548@smallexample
35549(gdb)
35550-target-flash-erase
35551^done,erased-regions=@{address="0x0",size="0x40000"@}
35552(gdb)
35553@end smallexample
a2c02241
NR
35554
35555@subheading The @code{-target-select} Command
35556@findex -target-select
35557
35558@subsubheading Synopsis
922fbb7b
AC
35559
35560@smallexample
a2c02241 35561 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35562@end smallexample
35563
a2c02241 35564Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35565
a2c02241
NR
35566@table @samp
35567@item @var{type}
75c99385 35568The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35569@item @var{parameters}
35570Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35571Commands for Managing Targets}, for more details.
a2c02241
NR
35572@end table
35573
35574The output is a connection notification, followed by the address at
35575which the target program is, in the following form:
922fbb7b
AC
35576
35577@smallexample
a2c02241
NR
35578^connected,addr="@var{address}",func="@var{function name}",
35579 args=[@var{arg list}]
922fbb7b
AC
35580@end smallexample
35581
a2c02241
NR
35582@subsubheading @value{GDBN} Command
35583
35584The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35585
35586@subsubheading Example
922fbb7b 35587
265eeb58 35588@smallexample
594fe323 35589(gdb)
75c99385 35590-target-select remote /dev/ttya
a2c02241 35591^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35592(gdb)
265eeb58 35593@end smallexample
ef21caaf 35594
a6b151f1
DJ
35595@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35596@node GDB/MI File Transfer Commands
35597@section @sc{gdb/mi} File Transfer Commands
35598
35599
35600@subheading The @code{-target-file-put} Command
35601@findex -target-file-put
35602
35603@subsubheading Synopsis
35604
35605@smallexample
35606 -target-file-put @var{hostfile} @var{targetfile}
35607@end smallexample
35608
35609Copy file @var{hostfile} from the host system (the machine running
35610@value{GDBN}) to @var{targetfile} on the target system.
35611
35612@subsubheading @value{GDBN} Command
35613
35614The corresponding @value{GDBN} command is @samp{remote put}.
35615
35616@subsubheading Example
35617
35618@smallexample
35619(gdb)
35620-target-file-put localfile remotefile
35621^done
35622(gdb)
35623@end smallexample
35624
35625
1763a388 35626@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35627@findex -target-file-get
35628
35629@subsubheading Synopsis
35630
35631@smallexample
35632 -target-file-get @var{targetfile} @var{hostfile}
35633@end smallexample
35634
35635Copy file @var{targetfile} from the target system to @var{hostfile}
35636on the host system.
35637
35638@subsubheading @value{GDBN} Command
35639
35640The corresponding @value{GDBN} command is @samp{remote get}.
35641
35642@subsubheading Example
35643
35644@smallexample
35645(gdb)
35646-target-file-get remotefile localfile
35647^done
35648(gdb)
35649@end smallexample
35650
35651
35652@subheading The @code{-target-file-delete} Command
35653@findex -target-file-delete
35654
35655@subsubheading Synopsis
35656
35657@smallexample
35658 -target-file-delete @var{targetfile}
35659@end smallexample
35660
35661Delete @var{targetfile} from the target system.
35662
35663@subsubheading @value{GDBN} Command
35664
35665The corresponding @value{GDBN} command is @samp{remote delete}.
35666
35667@subsubheading Example
35668
35669@smallexample
35670(gdb)
35671-target-file-delete remotefile
35672^done
35673(gdb)
35674@end smallexample
35675
35676
58d06528
JB
35677@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35678@node GDB/MI Ada Exceptions Commands
35679@section Ada Exceptions @sc{gdb/mi} Commands
35680
35681@subheading The @code{-info-ada-exceptions} Command
35682@findex -info-ada-exceptions
35683
35684@subsubheading Synopsis
35685
35686@smallexample
35687 -info-ada-exceptions [ @var{regexp}]
35688@end smallexample
35689
35690List all Ada exceptions defined within the program being debugged.
35691With a regular expression @var{regexp}, only those exceptions whose
35692names match @var{regexp} are listed.
35693
35694@subsubheading @value{GDBN} Command
35695
35696The corresponding @value{GDBN} command is @samp{info exceptions}.
35697
35698@subsubheading Result
35699
35700The result is a table of Ada exceptions. The following columns are
35701defined for each exception:
35702
35703@table @samp
35704@item name
35705The name of the exception.
35706
35707@item address
35708The address of the exception.
35709
35710@end table
35711
35712@subsubheading Example
35713
35714@smallexample
35715-info-ada-exceptions aint
35716^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35717hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35718@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35719body=[@{name="constraint_error",address="0x0000000000613da0"@},
35720@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35721@end smallexample
35722
35723@subheading Catching Ada Exceptions
35724
35725The commands describing how to ask @value{GDBN} to stop when a program
35726raises an exception are described at @ref{Ada Exception GDB/MI
35727Catchpoint Commands}.
35728
35729
ef21caaf 35730@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35731@node GDB/MI Support Commands
35732@section @sc{gdb/mi} Support Commands
ef21caaf 35733
d192b373
JB
35734Since new commands and features get regularly added to @sc{gdb/mi},
35735some commands are available to help front-ends query the debugger
35736about support for these capabilities. Similarly, it is also possible
35737to query @value{GDBN} about target support of certain features.
ef21caaf 35738
6b7cbff1
JB
35739@subheading The @code{-info-gdb-mi-command} Command
35740@cindex @code{-info-gdb-mi-command}
35741@findex -info-gdb-mi-command
35742
35743@subsubheading Synopsis
35744
35745@smallexample
35746 -info-gdb-mi-command @var{cmd_name}
35747@end smallexample
35748
35749Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35750
35751Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35752is technically not part of the command name (@pxref{GDB/MI Input
35753Syntax}), and thus should be omitted in @var{cmd_name}. However,
35754for ease of use, this command also accepts the form with the leading
35755dash.
35756
35757@subsubheading @value{GDBN} Command
35758
35759There is no corresponding @value{GDBN} command.
35760
35761@subsubheading Result
35762
35763The result is a tuple. There is currently only one field:
35764
35765@table @samp
35766@item exists
35767This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35768@code{"false"} otherwise.
35769
35770@end table
35771
35772@subsubheading Example
35773
35774Here is an example where the @sc{gdb/mi} command does not exist:
35775
35776@smallexample
35777-info-gdb-mi-command unsupported-command
35778^done,command=@{exists="false"@}
35779@end smallexample
35780
35781@noindent
35782And here is an example where the @sc{gdb/mi} command is known
35783to the debugger:
35784
35785@smallexample
35786-info-gdb-mi-command symbol-list-lines
35787^done,command=@{exists="true"@}
35788@end smallexample
35789
084344da
VP
35790@subheading The @code{-list-features} Command
35791@findex -list-features
9b26f0fb 35792@cindex supported @sc{gdb/mi} features, list
084344da
VP
35793
35794Returns a list of particular features of the MI protocol that
35795this version of gdb implements. A feature can be a command,
35796or a new field in an output of some command, or even an
35797important bugfix. While a frontend can sometimes detect presence
35798of a feature at runtime, it is easier to perform detection at debugger
d192b373 35799startup.
084344da
VP
35800
35801The command returns a list of strings, with each string naming an
35802available feature. Each returned string is just a name, it does not
d192b373 35803have any internal structure. The list of possible feature names
084344da
VP
35804is given below.
35805
35806Example output:
35807
35808@smallexample
35809(gdb) -list-features
35810^done,result=["feature1","feature2"]
35811@end smallexample
35812
35813The current list of features is:
35814
edef6000 35815@ftable @samp
30e026bb 35816@item frozen-varobjs
a05336a1 35817Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 35818as possible presence of the @code{frozen} field in the output
30e026bb
VP
35819of @code{-varobj-create}.
35820@item pending-breakpoints
a05336a1
JB
35821Indicates support for the @option{-f} option to the @code{-break-insert}
35822command.
b6313243 35823@item python
a05336a1 35824Indicates Python scripting support, Python-based
b6313243
TT
35825pretty-printing commands, and possible presence of the
35826@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 35827@item thread-info
a05336a1 35828Indicates support for the @code{-thread-info} command.
8dedea02 35829@item data-read-memory-bytes
a05336a1 35830Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 35831@code{-data-write-memory-bytes} commands.
39c4d40a
TT
35832@item breakpoint-notifications
35833Indicates that changes to breakpoints and breakpoints created via the
35834CLI will be announced via async records.
5d77fe44 35835@item ada-task-info
6adcee18 35836Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
35837@item language-option
35838Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35839option (@pxref{Context management}).
6b7cbff1
JB
35840@item info-gdb-mi-command
35841Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
35842@item undefined-command-error-code
35843Indicates support for the "undefined-command" error code in error result
35844records, produced when trying to execute an undefined @sc{gdb/mi} command
35845(@pxref{GDB/MI Result Records}).
72bfa06c
JB
35846@item exec-run-start-option
35847Indicates that the @code{-exec-run} command supports the @option{--start}
35848option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
35849@item data-disassemble-a-option
35850Indicates that the @code{-data-disassemble} command supports the @option{-a}
35851option (@pxref{GDB/MI Data Manipulation}).
edef6000 35852@end ftable
084344da 35853
c6ebd6cf
VP
35854@subheading The @code{-list-target-features} Command
35855@findex -list-target-features
35856
35857Returns a list of particular features that are supported by the
35858target. Those features affect the permitted MI commands, but
35859unlike the features reported by the @code{-list-features} command, the
35860features depend on which target GDB is using at the moment. Whenever
35861a target can change, due to commands such as @code{-target-select},
35862@code{-target-attach} or @code{-exec-run}, the list of target features
35863may change, and the frontend should obtain it again.
35864Example output:
35865
35866@smallexample
b3d3b4bd 35867(gdb) -list-target-features
c6ebd6cf
VP
35868^done,result=["async"]
35869@end smallexample
35870
35871The current list of features is:
35872
35873@table @samp
35874@item async
35875Indicates that the target is capable of asynchronous command
35876execution, which means that @value{GDBN} will accept further commands
35877while the target is running.
35878
f75d858b
MK
35879@item reverse
35880Indicates that the target is capable of reverse execution.
35881@xref{Reverse Execution}, for more information.
35882
c6ebd6cf
VP
35883@end table
35884
d192b373
JB
35885@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35886@node GDB/MI Miscellaneous Commands
35887@section Miscellaneous @sc{gdb/mi} Commands
35888
35889@c @subheading -gdb-complete
35890
35891@subheading The @code{-gdb-exit} Command
35892@findex -gdb-exit
35893
35894@subsubheading Synopsis
35895
35896@smallexample
35897 -gdb-exit
35898@end smallexample
35899
35900Exit @value{GDBN} immediately.
35901
35902@subsubheading @value{GDBN} Command
35903
35904Approximately corresponds to @samp{quit}.
35905
35906@subsubheading Example
35907
35908@smallexample
35909(gdb)
35910-gdb-exit
35911^exit
35912@end smallexample
35913
35914
35915@ignore
35916@subheading The @code{-exec-abort} Command
35917@findex -exec-abort
35918
35919@subsubheading Synopsis
35920
35921@smallexample
35922 -exec-abort
35923@end smallexample
35924
35925Kill the inferior running program.
35926
35927@subsubheading @value{GDBN} Command
35928
35929The corresponding @value{GDBN} command is @samp{kill}.
35930
35931@subsubheading Example
35932N.A.
35933@end ignore
35934
35935
35936@subheading The @code{-gdb-set} Command
35937@findex -gdb-set
35938
35939@subsubheading Synopsis
35940
35941@smallexample
35942 -gdb-set
35943@end smallexample
35944
35945Set an internal @value{GDBN} variable.
35946@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35947
35948@subsubheading @value{GDBN} Command
35949
35950The corresponding @value{GDBN} command is @samp{set}.
35951
35952@subsubheading Example
35953
35954@smallexample
35955(gdb)
35956-gdb-set $foo=3
35957^done
35958(gdb)
35959@end smallexample
35960
35961
35962@subheading The @code{-gdb-show} Command
35963@findex -gdb-show
35964
35965@subsubheading Synopsis
35966
35967@smallexample
35968 -gdb-show
35969@end smallexample
35970
35971Show the current value of a @value{GDBN} variable.
35972
35973@subsubheading @value{GDBN} Command
35974
35975The corresponding @value{GDBN} command is @samp{show}.
35976
35977@subsubheading Example
35978
35979@smallexample
35980(gdb)
35981-gdb-show annotate
35982^done,value="0"
35983(gdb)
35984@end smallexample
35985
35986@c @subheading -gdb-source
35987
35988
35989@subheading The @code{-gdb-version} Command
35990@findex -gdb-version
35991
35992@subsubheading Synopsis
35993
35994@smallexample
35995 -gdb-version
35996@end smallexample
35997
35998Show version information for @value{GDBN}. Used mostly in testing.
35999
36000@subsubheading @value{GDBN} Command
36001
36002The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36003default shows this information when you start an interactive session.
36004
36005@subsubheading Example
36006
36007@c This example modifies the actual output from GDB to avoid overfull
36008@c box in TeX.
36009@smallexample
36010(gdb)
36011-gdb-version
36012~GNU gdb 5.2.1
36013~Copyright 2000 Free Software Foundation, Inc.
36014~GDB is free software, covered by the GNU General Public License, and
36015~you are welcome to change it and/or distribute copies of it under
36016~ certain conditions.
36017~Type "show copying" to see the conditions.
36018~There is absolutely no warranty for GDB. Type "show warranty" for
36019~ details.
36020~This GDB was configured as
36021 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36022^done
36023(gdb)
36024@end smallexample
36025
c3b108f7
VP
36026@subheading The @code{-list-thread-groups} Command
36027@findex -list-thread-groups
36028
36029@subheading Synopsis
36030
36031@smallexample
dc146f7c 36032-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
36033@end smallexample
36034
dc146f7c
VP
36035Lists thread groups (@pxref{Thread groups}). When a single thread
36036group is passed as the argument, lists the children of that group.
36037When several thread group are passed, lists information about those
36038thread groups. Without any parameters, lists information about all
36039top-level thread groups.
36040
36041Normally, thread groups that are being debugged are reported.
36042With the @samp{--available} option, @value{GDBN} reports thread groups
36043available on the target.
36044
36045The output of this command may have either a @samp{threads} result or
36046a @samp{groups} result. The @samp{thread} result has a list of tuples
36047as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36048Information}). The @samp{groups} result has a list of tuples as value,
36049each tuple describing a thread group. If top-level groups are
36050requested (that is, no parameter is passed), or when several groups
36051are passed, the output always has a @samp{groups} result. The format
36052of the @samp{group} result is described below.
36053
36054To reduce the number of roundtrips it's possible to list thread groups
36055together with their children, by passing the @samp{--recurse} option
36056and the recursion depth. Presently, only recursion depth of 1 is
36057permitted. If this option is present, then every reported thread group
36058will also include its children, either as @samp{group} or
36059@samp{threads} field.
36060
36061In general, any combination of option and parameters is permitted, with
36062the following caveats:
36063
36064@itemize @bullet
36065@item
36066When a single thread group is passed, the output will typically
36067be the @samp{threads} result. Because threads may not contain
36068anything, the @samp{recurse} option will be ignored.
36069
36070@item
36071When the @samp{--available} option is passed, limited information may
36072be available. In particular, the list of threads of a process might
36073be inaccessible. Further, specifying specific thread groups might
36074not give any performance advantage over listing all thread groups.
36075The frontend should assume that @samp{-list-thread-groups --available}
36076is always an expensive operation and cache the results.
36077
36078@end itemize
36079
36080The @samp{groups} result is a list of tuples, where each tuple may
36081have the following fields:
36082
36083@table @code
36084@item id
36085Identifier of the thread group. This field is always present.
a79b8f6e
VP
36086The identifier is an opaque string; frontends should not try to
36087convert it to an integer, even though it might look like one.
dc146f7c
VP
36088
36089@item type
36090The type of the thread group. At present, only @samp{process} is a
36091valid type.
36092
36093@item pid
36094The target-specific process identifier. This field is only present
a79b8f6e 36095for thread groups of type @samp{process} and only if the process exists.
c3b108f7 36096
2ddf4301
SM
36097@item exit-code
36098The exit code of this group's last exited thread, formatted in octal.
36099This field is only present for thread groups of type @samp{process} and
36100only if the process is not running.
36101
dc146f7c
VP
36102@item num_children
36103The number of children this thread group has. This field may be
36104absent for an available thread group.
36105
36106@item threads
36107This field has a list of tuples as value, each tuple describing a
36108thread. It may be present if the @samp{--recurse} option is
36109specified, and it's actually possible to obtain the threads.
36110
36111@item cores
36112This field is a list of integers, each identifying a core that one
36113thread of the group is running on. This field may be absent if
36114such information is not available.
36115
a79b8f6e
VP
36116@item executable
36117The name of the executable file that corresponds to this thread group.
36118The field is only present for thread groups of type @samp{process},
36119and only if there is a corresponding executable file.
36120
dc146f7c 36121@end table
c3b108f7
VP
36122
36123@subheading Example
36124
36125@smallexample
36126@value{GDBP}
36127-list-thread-groups
36128^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36129-list-thread-groups 17
36130^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36131 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36132@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36133 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 36134 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
36135-list-thread-groups --available
36136^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36137-list-thread-groups --available --recurse 1
36138 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36139 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36140 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36141-list-thread-groups --available --recurse 1 17 18
36142^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36143 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36144 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 36145@end smallexample
c6ebd6cf 36146
f3e0e960
SS
36147@subheading The @code{-info-os} Command
36148@findex -info-os
36149
36150@subsubheading Synopsis
36151
36152@smallexample
36153-info-os [ @var{type} ]
36154@end smallexample
36155
36156If no argument is supplied, the command returns a table of available
36157operating-system-specific information types. If one of these types is
36158supplied as an argument @var{type}, then the command returns a table
36159of data of that type.
36160
36161The types of information available depend on the target operating
36162system.
36163
36164@subsubheading @value{GDBN} Command
36165
36166The corresponding @value{GDBN} command is @samp{info os}.
36167
36168@subsubheading Example
36169
36170When run on a @sc{gnu}/Linux system, the output will look something
36171like this:
36172
36173@smallexample
36174@value{GDBP}
36175-info-os
d33279b3 36176^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 36177hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
36178 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36179 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
36180body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36181 col2="CPUs"@},
36182 item=@{col0="files",col1="Listing of all file descriptors",
36183 col2="File descriptors"@},
36184 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36185 col2="Kernel modules"@},
36186 item=@{col0="msg",col1="Listing of all message queues",
36187 col2="Message queues"@},
36188 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
36189 col2="Processes"@},
36190 item=@{col0="procgroups",col1="Listing of all process groups",
36191 col2="Process groups"@},
71caed83
SS
36192 item=@{col0="semaphores",col1="Listing of all semaphores",
36193 col2="Semaphores"@},
d33279b3
AT
36194 item=@{col0="shm",col1="Listing of all shared-memory regions",
36195 col2="Shared-memory regions"@},
36196 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36197 col2="Sockets"@},
36198 item=@{col0="threads",col1="Listing of all threads",
36199 col2="Threads"@}]
f3e0e960
SS
36200@value{GDBP}
36201-info-os processes
36202^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36203hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36204 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36205 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36206 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36207body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36208 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36209 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36210 ...
36211 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36212 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36213(gdb)
36214@end smallexample
a79b8f6e 36215
71caed83
SS
36216(Note that the MI output here includes a @code{"Title"} column that
36217does not appear in command-line @code{info os}; this column is useful
36218for MI clients that want to enumerate the types of data, such as in a
36219popup menu, but is needless clutter on the command line, and
36220@code{info os} omits it.)
36221
a79b8f6e
VP
36222@subheading The @code{-add-inferior} Command
36223@findex -add-inferior
36224
36225@subheading Synopsis
36226
36227@smallexample
36228-add-inferior
36229@end smallexample
36230
65c574f6 36231Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
36232inferior is not associated with any executable. Such association may
36233be established with the @samp{-file-exec-and-symbols} command
36234(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 36235field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
36236thread group corresponding to the new inferior.
36237
36238@subheading Example
36239
36240@smallexample
36241@value{GDBP}
36242-add-inferior
b7742092 36243^done,inferior="i3"
a79b8f6e
VP
36244@end smallexample
36245
ef21caaf
NR
36246@subheading The @code{-interpreter-exec} Command
36247@findex -interpreter-exec
36248
36249@subheading Synopsis
36250
36251@smallexample
36252-interpreter-exec @var{interpreter} @var{command}
36253@end smallexample
a2c02241 36254@anchor{-interpreter-exec}
ef21caaf
NR
36255
36256Execute the specified @var{command} in the given @var{interpreter}.
36257
36258@subheading @value{GDBN} Command
36259
36260The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36261
36262@subheading Example
36263
36264@smallexample
594fe323 36265(gdb)
ef21caaf
NR
36266-interpreter-exec console "break main"
36267&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36268&"During symbol reading, bad structure-type format.\n"
36269~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36270^done
594fe323 36271(gdb)
ef21caaf
NR
36272@end smallexample
36273
36274@subheading The @code{-inferior-tty-set} Command
36275@findex -inferior-tty-set
36276
36277@subheading Synopsis
36278
36279@smallexample
36280-inferior-tty-set /dev/pts/1
36281@end smallexample
36282
36283Set terminal for future runs of the program being debugged.
36284
36285@subheading @value{GDBN} Command
36286
36287The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36288
36289@subheading Example
36290
36291@smallexample
594fe323 36292(gdb)
ef21caaf
NR
36293-inferior-tty-set /dev/pts/1
36294^done
594fe323 36295(gdb)
ef21caaf
NR
36296@end smallexample
36297
36298@subheading The @code{-inferior-tty-show} Command
36299@findex -inferior-tty-show
36300
36301@subheading Synopsis
36302
36303@smallexample
36304-inferior-tty-show
36305@end smallexample
36306
36307Show terminal for future runs of program being debugged.
36308
36309@subheading @value{GDBN} Command
36310
36311The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36312
36313@subheading Example
36314
36315@smallexample
594fe323 36316(gdb)
ef21caaf
NR
36317-inferior-tty-set /dev/pts/1
36318^done
594fe323 36319(gdb)
ef21caaf
NR
36320-inferior-tty-show
36321^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36322(gdb)
ef21caaf 36323@end smallexample
922fbb7b 36324
a4eefcd8
NR
36325@subheading The @code{-enable-timings} Command
36326@findex -enable-timings
36327
36328@subheading Synopsis
36329
36330@smallexample
36331-enable-timings [yes | no]
36332@end smallexample
36333
36334Toggle the printing of the wallclock, user and system times for an MI
36335command as a field in its output. This command is to help frontend
36336developers optimize the performance of their code. No argument is
36337equivalent to @samp{yes}.
36338
36339@subheading @value{GDBN} Command
36340
36341No equivalent.
36342
36343@subheading Example
36344
36345@smallexample
36346(gdb)
36347-enable-timings
36348^done
36349(gdb)
36350-break-insert main
36351^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36352addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36353fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36354times="0"@},
a4eefcd8
NR
36355time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36356(gdb)
36357-enable-timings no
36358^done
36359(gdb)
36360-exec-run
36361^running
36362(gdb)
a47ec5fe 36363*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36364frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36365@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36366fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36367(gdb)
36368@end smallexample
36369
26648588
JV
36370@subheading The @code{-complete} Command
36371@findex -complete
36372
36373@subheading Synopsis
36374
36375@smallexample
36376-complete @var{command}
36377@end smallexample
36378
36379Show a list of completions for partially typed CLI @var{command}.
36380
36381This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36382CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36383because @value{GDBN} is used remotely via a SSH connection.
36384
36385@subheading Result
36386
36387The result consists of two or three fields:
36388
36389@table @samp
36390@item completion
36391This field contains the completed @var{command}. If @var{command}
36392has no known completions, this field is omitted.
36393
36394@item matches
36395This field contains a (possibly empty) array of matches. It is always present.
36396
36397@item max_completions_reached
36398This field contains @code{1} if number of known completions is above
7166f90a 36399@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36400@code{0}. It is always present.
36401
36402@end table
36403
36404@subheading @value{GDBN} Command
36405
36406The corresponding @value{GDBN} command is @samp{complete}.
36407
36408@subheading Example
36409
36410@smallexample
36411(gdb)
36412-complete br
36413^done,completion="break",
36414 matches=["break","break-range"],
36415 max_completions_reached="0"
36416(gdb)
36417-complete "b ma"
36418^done,completion="b ma",
36419 matches=["b madvise","b main"],max_completions_reached="0"
36420(gdb)
36421-complete "b push_b"
36422^done,completion="b push_back(",
36423 matches=[
36424 "b A::push_back(void*)",
36425 "b std::string::push_back(char)",
36426 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36427 max_completions_reached="0"
36428(gdb)
36429-complete "nonexist"
36430^done,matches=[],max_completions_reached="0"
36431(gdb)
36432
36433@end smallexample
36434
922fbb7b
AC
36435@node Annotations
36436@chapter @value{GDBN} Annotations
36437
086432e2
AC
36438This chapter describes annotations in @value{GDBN}. Annotations were
36439designed to interface @value{GDBN} to graphical user interfaces or other
36440similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36441relatively high level.
36442
d3e8051b 36443The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36444(@pxref{GDB/MI}).
36445
922fbb7b
AC
36446@ignore
36447This is Edition @value{EDITION}, @value{DATE}.
36448@end ignore
36449
36450@menu
36451* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36452* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36453* Prompting:: Annotations marking @value{GDBN}'s need for input.
36454* Errors:: Annotations for error messages.
922fbb7b
AC
36455* Invalidation:: Some annotations describe things now invalid.
36456* Annotations for Running::
36457 Whether the program is running, how it stopped, etc.
36458* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36459@end menu
36460
36461@node Annotations Overview
36462@section What is an Annotation?
36463@cindex annotations
36464
922fbb7b
AC
36465Annotations start with a newline character, two @samp{control-z}
36466characters, and the name of the annotation. If there is no additional
36467information associated with this annotation, the name of the annotation
36468is followed immediately by a newline. If there is additional
36469information, the name of the annotation is followed by a space, the
36470additional information, and a newline. The additional information
36471cannot contain newline characters.
36472
36473Any output not beginning with a newline and two @samp{control-z}
36474characters denotes literal output from @value{GDBN}. Currently there is
36475no need for @value{GDBN} to output a newline followed by two
36476@samp{control-z} characters, but if there was such a need, the
36477annotations could be extended with an @samp{escape} annotation which
36478means those three characters as output.
36479
086432e2
AC
36480The annotation @var{level}, which is specified using the
36481@option{--annotate} command line option (@pxref{Mode Options}), controls
36482how much information @value{GDBN} prints together with its prompt,
36483values of expressions, source lines, and other types of output. Level 0
d3e8051b 36484is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36485subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36486for programs that control @value{GDBN}, and level 2 annotations have
36487been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36488Interface, annotate, GDB's Obsolete Annotations}).
36489
36490@table @code
36491@kindex set annotate
36492@item set annotate @var{level}
e09f16f9 36493The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36494annotations to the specified @var{level}.
9c16f35a
EZ
36495
36496@item show annotate
36497@kindex show annotate
36498Show the current annotation level.
09d4efe1
EZ
36499@end table
36500
36501This chapter describes level 3 annotations.
086432e2 36502
922fbb7b
AC
36503A simple example of starting up @value{GDBN} with annotations is:
36504
36505@smallexample
086432e2
AC
36506$ @kbd{gdb --annotate=3}
36507GNU gdb 6.0
36508Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36509GDB is free software, covered by the GNU General Public License,
36510and you are welcome to change it and/or distribute copies of it
36511under certain conditions.
36512Type "show copying" to see the conditions.
36513There is absolutely no warranty for GDB. Type "show warranty"
36514for details.
086432e2 36515This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36516
36517^Z^Zpre-prompt
f7dc1244 36518(@value{GDBP})
922fbb7b 36519^Z^Zprompt
086432e2 36520@kbd{quit}
922fbb7b
AC
36521
36522^Z^Zpost-prompt
b383017d 36523$
922fbb7b
AC
36524@end smallexample
36525
36526Here @samp{quit} is input to @value{GDBN}; the rest is output from
36527@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36528denotes a @samp{control-z} character) are annotations; the rest is
36529output from @value{GDBN}.
36530
9e6c4bd5
NR
36531@node Server Prefix
36532@section The Server Prefix
36533@cindex server prefix
36534
36535If you prefix a command with @samp{server } then it will not affect
36536the command history, nor will it affect @value{GDBN}'s notion of which
36537command to repeat if @key{RET} is pressed on a line by itself. This
36538means that commands can be run behind a user's back by a front-end in
36539a transparent manner.
36540
d837706a
NR
36541The @code{server } prefix does not affect the recording of values into
36542the value history; to print a value without recording it into the
36543value history, use the @code{output} command instead of the
36544@code{print} command.
36545
36546Using this prefix also disables confirmation requests
36547(@pxref{confirmation requests}).
9e6c4bd5 36548
922fbb7b
AC
36549@node Prompting
36550@section Annotation for @value{GDBN} Input
36551
36552@cindex annotations for prompts
36553When @value{GDBN} prompts for input, it annotates this fact so it is possible
36554to know when to send output, when the output from a given command is
36555over, etc.
36556
36557Different kinds of input each have a different @dfn{input type}. Each
36558input type has three annotations: a @code{pre-} annotation, which
36559denotes the beginning of any prompt which is being output, a plain
36560annotation, which denotes the end of the prompt, and then a @code{post-}
36561annotation which denotes the end of any echo which may (or may not) be
36562associated with the input. For example, the @code{prompt} input type
36563features the following annotations:
36564
36565@smallexample
36566^Z^Zpre-prompt
36567^Z^Zprompt
36568^Z^Zpost-prompt
36569@end smallexample
36570
36571The input types are
36572
36573@table @code
e5ac9b53
EZ
36574@findex pre-prompt annotation
36575@findex prompt annotation
36576@findex post-prompt annotation
922fbb7b
AC
36577@item prompt
36578When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36579
e5ac9b53
EZ
36580@findex pre-commands annotation
36581@findex commands annotation
36582@findex post-commands annotation
922fbb7b
AC
36583@item commands
36584When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36585command. The annotations are repeated for each command which is input.
36586
e5ac9b53
EZ
36587@findex pre-overload-choice annotation
36588@findex overload-choice annotation
36589@findex post-overload-choice annotation
922fbb7b
AC
36590@item overload-choice
36591When @value{GDBN} wants the user to select between various overloaded functions.
36592
e5ac9b53
EZ
36593@findex pre-query annotation
36594@findex query annotation
36595@findex post-query annotation
922fbb7b
AC
36596@item query
36597When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36598
e5ac9b53
EZ
36599@findex pre-prompt-for-continue annotation
36600@findex prompt-for-continue annotation
36601@findex post-prompt-for-continue annotation
922fbb7b
AC
36602@item prompt-for-continue
36603When @value{GDBN} is asking the user to press return to continue. Note: Don't
36604expect this to work well; instead use @code{set height 0} to disable
36605prompting. This is because the counting of lines is buggy in the
36606presence of annotations.
36607@end table
36608
36609@node Errors
36610@section Errors
36611@cindex annotations for errors, warnings and interrupts
36612
e5ac9b53 36613@findex quit annotation
922fbb7b
AC
36614@smallexample
36615^Z^Zquit
36616@end smallexample
36617
36618This annotation occurs right before @value{GDBN} responds to an interrupt.
36619
e5ac9b53 36620@findex error annotation
922fbb7b
AC
36621@smallexample
36622^Z^Zerror
36623@end smallexample
36624
36625This annotation occurs right before @value{GDBN} responds to an error.
36626
36627Quit and error annotations indicate that any annotations which @value{GDBN} was
36628in the middle of may end abruptly. For example, if a
36629@code{value-history-begin} annotation is followed by a @code{error}, one
36630cannot expect to receive the matching @code{value-history-end}. One
36631cannot expect not to receive it either, however; an error annotation
36632does not necessarily mean that @value{GDBN} is immediately returning all the way
36633to the top level.
36634
e5ac9b53 36635@findex error-begin annotation
922fbb7b
AC
36636A quit or error annotation may be preceded by
36637
36638@smallexample
36639^Z^Zerror-begin
36640@end smallexample
36641
36642Any output between that and the quit or error annotation is the error
36643message.
36644
36645Warning messages are not yet annotated.
36646@c If we want to change that, need to fix warning(), type_error(),
36647@c range_error(), and possibly other places.
36648
922fbb7b
AC
36649@node Invalidation
36650@section Invalidation Notices
36651
36652@cindex annotations for invalidation messages
36653The following annotations say that certain pieces of state may have
36654changed.
36655
36656@table @code
e5ac9b53 36657@findex frames-invalid annotation
922fbb7b
AC
36658@item ^Z^Zframes-invalid
36659
36660The frames (for example, output from the @code{backtrace} command) may
36661have changed.
36662
e5ac9b53 36663@findex breakpoints-invalid annotation
922fbb7b
AC
36664@item ^Z^Zbreakpoints-invalid
36665
36666The breakpoints may have changed. For example, the user just added or
36667deleted a breakpoint.
36668@end table
36669
36670@node Annotations for Running
36671@section Running the Program
36672@cindex annotations for running programs
36673
e5ac9b53
EZ
36674@findex starting annotation
36675@findex stopping annotation
922fbb7b 36676When the program starts executing due to a @value{GDBN} command such as
b383017d 36677@code{step} or @code{continue},
922fbb7b
AC
36678
36679@smallexample
36680^Z^Zstarting
36681@end smallexample
36682
b383017d 36683is output. When the program stops,
922fbb7b
AC
36684
36685@smallexample
36686^Z^Zstopped
36687@end smallexample
36688
36689is output. Before the @code{stopped} annotation, a variety of
36690annotations describe how the program stopped.
36691
36692@table @code
e5ac9b53 36693@findex exited annotation
922fbb7b
AC
36694@item ^Z^Zexited @var{exit-status}
36695The program exited, and @var{exit-status} is the exit status (zero for
36696successful exit, otherwise nonzero).
36697
e5ac9b53
EZ
36698@findex signalled annotation
36699@findex signal-name annotation
36700@findex signal-name-end annotation
36701@findex signal-string annotation
36702@findex signal-string-end annotation
922fbb7b
AC
36703@item ^Z^Zsignalled
36704The program exited with a signal. After the @code{^Z^Zsignalled}, the
36705annotation continues:
36706
36707@smallexample
36708@var{intro-text}
36709^Z^Zsignal-name
36710@var{name}
36711^Z^Zsignal-name-end
36712@var{middle-text}
36713^Z^Zsignal-string
36714@var{string}
36715^Z^Zsignal-string-end
36716@var{end-text}
36717@end smallexample
36718
36719@noindent
36720where @var{name} is the name of the signal, such as @code{SIGILL} or
36721@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36722as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36723@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36724user's benefit and have no particular format.
36725
e5ac9b53 36726@findex signal annotation
922fbb7b
AC
36727@item ^Z^Zsignal
36728The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36729just saying that the program received the signal, not that it was
36730terminated with it.
36731
e5ac9b53 36732@findex breakpoint annotation
922fbb7b
AC
36733@item ^Z^Zbreakpoint @var{number}
36734The program hit breakpoint number @var{number}.
36735
e5ac9b53 36736@findex watchpoint annotation
922fbb7b
AC
36737@item ^Z^Zwatchpoint @var{number}
36738The program hit watchpoint number @var{number}.
36739@end table
36740
36741@node Source Annotations
36742@section Displaying Source
36743@cindex annotations for source display
36744
e5ac9b53 36745@findex source annotation
922fbb7b
AC
36746The following annotation is used instead of displaying source code:
36747
36748@smallexample
36749^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36750@end smallexample
36751
36752where @var{filename} is an absolute file name indicating which source
36753file, @var{line} is the line number within that file (where 1 is the
36754first line in the file), @var{character} is the character position
36755within the file (where 0 is the first character in the file) (for most
36756debug formats this will necessarily point to the beginning of a line),
36757@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36758line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36759@var{addr} is the address in the target program associated with the
697aa1b7 36760source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
36761followed by one or more lowercase hex digits (note that this does not
36762depend on the language).
36763
4efc6507
DE
36764@node JIT Interface
36765@chapter JIT Compilation Interface
36766@cindex just-in-time compilation
36767@cindex JIT compilation interface
36768
36769This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36770interface. A JIT compiler is a program or library that generates native
36771executable code at runtime and executes it, usually in order to achieve good
36772performance while maintaining platform independence.
36773
36774Programs that use JIT compilation are normally difficult to debug because
36775portions of their code are generated at runtime, instead of being loaded from
36776object files, which is where @value{GDBN} normally finds the program's symbols
36777and debug information. In order to debug programs that use JIT compilation,
36778@value{GDBN} has an interface that allows the program to register in-memory
36779symbol files with @value{GDBN} at runtime.
36780
36781If you are using @value{GDBN} to debug a program that uses this interface, then
36782it should work transparently so long as you have not stripped the binary. If
36783you are developing a JIT compiler, then the interface is documented in the rest
36784of this chapter. At this time, the only known client of this interface is the
36785LLVM JIT.
36786
36787Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36788JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 36789variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
36790attaches, it reads a linked list of symbol files from the global variable to
36791find existing code, and puts a breakpoint in the function so that it can find
36792out about additional code.
36793
36794@menu
36795* Declarations:: Relevant C struct declarations
36796* Registering Code:: Steps to register code
36797* Unregistering Code:: Steps to unregister code
f85b53f8 36798* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
36799@end menu
36800
36801@node Declarations
36802@section JIT Declarations
36803
36804These are the relevant struct declarations that a C program should include to
36805implement the interface:
36806
36807@smallexample
36808typedef enum
36809@{
36810 JIT_NOACTION = 0,
36811 JIT_REGISTER_FN,
36812 JIT_UNREGISTER_FN
36813@} jit_actions_t;
36814
36815struct jit_code_entry
36816@{
36817 struct jit_code_entry *next_entry;
36818 struct jit_code_entry *prev_entry;
36819 const char *symfile_addr;
36820 uint64_t symfile_size;
36821@};
36822
36823struct jit_descriptor
36824@{
36825 uint32_t version;
36826 /* This type should be jit_actions_t, but we use uint32_t
36827 to be explicit about the bitwidth. */
36828 uint32_t action_flag;
36829 struct jit_code_entry *relevant_entry;
36830 struct jit_code_entry *first_entry;
36831@};
36832
36833/* GDB puts a breakpoint in this function. */
36834void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36835
36836/* Make sure to specify the version statically, because the
36837 debugger may check the version before we can set it. */
36838struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36839@end smallexample
36840
36841If the JIT is multi-threaded, then it is important that the JIT synchronize any
36842modifications to this global data properly, which can easily be done by putting
36843a global mutex around modifications to these structures.
36844
36845@node Registering Code
36846@section Registering Code
36847
36848To register code with @value{GDBN}, the JIT should follow this protocol:
36849
36850@itemize @bullet
36851@item
36852Generate an object file in memory with symbols and other desired debug
36853information. The file must include the virtual addresses of the sections.
36854
36855@item
36856Create a code entry for the file, which gives the start and size of the symbol
36857file.
36858
36859@item
36860Add it to the linked list in the JIT descriptor.
36861
36862@item
36863Point the relevant_entry field of the descriptor at the entry.
36864
36865@item
36866Set @code{action_flag} to @code{JIT_REGISTER} and call
36867@code{__jit_debug_register_code}.
36868@end itemize
36869
36870When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36871@code{relevant_entry} pointer so it doesn't have to walk the list looking for
36872new code. However, the linked list must still be maintained in order to allow
36873@value{GDBN} to attach to a running process and still find the symbol files.
36874
36875@node Unregistering Code
36876@section Unregistering Code
36877
36878If code is freed, then the JIT should use the following protocol:
36879
36880@itemize @bullet
36881@item
36882Remove the code entry corresponding to the code from the linked list.
36883
36884@item
36885Point the @code{relevant_entry} field of the descriptor at the code entry.
36886
36887@item
36888Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36889@code{__jit_debug_register_code}.
36890@end itemize
36891
36892If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36893and the JIT will leak the memory used for the associated symbol files.
36894
f85b53f8
SD
36895@node Custom Debug Info
36896@section Custom Debug Info
36897@cindex custom JIT debug info
36898@cindex JIT debug info reader
36899
36900Generating debug information in platform-native file formats (like ELF
36901or COFF) may be an overkill for JIT compilers; especially if all the
36902debug info is used for is displaying a meaningful backtrace. The
36903issue can be resolved by having the JIT writers decide on a debug info
36904format and also provide a reader that parses the debug info generated
36905by the JIT compiler. This section gives a brief overview on writing
36906such a parser. More specific details can be found in the source file
36907@file{gdb/jit-reader.in}, which is also installed as a header at
36908@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36909
36910The reader is implemented as a shared object (so this functionality is
36911not available on platforms which don't allow loading shared objects at
36912runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36913@code{jit-reader-unload} are provided, to be used to load and unload
36914the readers from a preconfigured directory. Once loaded, the shared
36915object is used the parse the debug information emitted by the JIT
36916compiler.
36917
36918@menu
36919* Using JIT Debug Info Readers:: How to use supplied readers correctly
36920* Writing JIT Debug Info Readers:: Creating a debug-info reader
36921@end menu
36922
36923@node Using JIT Debug Info Readers
36924@subsection Using JIT Debug Info Readers
36925@kindex jit-reader-load
36926@kindex jit-reader-unload
36927
36928Readers can be loaded and unloaded using the @code{jit-reader-load}
36929and @code{jit-reader-unload} commands.
36930
36931@table @code
c9fb1240 36932@item jit-reader-load @var{reader}
697aa1b7 36933Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
36934object specified as either an absolute or a relative file name. In
36935the latter case, @value{GDBN} will try to load the reader from a
36936pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36937system (here @var{libdir} is the system library directory, often
36938@file{/usr/local/lib}).
36939
36940Only one reader can be active at a time; trying to load a second
36941reader when one is already loaded will result in @value{GDBN}
36942reporting an error. A new JIT reader can be loaded by first unloading
36943the current one using @code{jit-reader-unload} and then invoking
36944@code{jit-reader-load}.
f85b53f8
SD
36945
36946@item jit-reader-unload
36947Unload the currently loaded JIT reader.
36948
36949@end table
36950
36951@node Writing JIT Debug Info Readers
36952@subsection Writing JIT Debug Info Readers
36953@cindex writing JIT debug info readers
36954
36955As mentioned, a reader is essentially a shared object conforming to a
36956certain ABI. This ABI is described in @file{jit-reader.h}.
36957
36958@file{jit-reader.h} defines the structures, macros and functions
36959required to write a reader. It is installed (along with
36960@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36961the system include directory.
36962
36963Readers need to be released under a GPL compatible license. A reader
36964can be declared as released under such a license by placing the macro
36965@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36966
36967The entry point for readers is the symbol @code{gdb_init_reader},
36968which is expected to be a function with the prototype
36969
36970@findex gdb_init_reader
36971@smallexample
36972extern struct gdb_reader_funcs *gdb_init_reader (void);
36973@end smallexample
36974
36975@cindex @code{struct gdb_reader_funcs}
36976
36977@code{struct gdb_reader_funcs} contains a set of pointers to callback
36978functions. These functions are executed to read the debug info
36979generated by the JIT compiler (@code{read}), to unwind stack frames
36980(@code{unwind}) and to create canonical frame IDs
27f7b2f6 36981(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
36982reader is being unloaded (@code{destroy}). The struct looks like this
36983
36984@smallexample
36985struct gdb_reader_funcs
36986@{
36987 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36988 int reader_version;
36989
36990 /* For use by the reader. */
36991 void *priv_data;
36992
36993 gdb_read_debug_info *read;
36994 gdb_unwind_frame *unwind;
36995 gdb_get_frame_id *get_frame_id;
36996 gdb_destroy_reader *destroy;
36997@};
36998@end smallexample
36999
37000@cindex @code{struct gdb_symbol_callbacks}
37001@cindex @code{struct gdb_unwind_callbacks}
37002
37003The callbacks are provided with another set of callbacks by
37004@value{GDBN} to do their job. For @code{read}, these callbacks are
37005passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37006and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37007@code{struct gdb_symbol_callbacks} has callbacks to create new object
37008files and new symbol tables inside those object files. @code{struct
37009gdb_unwind_callbacks} has callbacks to read registers off the current
37010frame and to write out the values of the registers in the previous
37011frame. Both have a callback (@code{target_read}) to read bytes off the
37012target's address space.
37013
d1feda86
YQ
37014@node In-Process Agent
37015@chapter In-Process Agent
37016@cindex debugging agent
37017The traditional debugging model is conceptually low-speed, but works fine,
37018because most bugs can be reproduced in debugging-mode execution. However,
37019as multi-core or many-core processors are becoming mainstream, and
37020multi-threaded programs become more and more popular, there should be more
37021and more bugs that only manifest themselves at normal-mode execution, for
37022example, thread races, because debugger's interference with the program's
37023timing may conceal the bugs. On the other hand, in some applications,
37024it is not feasible for the debugger to interrupt the program's execution
37025long enough for the developer to learn anything helpful about its behavior.
37026If the program's correctness depends on its real-time behavior, delays
37027introduced by a debugger might cause the program to fail, even when the
37028code itself is correct. It is useful to be able to observe the program's
37029behavior without interrupting it.
37030
37031Therefore, traditional debugging model is too intrusive to reproduce
37032some bugs. In order to reduce the interference with the program, we can
37033reduce the number of operations performed by debugger. The
37034@dfn{In-Process Agent}, a shared library, is running within the same
37035process with inferior, and is able to perform some debugging operations
37036itself. As a result, debugger is only involved when necessary, and
37037performance of debugging can be improved accordingly. Note that
37038interference with program can be reduced but can't be removed completely,
37039because the in-process agent will still stop or slow down the program.
37040
37041The in-process agent can interpret and execute Agent Expressions
37042(@pxref{Agent Expressions}) during performing debugging operations. The
37043agent expressions can be used for different purposes, such as collecting
37044data in tracepoints, and condition evaluation in breakpoints.
37045
37046@anchor{Control Agent}
37047You can control whether the in-process agent is used as an aid for
37048debugging with the following commands:
37049
37050@table @code
37051@kindex set agent on
37052@item set agent on
37053Causes the in-process agent to perform some operations on behalf of the
37054debugger. Just which operations requested by the user will be done
37055by the in-process agent depends on the its capabilities. For example,
37056if you request to evaluate breakpoint conditions in the in-process agent,
37057and the in-process agent has such capability as well, then breakpoint
37058conditions will be evaluated in the in-process agent.
37059
37060@kindex set agent off
37061@item set agent off
37062Disables execution of debugging operations by the in-process agent. All
37063of the operations will be performed by @value{GDBN}.
37064
37065@kindex show agent
37066@item show agent
37067Display the current setting of execution of debugging operations by
37068the in-process agent.
37069@end table
37070
16bdd41f
YQ
37071@menu
37072* In-Process Agent Protocol::
37073@end menu
37074
37075@node In-Process Agent Protocol
37076@section In-Process Agent Protocol
37077@cindex in-process agent protocol
37078
37079The in-process agent is able to communicate with both @value{GDBN} and
37080GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37081used for communications between @value{GDBN} or GDBserver and the IPA.
37082In general, @value{GDBN} or GDBserver sends commands
37083(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37084in-process agent replies back with the return result of the command, or
37085some other information. The data sent to in-process agent is composed
37086of primitive data types, such as 4-byte or 8-byte type, and composite
37087types, which are called objects (@pxref{IPA Protocol Objects}).
37088
37089@menu
37090* IPA Protocol Objects::
37091* IPA Protocol Commands::
37092@end menu
37093
37094@node IPA Protocol Objects
37095@subsection IPA Protocol Objects
37096@cindex ipa protocol objects
37097
37098The commands sent to and results received from agent may contain some
37099complex data types called @dfn{objects}.
37100
37101The in-process agent is running on the same machine with @value{GDBN}
37102or GDBserver, so it doesn't have to handle as much differences between
37103two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37104However, there are still some differences of two ends in two processes:
37105
37106@enumerate
37107@item
37108word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37109compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37110@item
37111ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37112GDBserver is compiled with one, and in-process agent is compiled with
37113the other one.
37114@end enumerate
37115
37116Here are the IPA Protocol Objects:
37117
37118@enumerate
37119@item
37120agent expression object. It represents an agent expression
37121(@pxref{Agent Expressions}).
37122@anchor{agent expression object}
37123@item
37124tracepoint action object. It represents a tracepoint action
37125(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37126memory, static trace data and to evaluate expression.
37127@anchor{tracepoint action object}
37128@item
37129tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37130@anchor{tracepoint object}
37131
37132@end enumerate
37133
37134The following table describes important attributes of each IPA protocol
37135object:
37136
37137@multitable @columnfractions .30 .20 .50
37138@headitem Name @tab Size @tab Description
37139@item @emph{agent expression object} @tab @tab
37140@item length @tab 4 @tab length of bytes code
37141@item byte code @tab @var{length} @tab contents of byte code
37142@item @emph{tracepoint action for collecting memory} @tab @tab
37143@item 'M' @tab 1 @tab type of tracepoint action
37144@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37145address of the lowest byte to collect, otherwise @var{addr} is the offset
37146of @var{basereg} for memory collecting.
37147@item len @tab 8 @tab length of memory for collecting
37148@item basereg @tab 4 @tab the register number containing the starting
37149memory address for collecting.
37150@item @emph{tracepoint action for collecting registers} @tab @tab
37151@item 'R' @tab 1 @tab type of tracepoint action
37152@item @emph{tracepoint action for collecting static trace data} @tab @tab
37153@item 'L' @tab 1 @tab type of tracepoint action
37154@item @emph{tracepoint action for expression evaluation} @tab @tab
37155@item 'X' @tab 1 @tab type of tracepoint action
37156@item agent expression @tab length of @tab @ref{agent expression object}
37157@item @emph{tracepoint object} @tab @tab
37158@item number @tab 4 @tab number of tracepoint
37159@item address @tab 8 @tab address of tracepoint inserted on
37160@item type @tab 4 @tab type of tracepoint
37161@item enabled @tab 1 @tab enable or disable of tracepoint
37162@item step_count @tab 8 @tab step
37163@item pass_count @tab 8 @tab pass
37164@item numactions @tab 4 @tab number of tracepoint actions
37165@item hit count @tab 8 @tab hit count
37166@item trace frame usage @tab 8 @tab trace frame usage
37167@item compiled_cond @tab 8 @tab compiled condition
37168@item orig_size @tab 8 @tab orig size
37169@item condition @tab 4 if condition is NULL otherwise length of
37170@ref{agent expression object}
37171@tab zero if condition is NULL, otherwise is
37172@ref{agent expression object}
37173@item actions @tab variable
37174@tab numactions number of @ref{tracepoint action object}
37175@end multitable
37176
37177@node IPA Protocol Commands
37178@subsection IPA Protocol Commands
37179@cindex ipa protocol commands
37180
37181The spaces in each command are delimiters to ease reading this commands
37182specification. They don't exist in real commands.
37183
37184@table @samp
37185
37186@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37187Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 37188(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
37189head of @dfn{jumppad}, which is used to jump to data collection routine
37190in IPA finally.
37191
37192Replies:
37193@table @samp
37194@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37195@var{target_address} is address of tracepoint in the inferior.
697aa1b7 37196The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 37197@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
37198The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37199The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
37200@item E @var{NN}
37201for an error
37202
37203@end table
37204
7255706c
YQ
37205@item close
37206Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37207is about to kill inferiors.
37208
16bdd41f
YQ
37209@item qTfSTM
37210@xref{qTfSTM}.
37211@item qTsSTM
37212@xref{qTsSTM}.
37213@item qTSTMat
37214@xref{qTSTMat}.
37215@item probe_marker_at:@var{address}
37216Asks in-process agent to probe the marker at @var{address}.
37217
37218Replies:
37219@table @samp
37220@item E @var{NN}
37221for an error
37222@end table
37223@item unprobe_marker_at:@var{address}
37224Asks in-process agent to unprobe the marker at @var{address}.
37225@end table
37226
8e04817f
AC
37227@node GDB Bugs
37228@chapter Reporting Bugs in @value{GDBN}
37229@cindex bugs in @value{GDBN}
37230@cindex reporting bugs in @value{GDBN}
c906108c 37231
8e04817f 37232Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 37233
8e04817f
AC
37234Reporting a bug may help you by bringing a solution to your problem, or it
37235may not. But in any case the principal function of a bug report is to help
37236the entire community by making the next version of @value{GDBN} work better. Bug
37237reports are your contribution to the maintenance of @value{GDBN}.
c906108c 37238
8e04817f
AC
37239In order for a bug report to serve its purpose, you must include the
37240information that enables us to fix the bug.
c4555f82
SC
37241
37242@menu
8e04817f
AC
37243* Bug Criteria:: Have you found a bug?
37244* Bug Reporting:: How to report bugs
c4555f82
SC
37245@end menu
37246
8e04817f 37247@node Bug Criteria
79a6e687 37248@section Have You Found a Bug?
8e04817f 37249@cindex bug criteria
c4555f82 37250
8e04817f 37251If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
37252
37253@itemize @bullet
8e04817f
AC
37254@cindex fatal signal
37255@cindex debugger crash
37256@cindex crash of debugger
c4555f82 37257@item
8e04817f
AC
37258If the debugger gets a fatal signal, for any input whatever, that is a
37259@value{GDBN} bug. Reliable debuggers never crash.
37260
37261@cindex error on valid input
37262@item
37263If @value{GDBN} produces an error message for valid input, that is a
37264bug. (Note that if you're cross debugging, the problem may also be
37265somewhere in the connection to the target.)
c4555f82 37266
8e04817f 37267@cindex invalid input
c4555f82 37268@item
8e04817f
AC
37269If @value{GDBN} does not produce an error message for invalid input,
37270that is a bug. However, you should note that your idea of
37271``invalid input'' might be our idea of ``an extension'' or ``support
37272for traditional practice''.
37273
37274@item
37275If you are an experienced user of debugging tools, your suggestions
37276for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37277@end itemize
37278
8e04817f 37279@node Bug Reporting
79a6e687 37280@section How to Report Bugs
8e04817f
AC
37281@cindex bug reports
37282@cindex @value{GDBN} bugs, reporting
37283
37284A number of companies and individuals offer support for @sc{gnu} products.
37285If you obtained @value{GDBN} from a support organization, we recommend you
37286contact that organization first.
37287
37288You can find contact information for many support companies and
37289individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37290distribution.
37291@c should add a web page ref...
37292
c16158bc
JM
37293@ifset BUGURL
37294@ifset BUGURL_DEFAULT
129188f6 37295In any event, we also recommend that you submit bug reports for
d3e8051b 37296@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37297@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37298page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37299be used.
8e04817f
AC
37300
37301@strong{Do not send bug reports to @samp{info-gdb}, or to
37302@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37303not want to receive bug reports. Those that do have arranged to receive
37304@samp{bug-gdb}.
37305
37306The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37307serves as a repeater. The mailing list and the newsgroup carry exactly
37308the same messages. Often people think of posting bug reports to the
37309newsgroup instead of mailing them. This appears to work, but it has one
37310problem which can be crucial: a newsgroup posting often lacks a mail
37311path back to the sender. Thus, if we need to ask for more information,
37312we may be unable to reach you. For this reason, it is better to send
37313bug reports to the mailing list.
c16158bc
JM
37314@end ifset
37315@ifclear BUGURL_DEFAULT
37316In any event, we also recommend that you submit bug reports for
37317@value{GDBN} to @value{BUGURL}.
37318@end ifclear
37319@end ifset
c4555f82 37320
8e04817f
AC
37321The fundamental principle of reporting bugs usefully is this:
37322@strong{report all the facts}. If you are not sure whether to state a
37323fact or leave it out, state it!
c4555f82 37324
8e04817f
AC
37325Often people omit facts because they think they know what causes the
37326problem and assume that some details do not matter. Thus, you might
37327assume that the name of the variable you use in an example does not matter.
37328Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37329stray memory reference which happens to fetch from the location where that
37330name is stored in memory; perhaps, if the name were different, the contents
37331of that location would fool the debugger into doing the right thing despite
37332the bug. Play it safe and give a specific, complete example. That is the
37333easiest thing for you to do, and the most helpful.
c4555f82 37334
8e04817f
AC
37335Keep in mind that the purpose of a bug report is to enable us to fix the
37336bug. It may be that the bug has been reported previously, but neither
37337you nor we can know that unless your bug report is complete and
37338self-contained.
c4555f82 37339
8e04817f
AC
37340Sometimes people give a few sketchy facts and ask, ``Does this ring a
37341bell?'' Those bug reports are useless, and we urge everyone to
37342@emph{refuse to respond to them} except to chide the sender to report
37343bugs properly.
37344
37345To enable us to fix the bug, you should include all these things:
c4555f82
SC
37346
37347@itemize @bullet
37348@item
8e04817f
AC
37349The version of @value{GDBN}. @value{GDBN} announces it if you start
37350with no arguments; you can also print it at any time using @code{show
37351version}.
c4555f82 37352
8e04817f
AC
37353Without this, we will not know whether there is any point in looking for
37354the bug in the current version of @value{GDBN}.
c4555f82
SC
37355
37356@item
8e04817f
AC
37357The type of machine you are using, and the operating system name and
37358version number.
c4555f82 37359
6eaaf48b
EZ
37360@item
37361The details of the @value{GDBN} build-time configuration.
37362@value{GDBN} shows these details if you invoke it with the
37363@option{--configuration} command-line option, or if you type
37364@code{show configuration} at @value{GDBN}'s prompt.
37365
c4555f82 37366@item
c1468174 37367What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37368``@value{GCC}--2.8.1''.
c4555f82
SC
37369
37370@item
8e04817f 37371What compiler (and its version) was used to compile the program you are
c1468174 37372debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37373C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37374to get this information; for other compilers, see the documentation for
37375those compilers.
c4555f82 37376
8e04817f
AC
37377@item
37378The command arguments you gave the compiler to compile your example and
37379observe the bug. For example, did you use @samp{-O}? To guarantee
37380you will not omit something important, list them all. A copy of the
37381Makefile (or the output from make) is sufficient.
c4555f82 37382
8e04817f
AC
37383If we were to try to guess the arguments, we would probably guess wrong
37384and then we might not encounter the bug.
c4555f82 37385
8e04817f
AC
37386@item
37387A complete input script, and all necessary source files, that will
37388reproduce the bug.
c4555f82 37389
8e04817f
AC
37390@item
37391A description of what behavior you observe that you believe is
37392incorrect. For example, ``It gets a fatal signal.''
c4555f82 37393
8e04817f
AC
37394Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37395will certainly notice it. But if the bug is incorrect output, we might
37396not notice unless it is glaringly wrong. You might as well not give us
37397a chance to make a mistake.
c4555f82 37398
8e04817f
AC
37399Even if the problem you experience is a fatal signal, you should still
37400say so explicitly. Suppose something strange is going on, such as, your
37401copy of @value{GDBN} is out of synch, or you have encountered a bug in
37402the C library on your system. (This has happened!) Your copy might
37403crash and ours would not. If you told us to expect a crash, then when
37404ours fails to crash, we would know that the bug was not happening for
37405us. If you had not told us to expect a crash, then we would not be able
37406to draw any conclusion from our observations.
c4555f82 37407
e0c07bf0
MC
37408@pindex script
37409@cindex recording a session script
37410To collect all this information, you can use a session recording program
37411such as @command{script}, which is available on many Unix systems.
37412Just run your @value{GDBN} session inside @command{script} and then
37413include the @file{typescript} file with your bug report.
37414
37415Another way to record a @value{GDBN} session is to run @value{GDBN}
37416inside Emacs and then save the entire buffer to a file.
37417
8e04817f
AC
37418@item
37419If you wish to suggest changes to the @value{GDBN} source, send us context
37420diffs. If you even discuss something in the @value{GDBN} source, refer to
37421it by context, not by line number.
c4555f82 37422
8e04817f
AC
37423The line numbers in our development sources will not match those in your
37424sources. Your line numbers would convey no useful information to us.
c4555f82 37425
8e04817f 37426@end itemize
c4555f82 37427
8e04817f 37428Here are some things that are not necessary:
c4555f82 37429
8e04817f
AC
37430@itemize @bullet
37431@item
37432A description of the envelope of the bug.
c4555f82 37433
8e04817f
AC
37434Often people who encounter a bug spend a lot of time investigating
37435which changes to the input file will make the bug go away and which
37436changes will not affect it.
c4555f82 37437
8e04817f
AC
37438This is often time consuming and not very useful, because the way we
37439will find the bug is by running a single example under the debugger
37440with breakpoints, not by pure deduction from a series of examples.
37441We recommend that you save your time for something else.
c4555f82 37442
8e04817f
AC
37443Of course, if you can find a simpler example to report @emph{instead}
37444of the original one, that is a convenience for us. Errors in the
37445output will be easier to spot, running under the debugger will take
37446less time, and so on.
c4555f82 37447
8e04817f
AC
37448However, simplification is not vital; if you do not want to do this,
37449report the bug anyway and send us the entire test case you used.
c4555f82 37450
8e04817f
AC
37451@item
37452A patch for the bug.
c4555f82 37453
8e04817f
AC
37454A patch for the bug does help us if it is a good one. But do not omit
37455the necessary information, such as the test case, on the assumption that
37456a patch is all we need. We might see problems with your patch and decide
37457to fix the problem another way, or we might not understand it at all.
c4555f82 37458
8e04817f
AC
37459Sometimes with a program as complicated as @value{GDBN} it is very hard to
37460construct an example that will make the program follow a certain path
37461through the code. If you do not send us the example, we will not be able
37462to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37463
8e04817f
AC
37464And if we cannot understand what bug you are trying to fix, or why your
37465patch should be an improvement, we will not install it. A test case will
37466help us to understand.
c4555f82 37467
8e04817f
AC
37468@item
37469A guess about what the bug is or what it depends on.
c4555f82 37470
8e04817f
AC
37471Such guesses are usually wrong. Even we cannot guess right about such
37472things without first using the debugger to find the facts.
37473@end itemize
c4555f82 37474
8e04817f
AC
37475@c The readline documentation is distributed with the readline code
37476@c and consists of the two following files:
cc88a640
JK
37477@c rluser.texi
37478@c hsuser.texi
8e04817f
AC
37479@c Use -I with makeinfo to point to the appropriate directory,
37480@c environment var TEXINPUTS with TeX.
39037522 37481@ifclear SYSTEM_READLINE
5bdf8622 37482@include rluser.texi
cc88a640 37483@include hsuser.texi
39037522 37484@end ifclear
c4555f82 37485
4ceed123
JB
37486@node In Memoriam
37487@appendix In Memoriam
37488
9ed350ad
JB
37489The @value{GDBN} project mourns the loss of the following long-time
37490contributors:
4ceed123
JB
37491
37492@table @code
37493@item Fred Fish
9ed350ad
JB
37494Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37495to Free Software in general. Outside of @value{GDBN}, he was known in
37496the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37497
37498@item Michael Snyder
9ed350ad
JB
37499Michael was one of the Global Maintainers of the @value{GDBN} project,
37500with contributions recorded as early as 1996, until 2011. In addition
37501to his day to day participation, he was a large driving force behind
37502adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37503@end table
37504
37505Beyond their technical contributions to the project, they were also
37506enjoyable members of the Free Software Community. We will miss them.
c4555f82 37507
8e04817f
AC
37508@node Formatting Documentation
37509@appendix Formatting Documentation
c4555f82 37510
8e04817f
AC
37511@cindex @value{GDBN} reference card
37512@cindex reference card
37513The @value{GDBN} 4 release includes an already-formatted reference card, ready
37514for printing with PostScript or Ghostscript, in the @file{gdb}
37515subdirectory of the main source directory@footnote{In
37516@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37517release.}. If you can use PostScript or Ghostscript with your printer,
37518you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37519
8e04817f
AC
37520The release also includes the source for the reference card. You
37521can format it, using @TeX{}, by typing:
c4555f82 37522
474c8240 37523@smallexample
8e04817f 37524make refcard.dvi
474c8240 37525@end smallexample
c4555f82 37526
8e04817f
AC
37527The @value{GDBN} reference card is designed to print in @dfn{landscape}
37528mode on US ``letter'' size paper;
37529that is, on a sheet 11 inches wide by 8.5 inches
37530high. You will need to specify this form of printing as an option to
37531your @sc{dvi} output program.
c4555f82 37532
8e04817f 37533@cindex documentation
c4555f82 37534
8e04817f
AC
37535All the documentation for @value{GDBN} comes as part of the machine-readable
37536distribution. The documentation is written in Texinfo format, which is
37537a documentation system that uses a single source file to produce both
37538on-line information and a printed manual. You can use one of the Info
37539formatting commands to create the on-line version of the documentation
37540and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37541
8e04817f
AC
37542@value{GDBN} includes an already formatted copy of the on-line Info
37543version of this manual in the @file{gdb} subdirectory. The main Info
37544file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37545subordinate files matching @samp{gdb.info*} in the same directory. If
37546necessary, you can print out these files, or read them with any editor;
37547but they are easier to read using the @code{info} subsystem in @sc{gnu}
37548Emacs or the standalone @code{info} program, available as part of the
37549@sc{gnu} Texinfo distribution.
c4555f82 37550
8e04817f
AC
37551If you want to format these Info files yourself, you need one of the
37552Info formatting programs, such as @code{texinfo-format-buffer} or
37553@code{makeinfo}.
c4555f82 37554
8e04817f
AC
37555If you have @code{makeinfo} installed, and are in the top level
37556@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37557version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37558
474c8240 37559@smallexample
8e04817f
AC
37560cd gdb
37561make gdb.info
474c8240 37562@end smallexample
c4555f82 37563
8e04817f
AC
37564If you want to typeset and print copies of this manual, you need @TeX{},
37565a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37566Texinfo definitions file.
c4555f82 37567
8e04817f
AC
37568@TeX{} is a typesetting program; it does not print files directly, but
37569produces output files called @sc{dvi} files. To print a typeset
37570document, you need a program to print @sc{dvi} files. If your system
37571has @TeX{} installed, chances are it has such a program. The precise
37572command to use depends on your system; @kbd{lpr -d} is common; another
37573(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37574require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37575
8e04817f
AC
37576@TeX{} also requires a macro definitions file called
37577@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37578written in Texinfo format. On its own, @TeX{} cannot either read or
37579typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37580and is located in the @file{gdb-@var{version-number}/texinfo}
37581directory.
c4555f82 37582
8e04817f 37583If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37584typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37585subdirectory of the main source directory (for example, to
37586@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37587
474c8240 37588@smallexample
8e04817f 37589make gdb.dvi
474c8240 37590@end smallexample
c4555f82 37591
8e04817f 37592Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37593
8e04817f
AC
37594@node Installing GDB
37595@appendix Installing @value{GDBN}
8e04817f 37596@cindex installation
c4555f82 37597
7fa2210b
DJ
37598@menu
37599* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37600* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37601* Separate Objdir:: Compiling @value{GDBN} in another directory
37602* Config Names:: Specifying names for hosts and targets
37603* Configure Options:: Summary of options for configure
098b41a6 37604* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37605@end menu
37606
37607@node Requirements
79a6e687 37608@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37609@cindex building @value{GDBN}, requirements for
37610
37611Building @value{GDBN} requires various tools and packages to be available.
37612Other packages will be used only if they are found.
37613
79a6e687 37614@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37615@table @asis
7f0bd420
TT
37616@item C@t{++}11 compiler
37617@value{GDBN} is written in C@t{++}11. It should be buildable with any
37618recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37619
7f0bd420
TT
37620@item GNU make
37621@value{GDBN}'s build system relies on features only found in the GNU
37622make program. Other variants of @code{make} will not work.
7fa2210b
DJ
37623@end table
37624
79a6e687 37625@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37626@table @asis
37627@item Expat
123dc839 37628@anchor{Expat}
7fa2210b
DJ
37629@value{GDBN} can use the Expat XML parsing library. This library may be
37630included with your operating system distribution; if it is not, you
37631can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37632The @file{configure} script will search for this library in several
7fa2210b
DJ
37633standard locations; if it is installed in an unusual path, you can
37634use the @option{--with-libexpat-prefix} option to specify its location.
37635
9cceb671
DJ
37636Expat is used for:
37637
37638@itemize @bullet
37639@item
37640Remote protocol memory maps (@pxref{Memory Map Format})
37641@item
37642Target descriptions (@pxref{Target Descriptions})
37643@item
2268b414
JK
37644Remote shared library lists (@xref{Library List Format},
37645or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37646@item
37647MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37648@item
37649Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37650@item
f4abbc16
MM
37651Branch trace (@pxref{Branch Trace Format},
37652@pxref{Branch Trace Configuration Format})
9cceb671 37653@end itemize
7fa2210b 37654
7f0bd420
TT
37655@item Guile
37656@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37657default, @value{GDBN} will be compiled if the Guile libraries are
37658installed and are found by @file{configure}. You can use the
37659@code{--with-guile} option to request Guile, and pass either the Guile
37660version number or the file name of the relevant @code{pkg-config}
37661program to choose a particular version of Guile.
37662
37663@item iconv
37664@value{GDBN}'s features related to character sets (@pxref{Character
37665Sets}) require a functioning @code{iconv} implementation. If you are
37666on a GNU system, then this is provided by the GNU C Library. Some
37667other systems also provide a working @code{iconv}.
37668
37669If @value{GDBN} is using the @code{iconv} program which is installed
37670in a non-standard place, you will need to tell @value{GDBN} where to
37671find it. This is done with @option{--with-iconv-bin} which specifies
37672the directory that contains the @code{iconv} program. This program is
37673run in order to make a list of the available character sets.
37674
37675On systems without @code{iconv}, you can install GNU Libiconv. If
37676Libiconv is installed in a standard place, @value{GDBN} will
37677automatically use it if it is needed. If you have previously
37678installed Libiconv in a non-standard place, you can use the
37679@option{--with-libiconv-prefix} option to @file{configure}.
37680
37681@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37682arrange to build Libiconv if a directory named @file{libiconv} appears
37683in the top-most source directory. If Libiconv is built this way, and
37684if the operating system does not provide a suitable @code{iconv}
37685implementation, then the just-built library will automatically be used
37686by @value{GDBN}. One easy way to set this up is to download GNU
37687Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37688source tree, and then rename the directory holding the Libiconv source
37689code to @samp{libiconv}.
37690
37691@item lzma
37692@value{GDBN} can support debugging sections that are compressed with
37693the LZMA library. @xref{MiniDebugInfo}. If this library is not
37694included with your operating system, you can find it in the xz package
37695at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37696the usual place, then the @file{configure} script will use it
37697automatically. If it is installed in an unusual path, you can use the
37698@option{--with-lzma-prefix} option to specify its location.
37699
2400729e
UW
37700@item MPFR
37701@anchor{MPFR}
37702@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37703library. This library may be included with your operating system
37704distribution; if it is not, you can get the latest version from
37705@url{http://www.mpfr.org}. The @file{configure} script will search
37706for this library in several standard locations; if it is installed
37707in an unusual path, you can use the @option{--with-libmpfr-prefix}
37708option to specify its location.
37709
37710GNU MPFR is used to emulate target floating-point arithmetic during
37711expression evaluation when the target uses different floating-point
37712formats than the host. If GNU MPFR it is not available, @value{GDBN}
37713will fall back to using host floating-point arithmetic.
37714
7f0bd420
TT
37715@item Python
37716@value{GDBN} can be scripted using Python language. @xref{Python}.
37717By default, @value{GDBN} will be compiled if the Python libraries are
37718installed and are found by @file{configure}. You can use the
37719@code{--with-python} option to request Python, and pass either the
37720file name of the relevant @code{python} executable, or the name of the
37721directory in which Python is installed, to choose a particular
37722installation of Python.
37723
31fffb02
CS
37724@item zlib
37725@cindex compressed debug sections
37726@value{GDBN} will use the @samp{zlib} library, if available, to read
37727compressed debug sections. Some linkers, such as GNU gold, are capable
37728of producing binaries with compressed debug sections. If @value{GDBN}
37729is compiled with @samp{zlib}, it will be able to read the debug
37730information in such binaries.
37731
37732The @samp{zlib} library is likely included with your operating system
37733distribution; if it is not, you can get the latest version from
37734@url{http://zlib.net}.
7fa2210b
DJ
37735@end table
37736
37737@node Running Configure
db2e3e2e 37738@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 37739@cindex configuring @value{GDBN}
db2e3e2e 37740@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
37741of preparing @value{GDBN} for installation; you can then use @code{make} to
37742build the @code{gdb} program.
37743@iftex
37744@c irrelevant in info file; it's as current as the code it lives with.
37745@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37746look at the @file{README} file in the sources; we may have improved the
37747installation procedures since publishing this manual.}
37748@end iftex
c4555f82 37749
8e04817f
AC
37750The @value{GDBN} distribution includes all the source code you need for
37751@value{GDBN} in a single directory, whose name is usually composed by
37752appending the version number to @samp{gdb}.
c4555f82 37753
8e04817f
AC
37754For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37755@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 37756
8e04817f
AC
37757@table @code
37758@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37759script for configuring @value{GDBN} and all its supporting libraries
c4555f82 37760
8e04817f
AC
37761@item gdb-@value{GDBVN}/gdb
37762the source specific to @value{GDBN} itself
c4555f82 37763
8e04817f
AC
37764@item gdb-@value{GDBVN}/bfd
37765source for the Binary File Descriptor library
c906108c 37766
8e04817f
AC
37767@item gdb-@value{GDBVN}/include
37768@sc{gnu} include files
c906108c 37769
8e04817f
AC
37770@item gdb-@value{GDBVN}/libiberty
37771source for the @samp{-liberty} free software library
c906108c 37772
8e04817f
AC
37773@item gdb-@value{GDBVN}/opcodes
37774source for the library of opcode tables and disassemblers
c906108c 37775
8e04817f
AC
37776@item gdb-@value{GDBVN}/readline
37777source for the @sc{gnu} command-line interface
8e04817f 37778@end table
c906108c 37779
7f0bd420
TT
37780There may be other subdirectories as well.
37781
db2e3e2e 37782The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
37783from the @file{gdb-@var{version-number}} source directory, which in
37784this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 37785
8e04817f 37786First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 37787if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
37788identifier for the platform on which @value{GDBN} will run as an
37789argument.
c906108c 37790
8e04817f 37791For example:
c906108c 37792
474c8240 37793@smallexample
8e04817f 37794cd gdb-@value{GDBVN}
7f0bd420 37795./configure
8e04817f 37796make
474c8240 37797@end smallexample
c906108c 37798
7f0bd420
TT
37799Running @samp{configure} and then running @code{make} builds the
37800included supporting libraries, then @code{gdb} itself. The configured
37801source files, and the binaries, are left in the corresponding source
37802directories.
c906108c 37803
8e04817f 37804@need 750
db2e3e2e 37805@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
37806system does not recognize this automatically when you run a different
37807shell, you may need to run @code{sh} on it explicitly:
c906108c 37808
474c8240 37809@smallexample
7f0bd420 37810sh configure
474c8240 37811@end smallexample
c906108c 37812
db2e3e2e 37813You should run the @file{configure} script from the top directory in the
94e91d6d 37814source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 37815@file{configure} from one of the subdirectories, you will configure only
94e91d6d 37816that subdirectory. That is usually not what you want. In particular,
db2e3e2e 37817if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
37818of the @file{gdb-@var{version-number}} directory, you will omit the
37819configuration of @file{bfd}, @file{readline}, and other sibling
37820directories of the @file{gdb} subdirectory. This leads to build errors
37821about missing include files such as @file{bfd/bfd.h}.
c906108c 37822
7f0bd420
TT
37823You can install @code{@value{GDBN}} anywhere. The best way to do this
37824is to pass the @code{--prefix} option to @code{configure}, and then
37825install it with @code{make install}.
c906108c 37826
8e04817f 37827@node Separate Objdir
79a6e687 37828@section Compiling @value{GDBN} in Another Directory
c906108c 37829
8e04817f
AC
37830If you want to run @value{GDBN} versions for several host or target machines,
37831you need a different @code{gdb} compiled for each combination of
db2e3e2e 37832host and target. @file{configure} is designed to make this easy by
8e04817f
AC
37833allowing you to generate each configuration in a separate subdirectory,
37834rather than in the source directory. If your @code{make} program
37835handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37836@code{make} in each of these directories builds the @code{gdb}
37837program specified there.
c906108c 37838
db2e3e2e 37839To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 37840with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
37841(You also need to specify a path to find @file{configure}
37842itself from your working directory. If the path to @file{configure}
8e04817f
AC
37843would be the same as the argument to @samp{--srcdir}, you can leave out
37844the @samp{--srcdir} option; it is assumed.)
c906108c 37845
8e04817f
AC
37846For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37847separate directory for a Sun 4 like this:
c906108c 37848
474c8240 37849@smallexample
8e04817f
AC
37850@group
37851cd gdb-@value{GDBVN}
37852mkdir ../gdb-sun4
37853cd ../gdb-sun4
7f0bd420 37854../gdb-@value{GDBVN}/configure
8e04817f
AC
37855make
37856@end group
474c8240 37857@end smallexample
c906108c 37858
db2e3e2e 37859When @file{configure} builds a configuration using a remote source
8e04817f
AC
37860directory, it creates a tree for the binaries with the same structure
37861(and using the same names) as the tree under the source directory. In
37862the example, you'd find the Sun 4 library @file{libiberty.a} in the
37863directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37864@file{gdb-sun4/gdb}.
c906108c 37865
94e91d6d
MC
37866Make sure that your path to the @file{configure} script has just one
37867instance of @file{gdb} in it. If your path to @file{configure} looks
37868like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37869one subdirectory of @value{GDBN}, not the whole package. This leads to
37870build errors about missing include files such as @file{bfd/bfd.h}.
37871
8e04817f
AC
37872One popular reason to build several @value{GDBN} configurations in separate
37873directories is to configure @value{GDBN} for cross-compiling (where
37874@value{GDBN} runs on one machine---the @dfn{host}---while debugging
37875programs that run on another machine---the @dfn{target}).
37876You specify a cross-debugging target by
db2e3e2e 37877giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 37878
8e04817f
AC
37879When you run @code{make} to build a program or library, you must run
37880it in a configured directory---whatever directory you were in when you
db2e3e2e 37881called @file{configure} (or one of its subdirectories).
c906108c 37882
db2e3e2e 37883The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
37884directory also runs recursively. If you type @code{make} in a source
37885directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37886directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37887will build all the required libraries, and then build GDB.
c906108c 37888
8e04817f
AC
37889When you have multiple hosts or targets configured in separate
37890directories, you can run @code{make} on them in parallel (for example,
37891if they are NFS-mounted on each of the hosts); they will not interfere
37892with each other.
c906108c 37893
8e04817f 37894@node Config Names
79a6e687 37895@section Specifying Names for Hosts and Targets
c906108c 37896
db2e3e2e 37897The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
37898script are based on a three-part naming scheme, but some short predefined
37899aliases are also supported. The full naming scheme encodes three pieces
37900of information in the following pattern:
c906108c 37901
474c8240 37902@smallexample
8e04817f 37903@var{architecture}-@var{vendor}-@var{os}
474c8240 37904@end smallexample
c906108c 37905
8e04817f
AC
37906For example, you can use the alias @code{sun4} as a @var{host} argument,
37907or as the value for @var{target} in a @code{--target=@var{target}}
37908option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 37909
db2e3e2e 37910The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 37911any query facility to list all supported host and target names or
db2e3e2e 37912aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
37913@code{config.sub} to map abbreviations to full names; you can read the
37914script, if you wish, or you can use it to test your guesses on
37915abbreviations---for example:
c906108c 37916
8e04817f
AC
37917@smallexample
37918% sh config.sub i386-linux
37919i386-pc-linux-gnu
37920% sh config.sub alpha-linux
37921alpha-unknown-linux-gnu
37922% sh config.sub hp9k700
37923hppa1.1-hp-hpux
37924% sh config.sub sun4
37925sparc-sun-sunos4.1.1
37926% sh config.sub sun3
37927m68k-sun-sunos4.1.1
37928% sh config.sub i986v
37929Invalid configuration `i986v': machine `i986v' not recognized
37930@end smallexample
c906108c 37931
8e04817f
AC
37932@noindent
37933@code{config.sub} is also distributed in the @value{GDBN} source
37934directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 37935
8e04817f 37936@node Configure Options
db2e3e2e 37937@section @file{configure} Options
c906108c 37938
db2e3e2e 37939Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
37940are most often useful for building @value{GDBN}. @file{configure}
37941also has several other options not listed here. @inforef{Running
37942configure scripts,,autoconf.info}, for a full
37943explanation of @file{configure}.
c906108c 37944
474c8240 37945@smallexample
8e04817f
AC
37946configure @r{[}--help@r{]}
37947 @r{[}--prefix=@var{dir}@r{]}
37948 @r{[}--exec-prefix=@var{dir}@r{]}
37949 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 37950 @r{[}--target=@var{target}@r{]}
474c8240 37951@end smallexample
c906108c 37952
8e04817f
AC
37953@noindent
37954You may introduce options with a single @samp{-} rather than
37955@samp{--} if you prefer; but you may abbreviate option names if you use
37956@samp{--}.
c906108c 37957
8e04817f
AC
37958@table @code
37959@item --help
db2e3e2e 37960Display a quick summary of how to invoke @file{configure}.
c906108c 37961
8e04817f
AC
37962@item --prefix=@var{dir}
37963Configure the source to install programs and files under directory
37964@file{@var{dir}}.
c906108c 37965
8e04817f
AC
37966@item --exec-prefix=@var{dir}
37967Configure the source to install programs under directory
37968@file{@var{dir}}.
c906108c 37969
8e04817f
AC
37970@c avoid splitting the warning from the explanation:
37971@need 2000
37972@item --srcdir=@var{dirname}
8e04817f
AC
37973Use this option to make configurations in directories separate from the
37974@value{GDBN} source directories. Among other things, you can use this to
37975build (or maintain) several configurations simultaneously, in separate
db2e3e2e 37976directories. @file{configure} writes configuration-specific files in
8e04817f 37977the current directory, but arranges for them to use the source in the
db2e3e2e 37978directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
37979the working directory in parallel to the source directories below
37980@var{dirname}.
c906108c 37981
8e04817f
AC
37982@item --target=@var{target}
37983Configure @value{GDBN} for cross-debugging programs running on the specified
37984@var{target}. Without this option, @value{GDBN} is configured to debug
37985programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 37986
a95746f9
TT
37987There is no convenient way to generate a list of all available
37988targets. Also see the @code{--enable-targets} option, below.
8e04817f 37989@end table
c906108c 37990
a95746f9
TT
37991There are many other options that are specific to @value{GDBN}. This
37992lists just the most common ones; there are some very specialized
37993options not described here.
37994
37995@table @code
37996@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37997@itemx --enable-targets=all
37998Configure @value{GDBN} for cross-debugging programs running on the
37999specified list of targets. The special value @samp{all} configures
38000@value{GDBN} for debugging programs running on any target it supports.
38001
38002@item --with-gdb-datadir=@var{path}
38003Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38004here for certain supporting files or scripts. This defaults to the
6b92c0d3 38005@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
38006@code{--datadir}).
38007
38008@item --with-relocated-sources=@var{dir}
38009Sets up the default source path substitution rule so that directory
38010names recorded in debug information will be automatically adjusted for
38011any directory under @var{dir}. @var{dir} should be a subdirectory of
38012@value{GDBN}'s configured prefix, the one mentioned in the
38013@code{--prefix} or @code{--exec-prefix} options to configure. This
38014option is useful if GDB is supposed to be moved to a different place
38015after it is built.
38016
38017@item --enable-64-bit-bfd
38018Enable 64-bit support in BFD on 32-bit hosts.
38019
38020@item --disable-gdbmi
38021Build @value{GDBN} without the GDB/MI machine interface
38022(@pxref{GDB/MI}).
38023
38024@item --enable-tui
38025Build @value{GDBN} with the text-mode full-screen user interface
38026(TUI). Requires a curses library (ncurses and cursesX are also
38027supported).
38028
38029@item --with-curses
38030Use the curses library instead of the termcap library, for text-mode
38031terminal operations.
38032
0d79cdc4
AM
38033@item --with-debuginfod
38034Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38035Used to automatically fetch source files and separate debug files from
38036debuginfod servers using the associated executable's build ID. Enabled
38037by default if libdebuginfod is installed and found at configure time.
38038debuginfod is packaged with elfutils, starting with version 0.178. You
38039can get the latest version from `https://sourceware.org/elfutils/'.
38040
a95746f9
TT
38041@item --with-libunwind-ia64
38042Use the libunwind library for unwinding function call stack on ia64
38043target platforms. See http://www.nongnu.org/libunwind/index.html for
38044details.
38045
38046@item --with-system-readline
38047Use the readline library installed on the host, rather than the
86c6b807
TT
38048library supplied as part of @value{GDBN}. Readline 7 or newer is
38049required; this is enforced by the build system.
a95746f9
TT
38050
38051@item --with-system-zlib
38052Use the zlib library installed on the host, rather than the library
38053supplied as part of @value{GDBN}.
38054
38055@item --with-expat
38056Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38057default if libexpat is installed and found at configure time.) This
38058library is used to read XML files supplied with @value{GDBN}. If it
38059is unavailable, some features, such as remote protocol memory maps,
38060target descriptions, and shared library lists, that are based on XML
38061files, will not be available in @value{GDBN}. If your host does not
38062have libexpat installed, you can get the latest version from
38063`http://expat.sourceforge.net'.
38064
38065@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38066
38067Build @value{GDBN} with GNU libiconv, a character set encoding
38068conversion library. This is not done by default, as on GNU systems
38069the @code{iconv} that is built in to the C library is sufficient. If
38070your host does not have a working @code{iconv}, you can get the latest
38071version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38072
38073@value{GDBN}'s build system also supports building GNU libiconv as
38074part of the overall build. @xref{Requirements}.
38075
38076@item --with-lzma
38077Build @value{GDBN} with LZMA, a compression library. (Done by default
38078if liblzma is installed and found at configure time.) LZMA is used by
38079@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38080platforms using the ELF object file format. If your host does not
38081have liblzma installed, you can get the latest version from
38082`https://tukaani.org/xz/'.
38083
38084@item --with-mpfr
38085Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38086floating-point computation with correct rounding. (Done by default if
38087GNU MPFR is installed and found at configure time.) This library is
38088used to emulate target floating-point arithmetic during expression
38089evaluation when the target uses different floating-point formats than
38090the host. If GNU MPFR is not available, @value{GDBN} will fall back
38091to using host floating-point arithmetic. If your host does not have
38092GNU MPFR installed, you can get the latest version from
38093`http://www.mpfr.org'.
38094
38095@item --with-python@r{[}=@var{python}@r{]}
38096Build @value{GDBN} with Python scripting support. (Done by default if
38097libpython is present and found at configure time.) Python makes
38098@value{GDBN} scripting much more powerful than the restricted CLI
38099scripting language. If your host does not have Python installed, you
38100can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 38101of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
38102is used to find the Python headers and libraries. It can be either
38103the name of a Python executable, or the name of the directory in which
38104Python is installed.
38105
38106@item --with-guile[=GUILE]'
38107Build @value{GDBN} with GNU Guile scripting support. (Done by default
38108if libguile is present and found at configure time.) If your host
38109does not have Guile installed, you can find it at
38110`https://www.gnu.org/software/guile/'. The optional argument GUILE
38111can be a version number, which will cause @code{configure} to try to
38112use that version of Guile; or the file name of a @code{pkg-config}
38113executable, which will be queried to find the information needed to
38114compile and link against Guile.
38115
38116@item --without-included-regex
38117Don't use the regex library included with @value{GDBN} (as part of the
38118libiberty library). This is the default on hosts with version 2 of
38119the GNU C library.
38120
38121@item --with-sysroot=@var{dir}
38122Use @var{dir} as the default system root directory for libraries whose
38123file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38124@var{dir} can be modified at run time by using the @command{set
38125sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38126prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38127default system root will be automatically adjusted if and when
38128@value{GDBN} is moved to a different location.
38129
38130@item --with-system-gdbinit=@var{file}
38131Configure @value{GDBN} to automatically load a system-wide init file.
38132@var{file} should be an absolute file name. If @var{file} is in a
38133directory under the configured prefix, and @value{GDBN} is moved to
38134another location after being built, the location of the system-wide
38135init file will be adjusted accordingly.
38136
ed2a2229
CB
38137@item --with-system-gdbinit-dir=@var{directory}
38138Configure @value{GDBN} to automatically load init files from a
38139system-wide directory. @var{directory} should be an absolute directory
38140name. If @var{directory} is in a directory under the configured
38141prefix, and @value{GDBN} is moved to another location after being
38142built, the location of the system-wide init directory will be
38143adjusted accordingly.
38144
a95746f9
TT
38145@item --enable-build-warnings
38146When building the @value{GDBN} sources, ask the compiler to warn about
38147any code which looks even vaguely suspicious. It passes many
38148different warning flags, depending on the exact version of the
38149compiler you are using.
38150
38151@item --enable-werror
38152Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38153to the compiler, which will fail the compilation if the compiler
38154outputs any warning messages.
f35d5ade
TT
38155
38156@item --enable-ubsan
eff98030
TT
38157Enable the GCC undefined behavior sanitizer. This is disabled by
38158default, but passing @code{--enable-ubsan=yes} or
38159@code{--enable-ubsan=auto} to @code{configure} will enable it. The
38160undefined behavior sanitizer checks for C@t{++} undefined behavior.
38161It has a performance cost, so if you are looking at @value{GDBN}'s
38162performance, you should disable it. The undefined behavior sanitizer
38163was first introduced in GCC 4.9.
a95746f9 38164@end table
c906108c 38165
098b41a6
JG
38166@node System-wide configuration
38167@section System-wide configuration and settings
38168@cindex system-wide init file
38169
ed2a2229
CB
38170@value{GDBN} can be configured to have a system-wide init file and a
38171system-wide init file directory; this file and files in that directory
38172(if they have a recognized file extension) will be read and executed at
38173startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 38174
ed2a2229 38175Here are the corresponding configure options:
098b41a6
JG
38176
38177@table @code
38178@item --with-system-gdbinit=@var{file}
38179Specify that the default location of the system-wide init file is
38180@var{file}.
ed2a2229
CB
38181@item --with-system-gdbinit-dir=@var{directory}
38182Specify that the default location of the system-wide init file directory
38183is @var{directory}.
098b41a6
JG
38184@end table
38185
38186If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 38187they may be subject to relocation. Two possible cases:
098b41a6
JG
38188
38189@itemize @bullet
38190@item
ed2a2229 38191If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
38192it will be subject to relocation. Suppose that the configure options
38193are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38194if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38195init file is looked for as @file{$install/etc/gdbinit} instead of
38196@file{$prefix/etc/gdbinit}.
38197
38198@item
38199By contrast, if the default location does not contain the prefix,
38200it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38201@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38202then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38203wherever @value{GDBN} is installed.
38204@end itemize
38205
e64e0392
DE
38206If the configured location of the system-wide init file (as given by the
38207@option{--with-system-gdbinit} option at configure time) is in the
38208data-directory (as specified by @option{--with-gdb-datadir} at configure
38209time) or in one of its subdirectories, then @value{GDBN} will look for the
38210system-wide init file in the directory specified by the
38211@option{--data-directory} command-line option.
38212Note that the system-wide init file is only read once, during @value{GDBN}
38213initialization. If the data-directory is changed after @value{GDBN} has
38214started with the @code{set data-directory} command, the file will not be
38215reread.
38216
ed2a2229
CB
38217This applies similarly to the system-wide directory specified in
38218@option{--with-system-gdbinit-dir}.
38219
38220Any supported scripting language can be used for these init files, as long
38221as the file extension matches the scripting language. To be interpreted
38222as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38223extension.
38224
5901af59
JB
38225@menu
38226* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38227@end menu
38228
38229@node System-wide Configuration Scripts
0201faac
JB
38230@subsection Installed System-wide Configuration Scripts
38231@cindex system-wide configuration scripts
38232
38233The @file{system-gdbinit} directory, located inside the data-directory
38234(as specified by @option{--with-gdb-datadir} at configure time) contains
38235a number of scripts which can be used as system-wide init files. To
38236automatically source those scripts at startup, @value{GDBN} should be
38237configured with @option{--with-system-gdbinit}. Otherwise, any user
38238should be able to source them by hand as needed.
38239
38240The following scripts are currently available:
38241@itemize @bullet
38242
38243@item @file{elinos.py}
38244@pindex elinos.py
38245@cindex ELinOS system-wide configuration script
38246This script is useful when debugging a program on an ELinOS target.
38247It takes advantage of the environment variables defined in a standard
38248ELinOS environment in order to determine the location of the system
38249shared libraries, and then sets the @samp{solib-absolute-prefix}
38250and @samp{solib-search-path} variables appropriately.
38251
38252@item @file{wrs-linux.py}
38253@pindex wrs-linux.py
38254@cindex Wind River Linux system-wide configuration script
38255This script is useful when debugging a program on a target running
38256Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38257the host-side sysroot used by the target system.
38258
38259@end itemize
38260
8e04817f
AC
38261@node Maintenance Commands
38262@appendix Maintenance Commands
38263@cindex maintenance commands
38264@cindex internal commands
c906108c 38265
8e04817f 38266In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
38267includes a number of commands intended for @value{GDBN} developers,
38268that are not documented elsewhere in this manual. These commands are
da316a69
EZ
38269provided here for reference. (For commands that turn on debugging
38270messages, see @ref{Debugging Output}.)
c906108c 38271
8e04817f 38272@table @code
09d4efe1 38273@kindex maint agent
782b2b07 38274@kindex maint agent-eval
f77cc5f0
HZ
38275@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38276@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38277Translate the given @var{expression} into remote agent bytecodes.
38278This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38279(@pxref{Agent Expressions}). The @samp{agent} version produces an
38280expression useful for data collection, such as by tracepoints, while
38281@samp{maint agent-eval} produces an expression that evaluates directly
38282to a result. For instance, a collection expression for @code{globa +
38283globb} will include bytecodes to record four bytes of memory at each
38284of the addresses of @code{globa} and @code{globb}, while discarding
38285the result of the addition, while an evaluation expression will do the
38286addition and return the sum.
f77cc5f0
HZ
38287If @code{-at} is given, generate remote agent bytecode for @var{location}.
38288If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38289
d3ce09f5
SS
38290@kindex maint agent-printf
38291@item maint agent-printf @var{format},@var{expr},...
38292Translate the given format string and list of argument expressions
38293into remote agent bytecodes and display them as a disassembled list.
38294This command is useful for debugging the agent version of dynamic
6dd24dfa 38295printf (@pxref{Dynamic Printf}).
d3ce09f5 38296
8e04817f
AC
38297@kindex maint info breakpoints
38298@item @anchor{maint info breakpoints}maint info breakpoints
38299Using the same format as @samp{info breakpoints}, display both the
38300breakpoints you've set explicitly, and those @value{GDBN} is using for
38301internal purposes. Internal breakpoints are shown with negative
38302breakpoint numbers. The type column identifies what kind of breakpoint
38303is shown:
c906108c 38304
8e04817f
AC
38305@table @code
38306@item breakpoint
38307Normal, explicitly set breakpoint.
c906108c 38308
8e04817f
AC
38309@item watchpoint
38310Normal, explicitly set watchpoint.
c906108c 38311
8e04817f
AC
38312@item longjmp
38313Internal breakpoint, used to handle correctly stepping through
38314@code{longjmp} calls.
c906108c 38315
8e04817f
AC
38316@item longjmp resume
38317Internal breakpoint at the target of a @code{longjmp}.
c906108c 38318
8e04817f
AC
38319@item until
38320Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38321
8e04817f
AC
38322@item finish
38323Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38324
8e04817f
AC
38325@item shlib events
38326Shared library events.
c906108c 38327
8e04817f 38328@end table
c906108c 38329
b0627500
MM
38330@kindex maint info btrace
38331@item maint info btrace
38332Pint information about raw branch tracing data.
38333
38334@kindex maint btrace packet-history
38335@item maint btrace packet-history
38336Print the raw branch trace packets that are used to compute the
38337execution history for the @samp{record btrace} command. Both the
38338information and the format in which it is printed depend on the btrace
38339recording format.
38340
38341@table @code
38342@item bts
38343For the BTS recording format, print a list of blocks of sequential
38344code. For each block, the following information is printed:
38345
38346@table @asis
38347@item Block number
38348Newer blocks have higher numbers. The oldest block has number zero.
38349@item Lowest @samp{PC}
38350@item Highest @samp{PC}
38351@end table
38352
38353@item pt
bc504a31
PA
38354For the Intel Processor Trace recording format, print a list of
38355Intel Processor Trace packets. For each packet, the following
b0627500
MM
38356information is printed:
38357
38358@table @asis
38359@item Packet number
38360Newer packets have higher numbers. The oldest packet has number zero.
38361@item Trace offset
38362The packet's offset in the trace stream.
38363@item Packet opcode and payload
38364@end table
38365@end table
38366
38367@kindex maint btrace clear-packet-history
38368@item maint btrace clear-packet-history
38369Discards the cached packet history printed by the @samp{maint btrace
38370packet-history} command. The history will be computed again when
38371needed.
38372
38373@kindex maint btrace clear
38374@item maint btrace clear
38375Discard the branch trace data. The data will be fetched anew and the
38376branch trace will be recomputed when needed.
38377
38378This implicitly truncates the branch trace to a single branch trace
38379buffer. When updating branch trace incrementally, the branch trace
38380available to @value{GDBN} may be bigger than a single branch trace
38381buffer.
38382
38383@kindex maint set btrace pt skip-pad
38384@item maint set btrace pt skip-pad
38385@kindex maint show btrace pt skip-pad
38386@item maint show btrace pt skip-pad
38387Control whether @value{GDBN} will skip PAD packets when computing the
38388packet history.
38389
fff08868
HZ
38390@kindex set displaced-stepping
38391@kindex show displaced-stepping
237fc4c9
PA
38392@cindex displaced stepping support
38393@cindex out-of-line single-stepping
fff08868
HZ
38394@item set displaced-stepping
38395@itemx show displaced-stepping
237fc4c9 38396Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38397if the target supports it. Displaced stepping is a way to single-step
38398over breakpoints without removing them from the inferior, by executing
38399an out-of-line copy of the instruction that was originally at the
38400breakpoint location. It is also known as out-of-line single-stepping.
38401
38402@table @code
38403@item set displaced-stepping on
38404If the target architecture supports it, @value{GDBN} will use
38405displaced stepping to step over breakpoints.
38406
38407@item set displaced-stepping off
38408@value{GDBN} will not use displaced stepping to step over breakpoints,
38409even if such is supported by the target architecture.
38410
38411@cindex non-stop mode, and @samp{set displaced-stepping}
38412@item set displaced-stepping auto
38413This is the default mode. @value{GDBN} will use displaced stepping
38414only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38415architecture supports displaced stepping.
38416@end table
237fc4c9 38417
7d0c9981
DE
38418@kindex maint check-psymtabs
38419@item maint check-psymtabs
38420Check the consistency of currently expanded psymtabs versus symtabs.
38421Use this to check, for example, whether a symbol is in one but not the other.
38422
09d4efe1
EZ
38423@kindex maint check-symtabs
38424@item maint check-symtabs
7d0c9981
DE
38425Check the consistency of currently expanded symtabs.
38426
38427@kindex maint expand-symtabs
38428@item maint expand-symtabs [@var{regexp}]
38429Expand symbol tables.
38430If @var{regexp} is specified, only expand symbol tables for file
38431names matching @var{regexp}.
09d4efe1 38432
992c7d70
GB
38433@kindex maint set catch-demangler-crashes
38434@kindex maint show catch-demangler-crashes
38435@cindex demangler crashes
38436@item maint set catch-demangler-crashes [on|off]
38437@itemx maint show catch-demangler-crashes
38438Control whether @value{GDBN} should attempt to catch crashes in the
38439symbol name demangler. The default is to attempt to catch crashes.
38440If enabled, the first time a crash is caught, a core file is created,
38441the offending symbol is displayed and the user is presented with the
38442option to terminate the current session.
38443
09d4efe1
EZ
38444@kindex maint cplus first_component
38445@item maint cplus first_component @var{name}
38446Print the first C@t{++} class/namespace component of @var{name}.
38447
38448@kindex maint cplus namespace
38449@item maint cplus namespace
38450Print the list of possible C@t{++} namespaces.
38451
09d4efe1
EZ
38452@kindex maint deprecate
38453@kindex maint undeprecate
38454@cindex deprecated commands
38455@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38456@itemx maint undeprecate @var{command}
38457Deprecate or undeprecate the named @var{command}. Deprecated commands
38458cause @value{GDBN} to issue a warning when you use them. The optional
38459argument @var{replacement} says which newer command should be used in
38460favor of the deprecated one; if it is given, @value{GDBN} will mention
38461the replacement as part of the warning.
38462
38463@kindex maint dump-me
38464@item maint dump-me
721c2651 38465@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38466Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38467This is supported only on systems which support aborting a program
38468with the @code{SIGQUIT} signal.
09d4efe1 38469
8d30a00d
AC
38470@kindex maint internal-error
38471@kindex maint internal-warning
57fcfb1b
GB
38472@kindex maint demangler-warning
38473@cindex demangler crashes
09d4efe1
EZ
38474@item maint internal-error @r{[}@var{message-text}@r{]}
38475@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38476@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38477
38478Cause @value{GDBN} to call the internal function @code{internal_error},
38479@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38480as though an internal problem has been detected. In addition to
57fcfb1b
GB
38481reporting the internal problem, these functions give the user the
38482opportunity to either quit @value{GDBN} or (for @code{internal_error}
38483and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38484@value{GDBN} session.
38485
09d4efe1
EZ
38486These commands take an optional parameter @var{message-text} that is
38487used as the text of the error or warning message.
38488
d3e8051b 38489Here's an example of using @code{internal-error}:
09d4efe1 38490
8d30a00d 38491@smallexample
f7dc1244 38492(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38493@dots{}/maint.c:121: internal-error: testing, 1, 2
38494A problem internal to GDB has been detected. Further
38495debugging may prove unreliable.
38496Quit this debugging session? (y or n) @kbd{n}
38497Create a core file? (y or n) @kbd{n}
f7dc1244 38498(@value{GDBP})
8d30a00d
AC
38499@end smallexample
38500
3c16cced
PA
38501@cindex @value{GDBN} internal error
38502@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38503@cindex demangler crashes
3c16cced
PA
38504
38505@kindex maint set internal-error
38506@kindex maint show internal-error
38507@kindex maint set internal-warning
38508@kindex maint show internal-warning
57fcfb1b
GB
38509@kindex maint set demangler-warning
38510@kindex maint show demangler-warning
3c16cced
PA
38511@item maint set internal-error @var{action} [ask|yes|no]
38512@itemx maint show internal-error @var{action}
38513@itemx maint set internal-warning @var{action} [ask|yes|no]
38514@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38515@itemx maint set demangler-warning @var{action} [ask|yes|no]
38516@itemx maint show demangler-warning @var{action}
3c16cced
PA
38517When @value{GDBN} reports an internal problem (error or warning) it
38518gives the user the opportunity to both quit @value{GDBN} and create a
38519core file of the current @value{GDBN} session. These commands let you
38520override the default behaviour for each particular @var{action},
38521described in the table below.
38522
38523@table @samp
38524@item quit
38525You can specify that @value{GDBN} should always (yes) or never (no)
38526quit. The default is to ask the user what to do.
38527
38528@item corefile
38529You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38530create a core file. The default is to ask the user what to do. Note
38531that there is no @code{corefile} option for @code{demangler-warning}:
38532demangler warnings always create a core file and this cannot be
38533disabled.
3c16cced
PA
38534@end table
38535
09d4efe1
EZ
38536@kindex maint packet
38537@item maint packet @var{text}
38538If @value{GDBN} is talking to an inferior via the serial protocol,
38539then this command sends the string @var{text} to the inferior, and
38540displays the response packet. @value{GDBN} supplies the initial
38541@samp{$} character, the terminating @samp{#} character, and the
38542checksum.
38543
38544@kindex maint print architecture
38545@item maint print architecture @r{[}@var{file}@r{]}
38546Print the entire architecture configuration. The optional argument
38547@var{file} names the file where the output goes.
8d30a00d 38548
8e2141c6 38549@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 38550@item maint print c-tdesc
8e2141c6
YQ
38551Print the target description (@pxref{Target Descriptions}) as
38552a C source file. By default, the target description is for the current
38553target, but if the optional argument @var{file} is provided, that file
38554is used to produce the description. The @var{file} should be an XML
38555document, of the form described in @ref{Target Description Format}.
38556The created source file is built into @value{GDBN} when @value{GDBN} is
38557built again. This command is used by developers after they add or
38558modify XML target descriptions.
81adfced 38559
caa7fd04
AB
38560@kindex maint print xml-tdesc
38561@item maint print xml-tdesc @r{[}@var{file}@r{]}
38562Print the target description (@pxref{Target Descriptions}) as an XML
38563file. By default print the target description for the current target,
38564but if the optional argument @var{file} is provided, then that file is
38565read in by GDB and then used to produce the description. The
38566@var{file} should be an XML document, of the form described in
38567@ref{Target Description Format}.
38568
27d41eac
YQ
38569@kindex maint check xml-descriptions
38570@item maint check xml-descriptions @var{dir}
38571Check that the target descriptions dynamically created by @value{GDBN}
38572equal the descriptions created from XML files found in @var{dir}.
38573
41fc26a2 38574@anchor{maint check libthread-db}
5045b3d7
GB
38575@kindex maint check libthread-db
38576@item maint check libthread-db
38577Run integrity checks on the current inferior's thread debugging
38578library. This exercises all @code{libthread_db} functionality used by
38579@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38580@code{proc_service} functions provided by @value{GDBN} that
38581@code{libthread_db} uses. Note that parts of the test may be skipped
38582on some platforms when debugging core files.
38583
b089853a
KB
38584@kindex maint print core-file-backed-mappings
38585@cindex memory address space mappings
38586@item maint print core-file-backed-mappings
38587Print the file-backed mappings which were loaded from a core file note.
38588This output represents state internal to @value{GDBN} and should be
38589similar to the mappings displayed by the @code{info proc mappings}
38590command.
38591
00905d52
AC
38592@kindex maint print dummy-frames
38593@item maint print dummy-frames
00905d52
AC
38594Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38595
38596@smallexample
f7dc1244 38597(@value{GDBP}) @kbd{b add}
00905d52 38598@dots{}
f7dc1244 38599(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38600Breakpoint 2, add (a=2, b=3) at @dots{}
3860158 return (a + b);
38602The program being debugged stopped while in a function called from GDB.
38603@dots{}
f7dc1244 38604(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 386050xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38606(@value{GDBP})
00905d52
AC
38607@end smallexample
38608
38609Takes an optional file parameter.
38610
0680b120
AC
38611@kindex maint print registers
38612@kindex maint print raw-registers
38613@kindex maint print cooked-registers
617073a9 38614@kindex maint print register-groups
c21236dc 38615@kindex maint print remote-registers
09d4efe1
EZ
38616@item maint print registers @r{[}@var{file}@r{]}
38617@itemx maint print raw-registers @r{[}@var{file}@r{]}
38618@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38619@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38620@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38621Print @value{GDBN}'s internal register data structures.
38622
617073a9 38623The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38624the raw register cache; the command @code{maint print
38625cooked-registers} includes the (cooked) value of all registers,
38626including registers which aren't available on the target nor visible
38627to user; the command @code{maint print register-groups} includes the
38628groups that each register is a member of; and the command @code{maint
38629print remote-registers} includes the remote target's register numbers
0a7cfe2c 38630and offsets in the `G' packets.
0680b120 38631
09d4efe1
EZ
38632These commands take an optional parameter, a file name to which to
38633write the information.
0680b120 38634
617073a9 38635@kindex maint print reggroups
09d4efe1
EZ
38636@item maint print reggroups @r{[}@var{file}@r{]}
38637Print @value{GDBN}'s internal register group data structures. The
38638optional argument @var{file} tells to what file to write the
38639information.
617073a9 38640
09d4efe1 38641The register groups info looks like this:
617073a9
AC
38642
38643@smallexample
f7dc1244 38644(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38645 Group Type
38646 general user
38647 float user
38648 all user
38649 vector user
38650 system user
38651 save internal
38652 restore internal
617073a9
AC
38653@end smallexample
38654
09d4efe1
EZ
38655@kindex flushregs
38656@item flushregs
38657This command forces @value{GDBN} to flush its internal register cache.
38658
38659@kindex maint print objfiles
38660@cindex info for known object files
52e260a3
DE
38661@item maint print objfiles @r{[}@var{regexp}@r{]}
38662Print a dump of all known object files.
38663If @var{regexp} is specified, only print object files whose names
38664match @var{regexp}. For each object file, this command prints its name,
38665address in memory, and all of its psymtabs and symtabs.
09d4efe1 38666
f5b95c01
AA
38667@kindex maint print user-registers
38668@cindex user registers
38669@item maint print user-registers
38670List all currently available @dfn{user registers}. User registers
38671typically provide alternate names for actual hardware registers. They
38672include the four ``standard'' registers @code{$fp}, @code{$pc},
38673@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38674registers can be used in expressions in the same way as the canonical
38675register names, but only the latter are listed by the @code{info
38676registers} and @code{maint print registers} commands.
38677
8a1ea21f
DE
38678@kindex maint print section-scripts
38679@cindex info for known .debug_gdb_scripts-loaded scripts
38680@item maint print section-scripts [@var{regexp}]
38681Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38682If @var{regexp} is specified, only print scripts loaded by object files
38683matching @var{regexp}.
38684For each script, this command prints its name as specified in the objfile,
38685and the full path if known.
8e0583c8 38686@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38687
09d4efe1
EZ
38688@kindex maint print statistics
38689@cindex bcache statistics
38690@item maint print statistics
38691This command prints, for each object file in the program, various data
38692about that object file followed by the byte cache (@dfn{bcache})
38693statistics for the object file. The objfile data includes the number
d3e8051b 38694of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38695defined by the objfile, the number of as yet unexpanded psym tables,
38696the number of line tables and string tables, and the amount of memory
38697used by the various tables. The bcache statistics include the counts,
38698sizes, and counts of duplicates of all and unique objects, max,
38699average, and median entry size, total memory used and its overhead and
38700savings, and various measures of the hash table size and chain
38701lengths.
38702
c7ba131e
JB
38703@kindex maint print target-stack
38704@cindex target stack description
38705@item maint print target-stack
38706A @dfn{target} is an interface between the debugger and a particular
38707kind of file or process. Targets can be stacked in @dfn{strata},
38708so that more than one target can potentially respond to a request.
38709In particular, memory accesses will walk down the stack of targets
38710until they find a target that is interested in handling that particular
38711address.
38712
38713This command prints a short description of each layer that was pushed on
38714the @dfn{target stack}, starting from the top layer down to the bottom one.
38715
09d4efe1
EZ
38716@kindex maint print type
38717@cindex type chain of a data type
38718@item maint print type @var{expr}
38719Print the type chain for a type specified by @var{expr}. The argument
38720can be either a type name or a symbol. If it is a symbol, the type of
38721that symbol is described. The type chain produced by this command is
38722a recursive definition of the data type as stored in @value{GDBN}'s
38723data structures, including its flags and contained types.
38724
dcd1f979
TT
38725@kindex maint selftest
38726@cindex self tests
1526853e 38727@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
38728Run any self tests that were compiled in to @value{GDBN}. This will
38729print a message showing how many tests were run, and how many failed.
1526853e
SM
38730If a @var{filter} is passed, only the tests with @var{filter} in their
38731name will by ran.
38732
3c2fcaf9 38733@kindex maint info selftests
1526853e
SM
38734@cindex self tests
38735@item maint info selftests
38736List the selftests compiled in to @value{GDBN}.
dcd1f979 38737
b4f54984
DE
38738@kindex maint set dwarf always-disassemble
38739@kindex maint show dwarf always-disassemble
38740@item maint set dwarf always-disassemble
38741@item maint show dwarf always-disassemble
9eae7c52
TT
38742Control the behavior of @code{info address} when using DWARF debugging
38743information.
38744
38745The default is @code{off}, which means that @value{GDBN} should try to
38746describe a variable's location in an easily readable format. When
38747@code{on}, @value{GDBN} will instead display the DWARF location
38748expression in an assembly-like format. Note that some locations are
38749too complex for @value{GDBN} to describe simply; in this case you will
38750always see the disassembly form.
38751
38752Here is an example of the resulting disassembly:
38753
38754@smallexample
38755(gdb) info addr argc
38756Symbol "argc" is a complex DWARF expression:
38757 1: DW_OP_fbreg 0
38758@end smallexample
38759
38760For more information on these expressions, see
38761@uref{http://www.dwarfstd.org/, the DWARF standard}.
38762
b4f54984
DE
38763@kindex maint set dwarf max-cache-age
38764@kindex maint show dwarf max-cache-age
38765@item maint set dwarf max-cache-age
38766@itemx maint show dwarf max-cache-age
38767Control the DWARF compilation unit cache.
09d4efe1 38768
b4f54984 38769@cindex DWARF compilation units cache
09d4efe1 38770In object files with inter-compilation-unit references, such as those
b4f54984 38771produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
38772reader needs to frequently refer to previously read compilation units.
38773This setting controls how long a compilation unit will remain in the
38774cache if it is not referenced. A higher limit means that cached
38775compilation units will be stored in memory longer, and more total
38776memory will be used. Setting it to zero disables caching, which will
38777slow down @value{GDBN} startup, but reduce memory consumption.
38778
3c3bb058
AB
38779@kindex maint set dwarf unwinders
38780@kindex maint show dwarf unwinders
38781@item maint set dwarf unwinders
38782@itemx maint show dwarf unwinders
38783Control use of the DWARF frame unwinders.
38784
38785@cindex DWARF frame unwinders
38786Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38787frame unwinders to build the backtrace. Many of these targets will
38788also have a second mechanism for building the backtrace for use in
38789cases where DWARF information is not available, this second mechanism
38790is often an analysis of a function's prologue.
38791
38792In order to extend testing coverage of the second level stack
38793unwinding mechanisms it is helpful to be able to disable the DWARF
38794stack unwinders, this can be done with this switch.
38795
38796In normal use of @value{GDBN} disabling the DWARF unwinders is not
38797advisable, there are cases that are better handled through DWARF than
38798prologue analysis, and the debug experience is likely to be better
38799with the DWARF frame unwinders enabled.
38800
38801If DWARF frame unwinders are not supported for a particular target
38802architecture, then enabling this flag does not cause them to be used.
22138db6
TT
38803
38804@kindex maint set worker-threads
38805@kindex maint show worker-threads
38806@item maint set worker-threads
38807@item maint show worker-threads
38808Control the number of worker threads that may be used by @value{GDBN}.
38809On capable hosts, @value{GDBN} may use multiple threads to speed up
38810certain CPU-intensive operations, such as demangling symbol names.
38811While the number of threads used by @value{GDBN} may vary, this
38812command can be used to set an upper bound on this number. The default
38813is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38814number. Note that this only controls worker threads started by
38815@value{GDBN} itself; libraries used by @value{GDBN} may start threads
38816of their own.
38817
e7ba9c65
DJ
38818@kindex maint set profile
38819@kindex maint show profile
38820@cindex profiling GDB
38821@item maint set profile
38822@itemx maint show profile
38823Control profiling of @value{GDBN}.
38824
38825Profiling will be disabled until you use the @samp{maint set profile}
38826command to enable it. When you enable profiling, the system will begin
38827collecting timing and execution count data; when you disable profiling or
38828exit @value{GDBN}, the results will be written to a log file. Remember that
38829if you use profiling, @value{GDBN} will overwrite the profiling log file
38830(often called @file{gmon.out}). If you have a record of important profiling
38831data in a @file{gmon.out} file, be sure to move it to a safe location.
38832
38833Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 38834compiled with the @samp{-pg} compiler option.
e7ba9c65 38835
cbe54154
PA
38836@kindex maint set show-debug-regs
38837@kindex maint show show-debug-regs
eac35c4e 38838@cindex hardware debug registers
cbe54154
PA
38839@item maint set show-debug-regs
38840@itemx maint show show-debug-regs
eac35c4e 38841Control whether to show variables that mirror the hardware debug
6dd315ba 38842registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 38843enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
38844removes a hardware breakpoint or watchpoint, and when the inferior
38845triggers a hardware-assisted breakpoint or watchpoint.
38846
711e434b
PM
38847@kindex maint set show-all-tib
38848@kindex maint show show-all-tib
38849@item maint set show-all-tib
38850@itemx maint show show-all-tib
38851Control whether to show all non zero areas within a 1k block starting
38852at thread local base, when using the @samp{info w32 thread-information-block}
38853command.
38854
329ea579
PA
38855@kindex maint set target-async
38856@kindex maint show target-async
38857@item maint set target-async
38858@itemx maint show target-async
38859This controls whether @value{GDBN} targets operate in synchronous or
38860asynchronous mode (@pxref{Background Execution}). Normally the
38861default is asynchronous, if it is available; but this can be changed
38862to more easily debug problems occurring only in synchronous mode.
38863
fbea99ea
PA
38864@kindex maint set target-non-stop @var{mode} [on|off|auto]
38865@kindex maint show target-non-stop
38866@item maint set target-non-stop
38867@itemx maint show target-non-stop
38868
38869This controls whether @value{GDBN} targets always operate in non-stop
38870mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38871Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38872if supported by the target.
38873
38874@table @code
38875@item maint set target-non-stop auto
38876This is the default mode. @value{GDBN} controls the target in
38877non-stop mode if the target supports it.
38878
38879@item maint set target-non-stop on
38880@value{GDBN} controls the target in non-stop mode even if the target
38881does not indicate support.
38882
38883@item maint set target-non-stop off
38884@value{GDBN} does not control the target in non-stop mode even if the
38885target supports it.
38886@end table
38887
45e42163
TT
38888@kindex maint set tui-resize-message
38889@kindex maint show tui-resize-message
38890@item maint set tui-resize-message
38891@item maint show tui-resize-message
38892Control whether @value{GDBN} displays a message each time the terminal
38893is resized when in TUI mode. The default is @code{off}, which means
38894that @value{GDBN} is silent during resizes. When @code{on},
38895@value{GDBN} will display a message after a resize is completed; the
38896message will include a number indicating how many times the terminal
38897has been resized. This setting is intended for use by the test suite,
38898where it would otherwise be difficult to determine when a resize and
38899refresh has been completed.
38900
bd712aed
DE
38901@kindex maint set per-command
38902@kindex maint show per-command
38903@item maint set per-command
38904@itemx maint show per-command
38905@cindex resources used by commands
09d4efe1 38906
bd712aed
DE
38907@value{GDBN} can display the resources used by each command.
38908This is useful in debugging performance problems.
38909
38910@table @code
38911@item maint set per-command space [on|off]
38912@itemx maint show per-command space
38913Enable or disable the printing of the memory used by GDB for each command.
38914If enabled, @value{GDBN} will display how much memory each command
38915took, following the command's own output.
38916This can also be requested by invoking @value{GDBN} with the
38917@option{--statistics} command-line switch (@pxref{Mode Options}).
38918
38919@item maint set per-command time [on|off]
38920@itemx maint show per-command time
38921Enable or disable the printing of the execution time of @value{GDBN}
38922for each command.
38923If enabled, @value{GDBN} will display how much time it
09d4efe1 38924took to execute each command, following the command's own output.
0a1c4d10
DE
38925Both CPU time and wallclock time are printed.
38926Printing both is useful when trying to determine whether the cost is
bd712aed 38927CPU or, e.g., disk/network latency.
0a1c4d10
DE
38928Note that the CPU time printed is for @value{GDBN} only, it does not include
38929the execution time of the inferior because there's no mechanism currently
38930to compute how much time was spent by @value{GDBN} and how much time was
38931spent by the program been debugged.
09d4efe1
EZ
38932This can also be requested by invoking @value{GDBN} with the
38933@option{--statistics} command-line switch (@pxref{Mode Options}).
38934
bd712aed
DE
38935@item maint set per-command symtab [on|off]
38936@itemx maint show per-command symtab
38937Enable or disable the printing of basic symbol table statistics
38938for each command.
38939If enabled, @value{GDBN} will display the following information:
38940
215b9f98
EZ
38941@enumerate a
38942@item
38943number of symbol tables
38944@item
38945number of primary symbol tables
38946@item
38947number of blocks in the blockvector
38948@end enumerate
bd712aed
DE
38949@end table
38950
5045b3d7
GB
38951@kindex maint set check-libthread-db
38952@kindex maint show check-libthread-db
38953@item maint set check-libthread-db [on|off]
38954@itemx maint show check-libthread-db
38955Control whether @value{GDBN} should run integrity checks on inferior
38956specific thread debugging libraries as they are loaded. The default
38957is not to perform such checks. If any check fails @value{GDBN} will
38958unload the library and continue searching for a suitable candidate as
38959described in @ref{set libthread-db-search-path}. For more information
38960about the tests, see @ref{maint check libthread-db}.
38961
bd712aed
DE
38962@kindex maint space
38963@cindex memory used by commands
38964@item maint space @var{value}
38965An alias for @code{maint set per-command space}.
38966A non-zero value enables it, zero disables it.
38967
38968@kindex maint time
38969@cindex time of command execution
38970@item maint time @var{value}
38971An alias for @code{maint set per-command time}.
38972A non-zero value enables it, zero disables it.
38973
09d4efe1
EZ
38974@kindex maint translate-address
38975@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38976Find the symbol stored at the location specified by the address
38977@var{addr} and an optional section name @var{section}. If found,
38978@value{GDBN} prints the name of the closest symbol and an offset from
38979the symbol's location to the specified address. This is similar to
38980the @code{info address} command (@pxref{Symbols}), except that this
38981command also allows to find symbols in other sections.
ae038cb0 38982
c14c28ba
PP
38983If section was not specified, the section in which the symbol was found
38984is also printed. For dynamically linked executables, the name of
38985executable or shared library containing the symbol is printed as well.
38986
3345721a
PA
38987@kindex maint test-options
38988@item maint test-options require-delimiter
38989@itemx maint test-options unknown-is-error
38990@itemx maint test-options unknown-is-operand
38991These commands are used by the testsuite to validate the command
38992options framework. The @code{require-delimiter} variant requires a
38993double-dash delimiter to indicate end of options. The
38994@code{unknown-is-error} and @code{unknown-is-operand} do not. The
38995@code{unknown-is-error} variant throws an error on unknown option,
38996while @code{unknown-is-operand} treats unknown options as the start of
38997the command's operands. When run, the commands output the result of
38998the processed options. When completed, the commands store the
38999internal result of completion in a variable exposed by the @code{maint
39000show test-options-completion-result} command.
39001
39002@kindex maint show test-options-completion-result
39003@item maint show test-options-completion-result
39004Shows the result of completing the @code{maint test-options}
39005subcommands. This is used by the testsuite to validate completion
39006support in the command options framework.
39007
c6ac8931
PA
39008@kindex maint set test-settings
39009@kindex maint show test-settings
39010@item maint set test-settings @var{kind}
39011@itemx maint show test-settings @var{kind}
dca0f6c0
PA
39012These are representative commands for each @var{kind} of setting type
39013@value{GDBN} supports. They are used by the testsuite for exercising
39014the settings infrastructure.
fdbc9870
PA
39015
39016@kindex maint with
39017@item maint with @var{setting} [@var{value}] [-- @var{command}]
39018Like the @code{with} command, but works with @code{maintenance set}
39019variables. This is used by the testsuite to exercise the @code{with}
39020command's infrastructure.
39021
8e04817f 39022@end table
c906108c 39023
9c16f35a
EZ
39024The following command is useful for non-interactive invocations of
39025@value{GDBN}, such as in the test suite.
39026
39027@table @code
39028@item set watchdog @var{nsec}
39029@kindex set watchdog
39030@cindex watchdog timer
39031@cindex timeout for commands
39032Set the maximum number of seconds @value{GDBN} will wait for the
39033target operation to finish. If this time expires, @value{GDBN}
39034reports and error and the command is aborted.
39035
39036@item show watchdog
39037Show the current setting of the target wait timeout.
39038@end table
c906108c 39039
e0ce93ac 39040@node Remote Protocol
8e04817f 39041@appendix @value{GDBN} Remote Serial Protocol
c906108c 39042
ee2d5c50
AC
39043@menu
39044* Overview::
39045* Packets::
39046* Stop Reply Packets::
39047* General Query Packets::
a1dcb23a 39048* Architecture-Specific Protocol Details::
9d29849a 39049* Tracepoint Packets::
a6b151f1 39050* Host I/O Packets::
9a6253be 39051* Interrupts::
8b23ecc4
SL
39052* Notification Packets::
39053* Remote Non-Stop::
a6f3e723 39054* Packet Acknowledgment::
ee2d5c50 39055* Examples::
79a6e687 39056* File-I/O Remote Protocol Extension::
cfa9d6d9 39057* Library List Format::
2268b414 39058* Library List Format for SVR4 Targets::
79a6e687 39059* Memory Map Format::
dc146f7c 39060* Thread List Format::
b3b9301e 39061* Traceframe Info Format::
2ae8c8e7 39062* Branch Trace Format::
f4abbc16 39063* Branch Trace Configuration Format::
ee2d5c50
AC
39064@end menu
39065
39066@node Overview
39067@section Overview
39068
8e04817f
AC
39069There may be occasions when you need to know something about the
39070protocol---for example, if there is only one serial port to your target
39071machine, you might want your program to do something special if it
39072recognizes a packet meant for @value{GDBN}.
c906108c 39073
d2c6833e 39074In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 39075transmitted and received data, respectively.
c906108c 39076
8e04817f
AC
39077@cindex protocol, @value{GDBN} remote serial
39078@cindex serial protocol, @value{GDBN} remote
39079@cindex remote serial protocol
8b23ecc4
SL
39080All @value{GDBN} commands and responses (other than acknowledgments
39081and notifications, see @ref{Notification Packets}) are sent as a
39082@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
39083@samp{$}, the actual @var{packet-data}, and the terminating character
39084@samp{#} followed by a two-digit @var{checksum}:
c906108c 39085
474c8240 39086@smallexample
8e04817f 39087@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 39088@end smallexample
8e04817f 39089@noindent
c906108c 39090
8e04817f
AC
39091@cindex checksum, for @value{GDBN} remote
39092@noindent
39093The two-digit @var{checksum} is computed as the modulo 256 sum of all
39094characters between the leading @samp{$} and the trailing @samp{#} (an
39095eight bit unsigned checksum).
c906108c 39096
8e04817f
AC
39097Implementors should note that prior to @value{GDBN} 5.0 the protocol
39098specification also included an optional two-digit @var{sequence-id}:
c906108c 39099
474c8240 39100@smallexample
8e04817f 39101@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 39102@end smallexample
c906108c 39103
8e04817f
AC
39104@cindex sequence-id, for @value{GDBN} remote
39105@noindent
39106That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39107has never output @var{sequence-id}s. Stubs that handle packets added
39108since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 39109
8e04817f
AC
39110When either the host or the target machine receives a packet, the first
39111response expected is an acknowledgment: either @samp{+} (to indicate
39112the package was received correctly) or @samp{-} (to request
39113retransmission):
c906108c 39114
474c8240 39115@smallexample
d2c6833e
AC
39116-> @code{$}@var{packet-data}@code{#}@var{checksum}
39117<- @code{+}
474c8240 39118@end smallexample
8e04817f 39119@noindent
53a5351d 39120
a6f3e723
SL
39121The @samp{+}/@samp{-} acknowledgments can be disabled
39122once a connection is established.
39123@xref{Packet Acknowledgment}, for details.
39124
8e04817f
AC
39125The host (@value{GDBN}) sends @var{command}s, and the target (the
39126debugging stub incorporated in your program) sends a @var{response}. In
39127the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
39128when the operation has completed, and the target has again stopped all
39129threads in all attached processes. This is the default all-stop mode
39130behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39131execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 39132
8e04817f
AC
39133@var{packet-data} consists of a sequence of characters with the
39134exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39135exceptions).
c906108c 39136
ee2d5c50 39137@cindex remote protocol, field separator
0876f84a 39138Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 39139@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 39140@sc{hex} with leading zeros suppressed.
c906108c 39141
8e04817f
AC
39142Implementors should note that prior to @value{GDBN} 5.0, the character
39143@samp{:} could not appear as the third character in a packet (as it
39144would potentially conflict with the @var{sequence-id}).
c906108c 39145
0876f84a
DJ
39146@cindex remote protocol, binary data
39147@anchor{Binary Data}
39148Binary data in most packets is encoded either as two hexadecimal
39149digits per byte of binary data. This allowed the traditional remote
39150protocol to work over connections which were only seven-bit clean.
39151Some packets designed more recently assume an eight-bit clean
39152connection, and use a more efficient encoding to send and receive
39153binary data.
39154
39155The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39156as an escape character. Any escaped byte is transmitted as the escape
39157character followed by the original character XORed with @code{0x20}.
39158For example, the byte @code{0x7d} would be transmitted as the two
39159bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39160@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39161@samp{@}}) must always be escaped. Responses sent by the stub
39162must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39163is not interpreted as the start of a run-length encoded sequence
39164(described next).
39165
1d3811f6
DJ
39166Response @var{data} can be run-length encoded to save space.
39167Run-length encoding replaces runs of identical characters with one
39168instance of the repeated character, followed by a @samp{*} and a
39169repeat count. The repeat count is itself sent encoded, to avoid
39170binary characters in @var{data}: a value of @var{n} is sent as
39171@code{@var{n}+29}. For a repeat count greater or equal to 3, this
39172produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39173code 32) for a repeat count of 3. (This is because run-length
39174encoding starts to win for counts 3 or more.) Thus, for example,
39175@samp{0* } is a run-length encoding of ``0000'': the space character
39176after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
391773}} more times.
39178
39179The printable characters @samp{#} and @samp{$} or with a numeric value
39180greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39181seven repeats (@samp{$}) can be expanded using a repeat count of only
39182five (@samp{"}). For example, @samp{00000000} can be encoded as
39183@samp{0*"00}.
c906108c 39184
8e04817f
AC
39185The error response returned for some packets includes a two character
39186error number. That number is not well defined.
c906108c 39187
f8da2bff 39188@cindex empty response, for unsupported packets
8e04817f
AC
39189For any @var{command} not supported by the stub, an empty response
39190(@samp{$#00}) should be returned. That way it is possible to extend the
39191protocol. A newer @value{GDBN} can tell if a packet is supported based
39192on that response.
c906108c 39193
c9fe1b58
RT
39194At a minimum, a stub is required to support the @samp{?} command to
39195tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
393eab54
PA
39196commands for register access, and the @samp{m} and @samp{M} commands
39197for memory access. Stubs that only control single-threaded targets
c9fe1b58
RT
39198can implement run control with the @samp{c} (continue) command, and if
39199the target architecture supports hardware-assisted single-stepping,
39200the @samp{s} (step) command. Stubs that support multi-threading
39201targets should support the @samp{vCont} command. All other commands
39202are optional.
c906108c 39203
ee2d5c50
AC
39204@node Packets
39205@section Packets
39206
39207The following table provides a complete list of all currently defined
39208@var{command}s and their corresponding response @var{data}.
79a6e687 39209@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 39210I/O extension of the remote protocol.
ee2d5c50 39211
b8ff78ce
JB
39212Each packet's description has a template showing the packet's overall
39213syntax, followed by an explanation of the packet's meaning. We
39214include spaces in some of the templates for clarity; these are not
39215part of the packet's syntax. No @value{GDBN} packet uses spaces to
39216separate its components. For example, a template like @samp{foo
39217@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39218bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 39219@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
39220@samp{foo} and the @var{bar}, or between the @var{bar} and the
39221@var{baz}.
39222
b90a069a
SL
39223@cindex @var{thread-id}, in remote protocol
39224@anchor{thread-id syntax}
39225Several packets and replies include a @var{thread-id} field to identify
39226a thread. Normally these are positive numbers with a target-specific
39227interpretation, formatted as big-endian hex strings. A @var{thread-id}
39228can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39229pick any thread.
39230
39231In addition, the remote protocol supports a multiprocess feature in
39232which the @var{thread-id} syntax is extended to optionally include both
39233process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39234The @var{pid} (process) and @var{tid} (thread) components each have the
39235format described above: a positive number with target-specific
39236interpretation formatted as a big-endian hex string, literal @samp{-1}
39237to indicate all processes or threads (respectively), or @samp{0} to
39238indicate an arbitrary process or thread. Specifying just a process, as
39239@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39240error to specify all processes but a specific thread, such as
39241@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39242for those packets and replies explicitly documented to include a process
39243ID, rather than a @var{thread-id}.
39244
39245The multiprocess @var{thread-id} syntax extensions are only used if both
39246@value{GDBN} and the stub report support for the @samp{multiprocess}
39247feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39248more information.
39249
8ffe2530
JB
39250Note that all packet forms beginning with an upper- or lower-case
39251letter, other than those described here, are reserved for future use.
39252
b8ff78ce 39253Here are the packet descriptions.
ee2d5c50 39254
b8ff78ce 39255@table @samp
ee2d5c50 39256
b8ff78ce
JB
39257@item !
39258@cindex @samp{!} packet
2d717e4f 39259@anchor{extended mode}
8e04817f
AC
39260Enable extended mode. In extended mode, the remote server is made
39261persistent. The @samp{R} packet is used to restart the program being
39262debugged.
ee2d5c50
AC
39263
39264Reply:
39265@table @samp
39266@item OK
8e04817f 39267The remote target both supports and has enabled extended mode.
ee2d5c50 39268@end table
c906108c 39269
b8ff78ce
JB
39270@item ?
39271@cindex @samp{?} packet
36cb1214 39272@anchor{? packet}
ee2d5c50 39273Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
39274step and continue. This packet has a special interpretation when the
39275target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 39276
ee2d5c50
AC
39277Reply:
39278@xref{Stop Reply Packets}, for the reply specifications.
39279
b8ff78ce
JB
39280@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39281@cindex @samp{A} packet
39282Initialized @code{argv[]} array passed into program. @var{arglen}
39283specifies the number of bytes in the hex encoded byte stream
39284@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
39285
39286Reply:
39287@table @samp
39288@item OK
b8ff78ce
JB
39289The arguments were set.
39290@item E @var{NN}
39291An error occurred.
ee2d5c50
AC
39292@end table
39293
b8ff78ce
JB
39294@item b @var{baud}
39295@cindex @samp{b} packet
39296(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39297Change the serial line speed to @var{baud}.
39298
39299JTC: @emph{When does the transport layer state change? When it's
39300received, or after the ACK is transmitted. In either case, there are
39301problems if the command or the acknowledgment packet is dropped.}
39302
39303Stan: @emph{If people really wanted to add something like this, and get
39304it working for the first time, they ought to modify ser-unix.c to send
39305some kind of out-of-band message to a specially-setup stub and have the
39306switch happen "in between" packets, so that from remote protocol's point
39307of view, nothing actually happened.}
39308
b8ff78ce
JB
39309@item B @var{addr},@var{mode}
39310@cindex @samp{B} packet
8e04817f 39311Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39312breakpoint at @var{addr}.
39313
b8ff78ce 39314Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39315(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39316
bacec72f 39317@cindex @samp{bc} packet
0d772ac9
MS
39318@anchor{bc}
39319@item bc
bacec72f
MS
39320Backward continue. Execute the target system in reverse. No parameter.
39321@xref{Reverse Execution}, for more information.
39322
39323Reply:
39324@xref{Stop Reply Packets}, for the reply specifications.
39325
bacec72f 39326@cindex @samp{bs} packet
0d772ac9
MS
39327@anchor{bs}
39328@item bs
bacec72f
MS
39329Backward single step. Execute one instruction in reverse. No parameter.
39330@xref{Reverse Execution}, for more information.
39331
39332Reply:
39333@xref{Stop Reply Packets}, for the reply specifications.
39334
4f553f88 39335@item c @r{[}@var{addr}@r{]}
b8ff78ce 39336@cindex @samp{c} packet
697aa1b7
EZ
39337Continue at @var{addr}, which is the address to resume. If @var{addr}
39338is omitted, resume at current address.
c906108c 39339
393eab54
PA
39340This packet is deprecated for multi-threading support. @xref{vCont
39341packet}.
39342
ee2d5c50
AC
39343Reply:
39344@xref{Stop Reply Packets}, for the reply specifications.
39345
4f553f88 39346@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39347@cindex @samp{C} packet
8e04817f 39348Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39349@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39350
393eab54
PA
39351This packet is deprecated for multi-threading support. @xref{vCont
39352packet}.
39353
ee2d5c50
AC
39354Reply:
39355@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39356
b8ff78ce
JB
39357@item d
39358@cindex @samp{d} packet
ee2d5c50
AC
39359Toggle debug flag.
39360
b8ff78ce
JB
39361Don't use this packet; instead, define a general set packet
39362(@pxref{General Query Packets}).
ee2d5c50 39363
b8ff78ce 39364@item D
b90a069a 39365@itemx D;@var{pid}
b8ff78ce 39366@cindex @samp{D} packet
b90a069a
SL
39367The first form of the packet is used to detach @value{GDBN} from the
39368remote system. It is sent to the remote target
07f31aa6 39369before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39370
b90a069a
SL
39371The second form, including a process ID, is used when multiprocess
39372protocol extensions are enabled (@pxref{multiprocess extensions}), to
39373detach only a specific process. The @var{pid} is specified as a
39374big-endian hex string.
39375
ee2d5c50
AC
39376Reply:
39377@table @samp
10fac096
NW
39378@item OK
39379for success
b8ff78ce 39380@item E @var{NN}
10fac096 39381for an error
ee2d5c50 39382@end table
c906108c 39383
b8ff78ce
JB
39384@item F @var{RC},@var{EE},@var{CF};@var{XX}
39385@cindex @samp{F} packet
39386A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39387This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39388Remote Protocol Extension}, for the specification.
ee2d5c50 39389
b8ff78ce 39390@item g
ee2d5c50 39391@anchor{read registers packet}
b8ff78ce 39392@cindex @samp{g} packet
ee2d5c50
AC
39393Read general registers.
39394
39395Reply:
39396@table @samp
39397@item @var{XX@dots{}}
8e04817f
AC
39398Each byte of register data is described by two hex digits. The bytes
39399with the register are transmitted in target byte order. The size of
b8ff78ce 39400each register and their position within the @samp{g} packet are
4a9bb1df 39401determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39402@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39403
39404When reading registers from a trace frame (@pxref{Analyze Collected
39405Data,,Using the Collected Data}), the stub may also return a string of
39406literal @samp{x}'s in place of the register data digits, to indicate
39407that the corresponding register has not been collected, thus its value
39408is unavailable. For example, for an architecture with 4 registers of
394094 bytes each, the following reply indicates to @value{GDBN} that
39410registers 0 and 2 have not been collected, while registers 1 and 3
39411have been collected, and both have zero value:
39412
39413@smallexample
39414-> @code{g}
39415<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39416@end smallexample
39417
b8ff78ce 39418@item E @var{NN}
ee2d5c50
AC
39419for an error.
39420@end table
c906108c 39421
b8ff78ce
JB
39422@item G @var{XX@dots{}}
39423@cindex @samp{G} packet
39424Write general registers. @xref{read registers packet}, for a
39425description of the @var{XX@dots{}} data.
ee2d5c50
AC
39426
39427Reply:
39428@table @samp
39429@item OK
39430for success
b8ff78ce 39431@item E @var{NN}
ee2d5c50
AC
39432for an error
39433@end table
39434
393eab54 39435@item H @var{op} @var{thread-id}
b8ff78ce 39436@cindex @samp{H} packet
8e04817f 39437Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39438@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39439should be @samp{c} for step and continue operations (note that this
393eab54 39440is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39441option), and @samp{g} for other operations. The thread designator
393eab54
PA
39442@var{thread-id} has the format and interpretation described in
39443@ref{thread-id syntax}.
ee2d5c50
AC
39444
39445Reply:
39446@table @samp
39447@item OK
39448for success
b8ff78ce 39449@item E @var{NN}
ee2d5c50
AC
39450for an error
39451@end table
c906108c 39452
8e04817f
AC
39453@c FIXME: JTC:
39454@c 'H': How restrictive (or permissive) is the thread model. If a
39455@c thread is selected and stopped, are other threads allowed
39456@c to continue to execute? As I mentioned above, I think the
39457@c semantics of each command when a thread is selected must be
39458@c described. For example:
39459@c
39460@c 'g': If the stub supports threads and a specific thread is
39461@c selected, returns the register block from that thread;
39462@c otherwise returns current registers.
39463@c
39464@c 'G' If the stub supports threads and a specific thread is
39465@c selected, sets the registers of the register block of
39466@c that thread; otherwise sets current registers.
c906108c 39467
b8ff78ce 39468@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39469@anchor{cycle step packet}
b8ff78ce
JB
39470@cindex @samp{i} packet
39471Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39472present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39473step starting at that address.
c906108c 39474
b8ff78ce
JB
39475@item I
39476@cindex @samp{I} packet
39477Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39478step packet}.
ee2d5c50 39479
b8ff78ce
JB
39480@item k
39481@cindex @samp{k} packet
39482Kill request.
c906108c 39483
36cb1214
HZ
39484The exact effect of this packet is not specified.
39485
39486For a bare-metal target, it may power cycle or reset the target
39487system. For that reason, the @samp{k} packet has no reply.
39488
39489For a single-process target, it may kill that process if possible.
39490
39491A multiple-process target may choose to kill just one process, or all
39492that are under @value{GDBN}'s control. For more precise control, use
39493the vKill packet (@pxref{vKill packet}).
39494
39495If the target system immediately closes the connection in response to
39496@samp{k}, @value{GDBN} does not consider the lack of packet
39497acknowledgment to be an error, and assumes the kill was successful.
39498
39499If connected using @kbd{target extended-remote}, and the target does
39500not close the connection in response to a kill request, @value{GDBN}
39501probes the target state as if a new connection was opened
39502(@pxref{? packet}).
c906108c 39503
b8ff78ce
JB
39504@item m @var{addr},@var{length}
39505@cindex @samp{m} packet
a86c90e6
SM
39506Read @var{length} addressable memory units starting at address @var{addr}
39507(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39508any particular boundary.
fb031cdf
JB
39509
39510The stub need not use any particular size or alignment when gathering
39511data from memory for the response; even if @var{addr} is word-aligned
39512and @var{length} is a multiple of the word size, the stub is free to
39513use byte accesses, or not. For this reason, this packet may not be
39514suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39515@cindex alignment of remote memory accesses
39516@cindex size of remote memory accesses
39517@cindex memory, alignment and size of remote accesses
c906108c 39518
ee2d5c50
AC
39519Reply:
39520@table @samp
39521@item @var{XX@dots{}}
a86c90e6
SM
39522Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39523The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39524server was able to read only part of the region of memory.
39525@item E @var{NN}
ee2d5c50
AC
39526@var{NN} is errno
39527@end table
39528
b8ff78ce
JB
39529@item M @var{addr},@var{length}:@var{XX@dots{}}
39530@cindex @samp{M} packet
a86c90e6
SM
39531Write @var{length} addressable memory units starting at address @var{addr}
39532(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39533byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39534
39535Reply:
39536@table @samp
39537@item OK
39538for success
b8ff78ce 39539@item E @var{NN}
8e04817f
AC
39540for an error (this includes the case where only part of the data was
39541written).
ee2d5c50 39542@end table
c906108c 39543
b8ff78ce
JB
39544@item p @var{n}
39545@cindex @samp{p} packet
39546Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39547@xref{read registers packet}, for a description of how the returned
39548register value is encoded.
ee2d5c50
AC
39549
39550Reply:
39551@table @samp
2e868123
AC
39552@item @var{XX@dots{}}
39553the register's value
b8ff78ce 39554@item E @var{NN}
2e868123 39555for an error
d57350ea 39556@item @w{}
2e868123 39557Indicating an unrecognized @var{query}.
ee2d5c50
AC
39558@end table
39559
b8ff78ce 39560@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39561@anchor{write register packet}
b8ff78ce
JB
39562@cindex @samp{P} packet
39563Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39564number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39565digits for each byte in the register (target byte order).
c906108c 39566
ee2d5c50
AC
39567Reply:
39568@table @samp
39569@item OK
39570for success
b8ff78ce 39571@item E @var{NN}
ee2d5c50
AC
39572for an error
39573@end table
39574
5f3bebba
JB
39575@item q @var{name} @var{params}@dots{}
39576@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39577@cindex @samp{q} packet
b8ff78ce 39578@cindex @samp{Q} packet
5f3bebba
JB
39579General query (@samp{q}) and set (@samp{Q}). These packets are
39580described fully in @ref{General Query Packets}.
c906108c 39581
b8ff78ce
JB
39582@item r
39583@cindex @samp{r} packet
8e04817f 39584Reset the entire system.
c906108c 39585
b8ff78ce 39586Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39587
b8ff78ce
JB
39588@item R @var{XX}
39589@cindex @samp{R} packet
697aa1b7 39590Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39591This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39592
8e04817f 39593The @samp{R} packet has no reply.
ee2d5c50 39594
4f553f88 39595@item s @r{[}@var{addr}@r{]}
b8ff78ce 39596@cindex @samp{s} packet
697aa1b7 39597Single step, resuming at @var{addr}. If
b8ff78ce 39598@var{addr} is omitted, resume at same address.
c906108c 39599
393eab54
PA
39600This packet is deprecated for multi-threading support. @xref{vCont
39601packet}.
39602
ee2d5c50
AC
39603Reply:
39604@xref{Stop Reply Packets}, for the reply specifications.
39605
4f553f88 39606@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39607@anchor{step with signal packet}
b8ff78ce
JB
39608@cindex @samp{S} packet
39609Step with signal. This is analogous to the @samp{C} packet, but
39610requests a single-step, rather than a normal resumption of execution.
c906108c 39611
393eab54
PA
39612This packet is deprecated for multi-threading support. @xref{vCont
39613packet}.
39614
ee2d5c50
AC
39615Reply:
39616@xref{Stop Reply Packets}, for the reply specifications.
39617
b8ff78ce
JB
39618@item t @var{addr}:@var{PP},@var{MM}
39619@cindex @samp{t} packet
8e04817f 39620Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39621@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39622There must be at least 3 digits in @var{addr}.
c906108c 39623
b90a069a 39624@item T @var{thread-id}
b8ff78ce 39625@cindex @samp{T} packet
b90a069a 39626Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39627
ee2d5c50
AC
39628Reply:
39629@table @samp
39630@item OK
39631thread is still alive
b8ff78ce 39632@item E @var{NN}
ee2d5c50
AC
39633thread is dead
39634@end table
39635
b8ff78ce
JB
39636@item v
39637Packets starting with @samp{v} are identified by a multi-letter name,
39638up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39639
2d717e4f
DJ
39640@item vAttach;@var{pid}
39641@cindex @samp{vAttach} packet
8b23ecc4
SL
39642Attach to a new process with the specified process ID @var{pid}.
39643The process ID is a
39644hexadecimal integer identifying the process. In all-stop mode, all
39645threads in the attached process are stopped; in non-stop mode, it may be
39646attached without being stopped if that is supported by the target.
39647
39648@c In non-stop mode, on a successful vAttach, the stub should set the
39649@c current thread to a thread of the newly-attached process. After
39650@c attaching, GDB queries for the attached process's thread ID with qC.
39651@c Also note that, from a user perspective, whether or not the
39652@c target is stopped on attach in non-stop mode depends on whether you
39653@c use the foreground or background version of the attach command, not
39654@c on what vAttach does; GDB does the right thing with respect to either
39655@c stopping or restarting threads.
2d717e4f
DJ
39656
39657This packet is only available in extended mode (@pxref{extended mode}).
39658
39659Reply:
39660@table @samp
39661@item E @var{nn}
39662for an error
39663@item @r{Any stop packet}
8b23ecc4
SL
39664for success in all-stop mode (@pxref{Stop Reply Packets})
39665@item OK
39666for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39667@end table
39668
b90a069a 39669@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39670@cindex @samp{vCont} packet
393eab54 39671@anchor{vCont packet}
b8ff78ce 39672Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39673
39674For each inferior thread, the leftmost action with a matching
39675@var{thread-id} is applied. Threads that don't match any action
39676remain in their current state. Thread IDs are specified using the
39677syntax described in @ref{thread-id syntax}. If multiprocess
39678extensions (@pxref{multiprocess extensions}) are supported, actions
39679can be specified to match all threads in a process by using the
39680@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39681@var{thread-id} matches all threads. Specifying no actions is an
39682error.
b90a069a
SL
39683
39684Currently supported actions are:
86d30acc 39685
b8ff78ce 39686@table @samp
86d30acc
DJ
39687@item c
39688Continue.
b8ff78ce 39689@item C @var{sig}
8b23ecc4 39690Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39691@item s
39692Step.
b8ff78ce 39693@item S @var{sig}
8b23ecc4
SL
39694Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39695@item t
39696Stop.
c1e36e3e
PA
39697@item r @var{start},@var{end}
39698Step once, and then keep stepping as long as the thread stops at
39699addresses between @var{start} (inclusive) and @var{end} (exclusive).
39700The remote stub reports a stop reply when either the thread goes out
39701of the range or is stopped due to an unrelated reason, such as hitting
39702a breakpoint. @xref{range stepping}.
39703
39704If the range is empty (@var{start} == @var{end}), then the action
39705becomes equivalent to the @samp{s} action. In other words,
39706single-step once, and report the stop (even if the stepped instruction
39707jumps to @var{start}).
39708
39709(A stop reply may be sent at any point even if the PC is still within
39710the stepping range; for example, it is valid to implement this packet
39711in a degenerate way as a single instruction step operation.)
39712
86d30acc
DJ
39713@end table
39714
8b23ecc4
SL
39715The optional argument @var{addr} normally associated with the
39716@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39717not supported in @samp{vCont}.
86d30acc 39718
08a0efd0
PA
39719The @samp{t} action is only relevant in non-stop mode
39720(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39721A stop reply should be generated for any affected thread not already stopped.
39722When a thread is stopped by means of a @samp{t} action,
39723the corresponding stop reply should indicate that the thread has stopped with
39724signal @samp{0}, regardless of whether the target uses some other signal
39725as an implementation detail.
39726
ca6eff59
PA
39727The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39728@samp{r} actions for threads that are already running. Conversely,
39729the server must ignore @samp{t} actions for threads that are already
39730stopped.
39731
39732@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 39733@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
39734the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39735
4220b2f8 39736The stub must support @samp{vCont} if it reports support for
ca6eff59 39737multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 39738
86d30acc
DJ
39739Reply:
39740@xref{Stop Reply Packets}, for the reply specifications.
39741
b8ff78ce
JB
39742@item vCont?
39743@cindex @samp{vCont?} packet
d3e8051b 39744Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
39745
39746Reply:
39747@table @samp
b8ff78ce
JB
39748@item vCont@r{[};@var{action}@dots{}@r{]}
39749The @samp{vCont} packet is supported. Each @var{action} is a supported
39750command in the @samp{vCont} packet.
d57350ea 39751@item @w{}
b8ff78ce 39752The @samp{vCont} packet is not supported.
86d30acc 39753@end table
ee2d5c50 39754
de979965
PA
39755@anchor{vCtrlC packet}
39756@item vCtrlC
39757@cindex @samp{vCtrlC} packet
39758Interrupt remote target as if a control-C was pressed on the remote
39759terminal. This is the equivalent to reacting to the @code{^C}
39760(@samp{\003}, the control-C character) character in all-stop mode
39761while the target is running, except this works in non-stop mode.
39762@xref{interrupting remote targets}, for more info on the all-stop
39763variant.
39764
39765Reply:
39766@table @samp
39767@item E @var{nn}
39768for an error
39769@item OK
39770for success
39771@end table
39772
a6b151f1
DJ
39773@item vFile:@var{operation}:@var{parameter}@dots{}
39774@cindex @samp{vFile} packet
39775Perform a file operation on the target system. For details,
39776see @ref{Host I/O Packets}.
39777
68437a39
DJ
39778@item vFlashErase:@var{addr},@var{length}
39779@cindex @samp{vFlashErase} packet
39780Direct the stub to erase @var{length} bytes of flash starting at
39781@var{addr}. The region may enclose any number of flash blocks, but
39782its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
39783flash block size appearing in the memory map (@pxref{Memory Map
39784Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
39785together, and sends a @samp{vFlashDone} request after each group; the
39786stub is allowed to delay erase operation until the @samp{vFlashDone}
39787packet is received.
39788
39789Reply:
39790@table @samp
39791@item OK
39792for success
39793@item E @var{NN}
39794for an error
39795@end table
39796
39797@item vFlashWrite:@var{addr}:@var{XX@dots{}}
39798@cindex @samp{vFlashWrite} packet
39799Direct the stub to write data to flash address @var{addr}. The data
39800is passed in binary form using the same encoding as for the @samp{X}
39801packet (@pxref{Binary Data}). The memory ranges specified by
39802@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39803not overlap, and must appear in order of increasing addresses
39804(although @samp{vFlashErase} packets for higher addresses may already
39805have been received; the ordering is guaranteed only between
39806@samp{vFlashWrite} packets). If a packet writes to an address that was
39807neither erased by a preceding @samp{vFlashErase} packet nor by some other
39808target-specific method, the results are unpredictable.
39809
39810
39811Reply:
39812@table @samp
39813@item OK
39814for success
39815@item E.memtype
39816for vFlashWrite addressing non-flash memory
39817@item E @var{NN}
39818for an error
39819@end table
39820
39821@item vFlashDone
39822@cindex @samp{vFlashDone} packet
39823Indicate to the stub that flash programming operation is finished.
39824The stub is permitted to delay or batch the effects of a group of
39825@samp{vFlashErase} and @samp{vFlashWrite} packets until a
39826@samp{vFlashDone} packet is received. The contents of the affected
39827regions of flash memory are unpredictable until the @samp{vFlashDone}
39828request is completed.
39829
b90a069a
SL
39830@item vKill;@var{pid}
39831@cindex @samp{vKill} packet
36cb1214 39832@anchor{vKill packet}
697aa1b7 39833Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
39834hexadecimal integer identifying the process. This packet is used in
39835preference to @samp{k} when multiprocess protocol extensions are
39836supported; see @ref{multiprocess extensions}.
39837
39838Reply:
39839@table @samp
39840@item E @var{nn}
39841for an error
39842@item OK
39843for success
39844@end table
39845
176efed1
AB
39846@item vMustReplyEmpty
39847@cindex @samp{vMustReplyEmpty} packet
39848The correct reply to an unknown @samp{v} packet is to return the empty
39849string, however, some older versions of @command{gdbserver} would
39850incorrectly return @samp{OK} for unknown @samp{v} packets.
39851
39852The @samp{vMustReplyEmpty} is used as a feature test to check how
39853@command{gdbserver} handles unknown packets, it is important that this
39854packet be handled in the same way as other unknown @samp{v} packets.
39855If this packet is handled differently to other unknown @samp{v}
6b92c0d3 39856packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
39857other areas, specifically around use of @samp{vFile:setfs:}.
39858
2d717e4f
DJ
39859@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39860@cindex @samp{vRun} packet
39861Run the program @var{filename}, passing it each @var{argument} on its
39862command line. The file and arguments are hex-encoded strings. If
39863@var{filename} is an empty string, the stub may use a default program
39864(e.g.@: the last program run). The program is created in the stopped
9b562ab8 39865state.
2d717e4f 39866
8b23ecc4
SL
39867@c FIXME: What about non-stop mode?
39868
2d717e4f
DJ
39869This packet is only available in extended mode (@pxref{extended mode}).
39870
39871Reply:
39872@table @samp
39873@item E @var{nn}
39874for an error
39875@item @r{Any stop packet}
39876for success (@pxref{Stop Reply Packets})
39877@end table
39878
8b23ecc4 39879@item vStopped
8b23ecc4 39880@cindex @samp{vStopped} packet
8dbe8ece 39881@xref{Notification Packets}.
8b23ecc4 39882
b8ff78ce 39883@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 39884@anchor{X packet}
b8ff78ce
JB
39885@cindex @samp{X} packet
39886Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
39887Memory is specified by its address @var{addr} and number of addressable memory
39888units @var{length} (@pxref{addressable memory unit});
0876f84a 39889@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 39890
ee2d5c50
AC
39891Reply:
39892@table @samp
39893@item OK
39894for success
b8ff78ce 39895@item E @var{NN}
ee2d5c50
AC
39896for an error
39897@end table
39898
a1dcb23a
DJ
39899@item z @var{type},@var{addr},@var{kind}
39900@itemx Z @var{type},@var{addr},@var{kind}
2f870471 39901@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
39902@cindex @samp{z} packet
39903@cindex @samp{Z} packets
39904Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 39905watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 39906
2f870471
AC
39907Each breakpoint and watchpoint packet @var{type} is documented
39908separately.
39909
512217c7
AC
39910@emph{Implementation notes: A remote target shall return an empty string
39911for an unrecognized breakpoint or watchpoint packet @var{type}. A
39912remote target shall support either both or neither of a given
b8ff78ce 39913@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
39914avoid potential problems with duplicate packets, the operations should
39915be implemented in an idempotent way.}
39916
a1dcb23a 39917@item z0,@var{addr},@var{kind}
d3ce09f5 39918@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39919@cindex @samp{z0} packet
39920@cindex @samp{Z0} packet
4435e1cc 39921Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 39922@var{addr} of type @var{kind}.
2f870471 39923
4435e1cc 39924A software breakpoint is implemented by replacing the instruction at
2f870471 39925@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
39926@var{kind} is target-specific and typically indicates the size of the
39927breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39928@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39929architectures have additional meanings for @var{kind}
39930(@pxref{Architecture-Specific Protocol Details}); if no
39931architecture-specific value is being used, it should be @samp{0}.
39932@var{kind} is hex-encoded. @var{cond_list} is an optional list of
39933conditional expressions in bytecode form that should be evaluated on
39934the target's side. These are the conditions that should be taken into
39935consideration when deciding if the breakpoint trigger should be
39936reported back to @value{GDBN}.
83364271 39937
f7e6eed5 39938See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 39939for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 39940
83364271
LM
39941The @var{cond_list} parameter is comprised of a series of expressions,
39942concatenated without separators. Each expression has the following form:
39943
39944@table @samp
39945
39946@item X @var{len},@var{expr}
39947@var{len} is the length of the bytecode expression and @var{expr} is the
39948actual conditional expression in bytecode form.
39949
39950@end table
39951
d3ce09f5
SS
39952The optional @var{cmd_list} parameter introduces commands that may be
39953run on the target, rather than being reported back to @value{GDBN}.
39954The parameter starts with a numeric flag @var{persist}; if the flag is
39955nonzero, then the breakpoint may remain active and the commands
39956continue to be run even when @value{GDBN} disconnects from the target.
39957Following this flag is a series of expressions concatenated with no
39958separators. Each expression has the following form:
39959
39960@table @samp
39961
39962@item X @var{len},@var{expr}
39963@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 39964actual commands expression in bytecode form.
d3ce09f5
SS
39965
39966@end table
39967
2f870471 39968@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 39969code that contains software breakpoints (e.g., when implementing
2f870471
AC
39970overlays). The behavior of this packet, in the presence of such a
39971target, is not defined.}
c906108c 39972
ee2d5c50
AC
39973Reply:
39974@table @samp
2f870471
AC
39975@item OK
39976success
d57350ea 39977@item @w{}
2f870471 39978not supported
b8ff78ce 39979@item E @var{NN}
ee2d5c50 39980for an error
2f870471
AC
39981@end table
39982
a1dcb23a 39983@item z1,@var{addr},@var{kind}
4435e1cc 39984@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39985@cindex @samp{z1} packet
39986@cindex @samp{Z1} packet
39987Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 39988address @var{addr}.
2f870471
AC
39989
39990A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
39991dependent on being able to modify the target's memory. The
39992@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39993same meaning as in @samp{Z0} packets.
2f870471
AC
39994
39995@emph{Implementation note: A hardware breakpoint is not affected by code
39996movement.}
39997
39998Reply:
39999@table @samp
ee2d5c50 40000@item OK
2f870471 40001success
d57350ea 40002@item @w{}
2f870471 40003not supported
b8ff78ce 40004@item E @var{NN}
2f870471
AC
40005for an error
40006@end table
40007
a1dcb23a
DJ
40008@item z2,@var{addr},@var{kind}
40009@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
40010@cindex @samp{z2} packet
40011@cindex @samp{Z2} packet
a1dcb23a 40012Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 40013The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40014
40015Reply:
40016@table @samp
40017@item OK
40018success
d57350ea 40019@item @w{}
2f870471 40020not supported
b8ff78ce 40021@item E @var{NN}
2f870471
AC
40022for an error
40023@end table
40024
a1dcb23a
DJ
40025@item z3,@var{addr},@var{kind}
40026@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
40027@cindex @samp{z3} packet
40028@cindex @samp{Z3} packet
a1dcb23a 40029Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 40030The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40031
40032Reply:
40033@table @samp
40034@item OK
40035success
d57350ea 40036@item @w{}
2f870471 40037not supported
b8ff78ce 40038@item E @var{NN}
2f870471
AC
40039for an error
40040@end table
40041
a1dcb23a
DJ
40042@item z4,@var{addr},@var{kind}
40043@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
40044@cindex @samp{z4} packet
40045@cindex @samp{Z4} packet
a1dcb23a 40046Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 40047The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40048
40049Reply:
40050@table @samp
40051@item OK
40052success
d57350ea 40053@item @w{}
2f870471 40054not supported
b8ff78ce 40055@item E @var{NN}
2f870471 40056for an error
ee2d5c50
AC
40057@end table
40058
40059@end table
c906108c 40060
ee2d5c50
AC
40061@node Stop Reply Packets
40062@section Stop Reply Packets
40063@cindex stop reply packets
c906108c 40064
8b23ecc4
SL
40065The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40066@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40067receive any of the below as a reply. Except for @samp{?}
40068and @samp{vStopped}, that reply is only returned
b8ff78ce 40069when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
40070number} is defined by the header @file{include/gdb/signals.h} in the
40071@value{GDBN} source code.
c906108c 40072
4435e1cc
TT
40073In non-stop mode, the server will simply reply @samp{OK} to commands
40074such as @samp{vCont}; any stop will be the subject of a future
40075notification. @xref{Remote Non-Stop}.
40076
b8ff78ce
JB
40077As in the description of request packets, we include spaces in the
40078reply templates for clarity; these are not part of the reply packet's
40079syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40080components.
c906108c 40081
b8ff78ce 40082@table @samp
ee2d5c50 40083
b8ff78ce 40084@item S @var{AA}
599b237a 40085The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40086number). This is equivalent to a @samp{T} response with no
40087@var{n}:@var{r} pairs.
c906108c 40088
b8ff78ce
JB
40089@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40090@cindex @samp{T} packet reply
599b237a 40091The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40092number). This is equivalent to an @samp{S} response, except that the
40093@samp{@var{n}:@var{r}} pairs can carry values of important registers
40094and other information directly in the stop reply packet, reducing
40095round-trip latency. Single-step and breakpoint traps are reported
40096this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
40097
40098@itemize @bullet
b8ff78ce 40099@item
599b237a 40100If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 40101corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
40102series of bytes in target byte order, with each byte given by a
40103two-digit hex number.
cfa9d6d9 40104
b8ff78ce 40105@item
b90a069a
SL
40106If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40107the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 40108
dc146f7c
VP
40109@item
40110If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40111the core on which the stop event was detected.
40112
b8ff78ce 40113@item
cfa9d6d9
DJ
40114If @var{n} is a recognized @dfn{stop reason}, it describes a more
40115specific event that stopped the target. The currently defined stop
697aa1b7 40116reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
40117signal. At most one stop reason should be present.
40118
b8ff78ce
JB
40119@item
40120Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40121and go on to the next; this allows us to extend the protocol in the
40122future.
cfa9d6d9
DJ
40123@end itemize
40124
40125The currently defined stop reasons are:
40126
40127@table @samp
40128@item watch
40129@itemx rwatch
40130@itemx awatch
40131The packet indicates a watchpoint hit, and @var{r} is the data address, in
40132hex.
40133
82075af2
JS
40134@item syscall_entry
40135@itemx syscall_return
40136The packet indicates a syscall entry or return, and @var{r} is the
40137syscall number, in hex.
40138
cfa9d6d9
DJ
40139@cindex shared library events, remote reply
40140@item library
40141The packet indicates that the loaded libraries have changed.
40142@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 40143list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
40144
40145@cindex replay log events, remote reply
40146@item replaylog
40147The packet indicates that the target cannot continue replaying
40148logged execution events, because it has reached the end (or the
40149beginning when executing backward) of the log. The value of @var{r}
40150will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40151for more information.
f7e6eed5
PA
40152
40153@item swbreak
40154@anchor{swbreak stop reason}
4435e1cc 40155The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
40156irrespective of whether it was @value{GDBN} that planted the
40157breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40158part must be left empty.
40159
40160On some architectures, such as x86, at the architecture level, when a
40161breakpoint instruction executes the program counter points at the
40162breakpoint address plus an offset. On such targets, the stub is
40163responsible for adjusting the PC to point back at the breakpoint
40164address.
40165
40166This packet should not be sent by default; older @value{GDBN} versions
40167did not support it. @value{GDBN} requests it, by supplying an
40168appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40169remote stub must also supply the appropriate @samp{qSupported} feature
40170indicating support.
40171
40172This packet is required for correct non-stop mode operation.
40173
40174@item hwbreak
40175The packet indicates the target stopped for a hardware breakpoint.
40176The @var{r} part must be left empty.
40177
40178The same remarks about @samp{qSupported} and non-stop mode above
40179apply.
0d71eef5
DB
40180
40181@cindex fork events, remote reply
40182@item fork
40183The packet indicates that @code{fork} was called, and @var{r}
40184is the thread ID of the new child process. Refer to
40185@ref{thread-id syntax} for the format of the @var{thread-id}
40186field. This packet is only applicable to targets that support
40187fork events.
40188
40189This packet should not be sent by default; older @value{GDBN} versions
40190did not support it. @value{GDBN} requests it, by supplying an
40191appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40192remote stub must also supply the appropriate @samp{qSupported} feature
40193indicating support.
40194
40195@cindex vfork events, remote reply
40196@item vfork
40197The packet indicates that @code{vfork} was called, and @var{r}
40198is the thread ID of the new child process. Refer to
40199@ref{thread-id syntax} for the format of the @var{thread-id}
40200field. This packet is only applicable to targets that support
40201vfork events.
40202
40203This packet should not be sent by default; older @value{GDBN} versions
40204did not support it. @value{GDBN} requests it, by supplying an
40205appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40206remote stub must also supply the appropriate @samp{qSupported} feature
40207indicating support.
40208
40209@cindex vforkdone events, remote reply
40210@item vforkdone
e68fa6f0
PA
40211The packet indicates that a child process created by a vfork
40212has either called @code{exec} or terminated, so that the
40213address spaces of the parent and child process are no longer
40214shared. The @var{r} part is ignored. This packet is only
40215applicable to targets that support vforkdone events.
0d71eef5
DB
40216
40217This packet should not be sent by default; older @value{GDBN} versions
40218did not support it. @value{GDBN} requests it, by supplying an
40219appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40220remote stub must also supply the appropriate @samp{qSupported} feature
40221indicating support.
40222
b459a59b
DB
40223@cindex exec events, remote reply
40224@item exec
40225The packet indicates that @code{execve} was called, and @var{r}
40226is the absolute pathname of the file that was executed, in hex.
40227This packet is only applicable to targets that support exec events.
40228
40229This packet should not be sent by default; older @value{GDBN} versions
40230did not support it. @value{GDBN} requests it, by supplying an
40231appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40232remote stub must also supply the appropriate @samp{qSupported} feature
40233indicating support.
40234
65706a29
PA
40235@cindex thread create event, remote reply
40236@anchor{thread create event}
40237@item create
40238The packet indicates that the thread was just created. The new thread
40239is stopped until @value{GDBN} sets it running with a resumption packet
40240(@pxref{vCont packet}). This packet should not be sent by default;
40241@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
40242also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40243@var{r} part is ignored.
65706a29 40244
cfa9d6d9 40245@end table
ee2d5c50 40246
b8ff78ce 40247@item W @var{AA}
b90a069a 40248@itemx W @var{AA} ; process:@var{pid}
8e04817f 40249The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
40250applicable to certain targets.
40251
4435e1cc
TT
40252The second form of the response, including the process ID of the
40253exited process, can be used only when @value{GDBN} has reported
40254support for multiprocess protocol extensions; see @ref{multiprocess
40255extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40256hex strings.
b90a069a 40257
b8ff78ce 40258@item X @var{AA}
b90a069a 40259@itemx X @var{AA} ; process:@var{pid}
8e04817f 40260The process terminated with signal @var{AA}.
c906108c 40261
b90a069a
SL
40262The second form of the response, including the process ID of the
40263terminated process, can be used only when @value{GDBN} has reported
40264support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
40265extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40266hex strings.
b90a069a 40267
65706a29
PA
40268@anchor{thread exit event}
40269@cindex thread exit event, remote reply
40270@item w @var{AA} ; @var{tid}
40271
40272The thread exited, and @var{AA} is the exit status. This response
40273should not be sent by default; @value{GDBN} requests it with the
40274@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 40275@var{AA} is formatted as a big-endian hex string.
65706a29 40276
f2faf941
PA
40277@item N
40278There are no resumed threads left in the target. In other words, even
40279though the process is alive, the last resumed thread has exited. For
40280example, say the target process has two threads: thread 1 and thread
402812. The client leaves thread 1 stopped, and resumes thread 2, which
40282subsequently exits. At this point, even though the process is still
40283alive, and thus no @samp{W} stop reply is sent, no thread is actually
40284executing either. The @samp{N} stop reply thus informs the client
40285that it can stop waiting for stop replies. This packet should not be
40286sent by default; older @value{GDBN} versions did not support it.
40287@value{GDBN} requests it, by supplying an appropriate
40288@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40289also supply the appropriate @samp{qSupported} feature indicating
40290support.
40291
b8ff78ce
JB
40292@item O @var{XX}@dots{}
40293@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40294written as the program's console output. This can happen at any time
40295while the program is running and the debugger should continue to wait
8b23ecc4 40296for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40297
b8ff78ce 40298@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40299@var{call-id} is the identifier which says which host system call should
40300be called. This is just the name of the function. Translation into the
40301correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40302@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40303system calls.
40304
b8ff78ce
JB
40305@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40306this very system call.
0ce1b118 40307
b8ff78ce
JB
40308The target replies with this packet when it expects @value{GDBN} to
40309call a host system call on behalf of the target. @value{GDBN} replies
40310with an appropriate @samp{F} packet and keeps up waiting for the next
40311reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40312or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40313Protocol Extension}, for more details.
0ce1b118 40314
ee2d5c50
AC
40315@end table
40316
40317@node General Query Packets
40318@section General Query Packets
9c16f35a 40319@cindex remote query requests
c906108c 40320
5f3bebba
JB
40321Packets starting with @samp{q} are @dfn{general query packets};
40322packets starting with @samp{Q} are @dfn{general set packets}. General
40323query and set packets are a semi-unified form for retrieving and
40324sending information to and from the stub.
40325
40326The initial letter of a query or set packet is followed by a name
40327indicating what sort of thing the packet applies to. For example,
40328@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40329definitions with the stub. These packet names follow some
40330conventions:
40331
40332@itemize @bullet
40333@item
40334The name must not contain commas, colons or semicolons.
40335@item
40336Most @value{GDBN} query and set packets have a leading upper case
40337letter.
40338@item
40339The names of custom vendor packets should use a company prefix, in
40340lower case, followed by a period. For example, packets designed at
40341the Acme Corporation might begin with @samp{qacme.foo} (for querying
40342foos) or @samp{Qacme.bar} (for setting bars).
40343@end itemize
40344
aa56d27a
JB
40345The name of a query or set packet should be separated from any
40346parameters by a @samp{:}; the parameters themselves should be
40347separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40348full packet name, and check for a separator or the end of the packet,
40349in case two packet names share a common prefix. New packets should not begin
40350with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40351packets predate these conventions, and have arguments without any terminator
40352for the packet name; we suspect they are in widespread use in places that
40353are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40354existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40355packet.}.
c906108c 40356
b8ff78ce
JB
40357Like the descriptions of the other packets, each description here
40358has a template showing the packet's overall syntax, followed by an
40359explanation of the packet's meaning. We include spaces in some of the
40360templates for clarity; these are not part of the packet's syntax. No
40361@value{GDBN} packet uses spaces to separate its components.
40362
5f3bebba
JB
40363Here are the currently defined query and set packets:
40364
b8ff78ce 40365@table @samp
c906108c 40366
d1feda86 40367@item QAgent:1
af4238e5 40368@itemx QAgent:0
d1feda86
YQ
40369Turn on or off the agent as a helper to perform some debugging operations
40370delegated from @value{GDBN} (@pxref{Control Agent}).
40371
d914c394
SS
40372@item QAllow:@var{op}:@var{val}@dots{}
40373@cindex @samp{QAllow} packet
40374Specify which operations @value{GDBN} expects to request of the
40375target, as a semicolon-separated list of operation name and value
40376pairs. Possible values for @var{op} include @samp{WriteReg},
40377@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40378@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40379indicating that @value{GDBN} will not request the operation, or 1,
40380indicating that it may. (The target can then use this to set up its
40381own internals optimally, for instance if the debugger never expects to
40382insert breakpoints, it may not need to install its own trap handler.)
40383
b8ff78ce 40384@item qC
9c16f35a 40385@cindex current thread, remote request
b8ff78ce 40386@cindex @samp{qC} packet
b90a069a 40387Return the current thread ID.
ee2d5c50
AC
40388
40389Reply:
40390@table @samp
b90a069a
SL
40391@item QC @var{thread-id}
40392Where @var{thread-id} is a thread ID as documented in
40393@ref{thread-id syntax}.
b8ff78ce 40394@item @r{(anything else)}
b90a069a 40395Any other reply implies the old thread ID.
ee2d5c50
AC
40396@end table
40397
b8ff78ce 40398@item qCRC:@var{addr},@var{length}
ff2587ec 40399@cindex CRC of memory block, remote request
b8ff78ce 40400@cindex @samp{qCRC} packet
936d2992 40401@anchor{qCRC packet}
99e008fe
EZ
40402Compute the CRC checksum of a block of memory using CRC-32 defined in
40403IEEE 802.3. The CRC is computed byte at a time, taking the most
40404significant bit of each byte first. The initial pattern code
40405@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40406
40407@emph{Note:} This is the same CRC used in validating separate debug
40408files (@pxref{Separate Debug Files, , Debugging Information in Separate
40409Files}). However the algorithm is slightly different. When validating
40410separate debug files, the CRC is computed taking the @emph{least}
40411significant bit of each byte first, and the final result is inverted to
40412detect trailing zeros.
40413
ff2587ec
WZ
40414Reply:
40415@table @samp
b8ff78ce 40416@item E @var{NN}
ff2587ec 40417An error (such as memory fault)
b8ff78ce
JB
40418@item C @var{crc32}
40419The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40420@end table
40421
03583c20
UW
40422@item QDisableRandomization:@var{value}
40423@cindex disable address space randomization, remote request
40424@cindex @samp{QDisableRandomization} packet
40425Some target operating systems will randomize the virtual address space
40426of the inferior process as a security feature, but provide a feature
40427to disable such randomization, e.g.@: to allow for a more deterministic
40428debugging experience. On such systems, this packet with a @var{value}
40429of 1 directs the target to disable address space randomization for
40430processes subsequently started via @samp{vRun} packets, while a packet
40431with a @var{value} of 0 tells the target to enable address space
40432randomization.
40433
40434This packet is only available in extended mode (@pxref{extended mode}).
40435
40436Reply:
40437@table @samp
40438@item OK
40439The request succeeded.
40440
40441@item E @var{nn}
697aa1b7 40442An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40443
d57350ea 40444@item @w{}
03583c20
UW
40445An empty reply indicates that @samp{QDisableRandomization} is not supported
40446by the stub.
40447@end table
40448
40449This packet is not probed by default; the remote stub must request it,
40450by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40451This should only be done on targets that actually support disabling
40452address space randomization.
40453
aefd8b33
SDJ
40454@item QStartupWithShell:@var{value}
40455@cindex startup with shell, remote request
40456@cindex @samp{QStartupWithShell} packet
40457On UNIX-like targets, it is possible to start the inferior using a
40458shell program. This is the default behavior on both @value{GDBN} and
40459@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40460used to inform @command{gdbserver} whether it should start the
40461inferior using a shell or not.
40462
40463If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40464to start the inferior. If @var{value} is @samp{1},
40465@command{gdbserver} will use a shell to start the inferior. All other
40466values are considered an error.
40467
40468This packet is only available in extended mode (@pxref{extended
40469mode}).
40470
40471Reply:
40472@table @samp
40473@item OK
40474The request succeeded.
40475
40476@item E @var{nn}
40477An error occurred. The error number @var{nn} is given as hex digits.
40478@end table
40479
40480This packet is not probed by default; the remote stub must request it,
40481by supplying an appropriate @samp{qSupported} response
40482(@pxref{qSupported}). This should only be done on targets that
40483actually support starting the inferior using a shell.
40484
40485Use of this packet is controlled by the @code{set startup-with-shell}
40486command; @pxref{set startup-with-shell}.
40487
0a2dde4a
SDJ
40488@item QEnvironmentHexEncoded:@var{hex-value}
40489@anchor{QEnvironmentHexEncoded}
40490@cindex set environment variable, remote request
40491@cindex @samp{QEnvironmentHexEncoded} packet
40492On UNIX-like targets, it is possible to set environment variables that
40493will be passed to the inferior during the startup process. This
40494packet is used to inform @command{gdbserver} of an environment
40495variable that has been defined by the user on @value{GDBN} (@pxref{set
40496environment}).
40497
40498The packet is composed by @var{hex-value}, an hex encoded
40499representation of the @var{name=value} format representing an
40500environment variable. The name of the environment variable is
40501represented by @var{name}, and the value to be assigned to the
40502environment variable is represented by @var{value}. If the variable
40503has no value (i.e., the value is @code{null}), then @var{value} will
40504not be present.
40505
40506This packet is only available in extended mode (@pxref{extended
40507mode}).
40508
40509Reply:
40510@table @samp
40511@item OK
40512The request succeeded.
40513@end table
40514
40515This packet is not probed by default; the remote stub must request it,
40516by supplying an appropriate @samp{qSupported} response
40517(@pxref{qSupported}). This should only be done on targets that
40518actually support passing environment variables to the starting
40519inferior.
40520
40521This packet is related to the @code{set environment} command;
40522@pxref{set environment}.
40523
40524@item QEnvironmentUnset:@var{hex-value}
40525@anchor{QEnvironmentUnset}
40526@cindex unset environment variable, remote request
40527@cindex @samp{QEnvironmentUnset} packet
40528On UNIX-like targets, it is possible to unset environment variables
40529before starting the inferior in the remote target. This packet is
40530used to inform @command{gdbserver} of an environment variable that has
40531been unset by the user on @value{GDBN} (@pxref{unset environment}).
40532
40533The packet is composed by @var{hex-value}, an hex encoded
40534representation of the name of the environment variable to be unset.
40535
40536This packet is only available in extended mode (@pxref{extended
40537mode}).
40538
40539Reply:
40540@table @samp
40541@item OK
40542The request succeeded.
40543@end table
40544
40545This packet is not probed by default; the remote stub must request it,
40546by supplying an appropriate @samp{qSupported} response
40547(@pxref{qSupported}). This should only be done on targets that
40548actually support passing environment variables to the starting
40549inferior.
40550
40551This packet is related to the @code{unset environment} command;
40552@pxref{unset environment}.
40553
40554@item QEnvironmentReset
40555@anchor{QEnvironmentReset}
40556@cindex reset environment, remote request
40557@cindex @samp{QEnvironmentReset} packet
40558On UNIX-like targets, this packet is used to reset the state of
40559environment variables in the remote target before starting the
40560inferior. In this context, reset means unsetting all environment
40561variables that were previously set by the user (i.e., were not
40562initially present in the environment). It is sent to
40563@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40564(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40565(@pxref{QEnvironmentUnset}) packets.
40566
40567This packet is only available in extended mode (@pxref{extended
40568mode}).
40569
40570Reply:
40571@table @samp
40572@item OK
40573The request succeeded.
40574@end table
40575
40576This packet is not probed by default; the remote stub must request it,
40577by supplying an appropriate @samp{qSupported} response
40578(@pxref{qSupported}). This should only be done on targets that
40579actually support passing environment variables to the starting
40580inferior.
40581
bc3b087d
SDJ
40582@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40583@anchor{QSetWorkingDir packet}
40584@cindex set working directory, remote request
40585@cindex @samp{QSetWorkingDir} packet
40586This packet is used to inform the remote server of the intended
40587current working directory for programs that are going to be executed.
40588
40589The packet is composed by @var{directory}, an hex encoded
40590representation of the directory that the remote inferior will use as
40591its current working directory. If @var{directory} is an empty string,
40592the remote server should reset the inferior's current working
40593directory to its original, empty value.
40594
40595This packet is only available in extended mode (@pxref{extended
40596mode}).
40597
40598Reply:
40599@table @samp
40600@item OK
40601The request succeeded.
40602@end table
40603
b8ff78ce
JB
40604@item qfThreadInfo
40605@itemx qsThreadInfo
9c16f35a 40606@cindex list active threads, remote request
b8ff78ce
JB
40607@cindex @samp{qfThreadInfo} packet
40608@cindex @samp{qsThreadInfo} packet
b90a069a 40609Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40610may be too many active threads to fit into one reply packet, this query
40611works iteratively: it may require more than one query/reply sequence to
40612obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40613be the @samp{qfThreadInfo} query; subsequent queries in the
40614sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40615
b8ff78ce 40616NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40617
40618Reply:
40619@table @samp
b90a069a
SL
40620@item m @var{thread-id}
40621A single thread ID
40622@item m @var{thread-id},@var{thread-id}@dots{}
40623a comma-separated list of thread IDs
b8ff78ce
JB
40624@item l
40625(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40626@end table
40627
40628In response to each query, the target will reply with a list of one or
b90a069a 40629more thread IDs, separated by commas.
e1aac25b 40630@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40631ids (using the @samp{qs} form of the query), until the target responds
501994c0 40632with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40633Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40634fields.
c906108c 40635
8dfcab11
DT
40636@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40637initial connection with the remote target, and the very first thread ID
40638mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40639message. Therefore, the stub should ensure that the first thread ID in
40640the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40641
b8ff78ce 40642@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40643@cindex get thread-local storage address, remote request
b8ff78ce 40644@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40645Fetch the address associated with thread local storage specified
40646by @var{thread-id}, @var{offset}, and @var{lm}.
40647
b90a069a
SL
40648@var{thread-id} is the thread ID associated with the
40649thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40650
40651@var{offset} is the (big endian, hex encoded) offset associated with the
40652thread local variable. (This offset is obtained from the debug
40653information associated with the variable.)
40654
db2e3e2e 40655@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40656load module associated with the thread local storage. For example,
ff2587ec
WZ
40657a @sc{gnu}/Linux system will pass the link map address of the shared
40658object associated with the thread local storage under consideration.
40659Other operating environments may choose to represent the load module
40660differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40661
40662Reply:
b8ff78ce
JB
40663@table @samp
40664@item @var{XX}@dots{}
ff2587ec
WZ
40665Hex encoded (big endian) bytes representing the address of the thread
40666local storage requested.
40667
b8ff78ce 40668@item E @var{nn}
697aa1b7 40669An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40670
d57350ea 40671@item @w{}
b8ff78ce 40672An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40673@end table
40674
711e434b
PM
40675@item qGetTIBAddr:@var{thread-id}
40676@cindex get thread information block address
40677@cindex @samp{qGetTIBAddr} packet
40678Fetch address of the Windows OS specific Thread Information Block.
40679
40680@var{thread-id} is the thread ID associated with the thread.
40681
40682Reply:
40683@table @samp
40684@item @var{XX}@dots{}
40685Hex encoded (big endian) bytes representing the linear address of the
40686thread information block.
40687
40688@item E @var{nn}
40689An error occured. This means that either the thread was not found, or the
40690address could not be retrieved.
40691
d57350ea 40692@item @w{}
711e434b
PM
40693An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40694@end table
40695
b8ff78ce 40696@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40697Obtain thread information from RTOS. Where: @var{startflag} (one hex
40698digit) is one to indicate the first query and zero to indicate a
40699subsequent query; @var{threadcount} (two hex digits) is the maximum
40700number of threads the response packet can contain; and @var{nextthread}
40701(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40702returned in the response as @var{argthread}.
ee2d5c50 40703
b8ff78ce 40704Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40705
40706Reply:
40707@table @samp
b8ff78ce 40708@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40709Where: @var{count} (two hex digits) is the number of threads being
40710returned; @var{done} (one hex digit) is zero to indicate more threads
40711and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40712digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40713is a sequence of thread IDs, @var{threadid} (eight hex
40714digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40715@end table
c906108c 40716
b8ff78ce 40717@item qOffsets
9c16f35a 40718@cindex section offsets, remote request
b8ff78ce 40719@cindex @samp{qOffsets} packet
31d99776
DJ
40720Get section offsets that the target used when relocating the downloaded
40721image.
c906108c 40722
ee2d5c50
AC
40723Reply:
40724@table @samp
31d99776
DJ
40725@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40726Relocate the @code{Text} section by @var{xxx} from its original address.
40727Relocate the @code{Data} section by @var{yyy} from its original address.
40728If the object file format provides segment information (e.g.@: @sc{elf}
40729@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40730segments by the supplied offsets.
40731
40732@emph{Note: while a @code{Bss} offset may be included in the response,
40733@value{GDBN} ignores this and instead applies the @code{Data} offset
40734to the @code{Bss} section.}
40735
40736@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40737Relocate the first segment of the object file, which conventionally
40738contains program code, to a starting address of @var{xxx}. If
40739@samp{DataSeg} is specified, relocate the second segment, which
40740conventionally contains modifiable data, to a starting address of
40741@var{yyy}. @value{GDBN} will report an error if the object file
40742does not contain segment information, or does not contain at least
40743as many segments as mentioned in the reply. Extra segments are
40744kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
40745@end table
40746
b90a069a 40747@item qP @var{mode} @var{thread-id}
9c16f35a 40748@cindex thread information, remote request
b8ff78ce 40749@cindex @samp{qP} packet
b90a069a
SL
40750Returns information on @var{thread-id}. Where: @var{mode} is a hex
40751encoded 32 bit mode; @var{thread-id} is a thread ID
40752(@pxref{thread-id syntax}).
ee2d5c50 40753
aa56d27a
JB
40754Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40755(see below).
40756
b8ff78ce 40757Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 40758
8b23ecc4 40759@item QNonStop:1
687e43a4 40760@itemx QNonStop:0
8b23ecc4
SL
40761@cindex non-stop mode, remote request
40762@cindex @samp{QNonStop} packet
40763@anchor{QNonStop}
40764Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40765@xref{Remote Non-Stop}, for more information.
40766
40767Reply:
40768@table @samp
40769@item OK
40770The request succeeded.
40771
40772@item E @var{nn}
697aa1b7 40773An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 40774
d57350ea 40775@item @w{}
8b23ecc4
SL
40776An empty reply indicates that @samp{QNonStop} is not supported by
40777the stub.
40778@end table
40779
40780This packet is not probed by default; the remote stub must request it,
40781by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40782Use of this packet is controlled by the @code{set non-stop} command;
40783@pxref{Non-Stop Mode}.
40784
82075af2
JS
40785@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40786@itemx QCatchSyscalls:0
40787@cindex catch syscalls from inferior, remote request
40788@cindex @samp{QCatchSyscalls} packet
40789@anchor{QCatchSyscalls}
40790Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40791catching syscalls from the inferior process.
40792
40793For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40794in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40795is listed, every system call should be reported.
40796
40797Note that if a syscall not in the list is reported, @value{GDBN} will
40798still filter the event according to its own list from all corresponding
40799@code{catch syscall} commands. However, it is more efficient to only
40800report the requested syscalls.
40801
40802Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40803@samp{QCatchSyscalls:1} list is completely replaced by the new list.
40804
40805If the inferior process execs, the state of @samp{QCatchSyscalls} is
40806kept for the new process too. On targets where exec may affect syscall
40807numbers, for example with exec between 32 and 64-bit processes, the
40808client should send a new packet with the new syscall list.
40809
40810Reply:
40811@table @samp
40812@item OK
40813The request succeeded.
40814
40815@item E @var{nn}
40816An error occurred. @var{nn} are hex digits.
40817
40818@item @w{}
40819An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40820the stub.
40821@end table
40822
40823Use of this packet is controlled by the @code{set remote catch-syscalls}
40824command (@pxref{Remote Configuration, set remote catch-syscalls}).
40825This packet is not probed by default; the remote stub must request it,
40826by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40827
89be2091
DJ
40828@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40829@cindex pass signals to inferior, remote request
40830@cindex @samp{QPassSignals} packet
23181151 40831@anchor{QPassSignals}
89be2091
DJ
40832Each listed @var{signal} should be passed directly to the inferior process.
40833Signals are numbered identically to continue packets and stop replies
40834(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40835strictly greater than the previous item. These signals do not need to stop
40836the inferior, or be reported to @value{GDBN}. All other signals should be
40837reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40838combine; any earlier @samp{QPassSignals} list is completely replaced by the
40839new list. This packet improves performance when using @samp{handle
40840@var{signal} nostop noprint pass}.
40841
40842Reply:
40843@table @samp
40844@item OK
40845The request succeeded.
40846
40847@item E @var{nn}
697aa1b7 40848An error occurred. The error number @var{nn} is given as hex digits.
89be2091 40849
d57350ea 40850@item @w{}
89be2091
DJ
40851An empty reply indicates that @samp{QPassSignals} is not supported by
40852the stub.
40853@end table
40854
40855Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 40856command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
40857This packet is not probed by default; the remote stub must request it,
40858by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40859
9b224c5e
PA
40860@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40861@cindex signals the inferior may see, remote request
40862@cindex @samp{QProgramSignals} packet
40863@anchor{QProgramSignals}
40864Each listed @var{signal} may be delivered to the inferior process.
40865Others should be silently discarded.
40866
40867In some cases, the remote stub may need to decide whether to deliver a
40868signal to the program or not without @value{GDBN} involvement. One
40869example of that is while detaching --- the program's threads may have
40870stopped for signals that haven't yet had a chance of being reported to
40871@value{GDBN}, and so the remote stub can use the signal list specified
40872by this packet to know whether to deliver or ignore those pending
40873signals.
40874
40875This does not influence whether to deliver a signal as requested by a
40876resumption packet (@pxref{vCont packet}).
40877
40878Signals are numbered identically to continue packets and stop replies
40879(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40880strictly greater than the previous item. Multiple
40881@samp{QProgramSignals} packets do not combine; any earlier
40882@samp{QProgramSignals} list is completely replaced by the new list.
40883
40884Reply:
40885@table @samp
40886@item OK
40887The request succeeded.
40888
40889@item E @var{nn}
697aa1b7 40890An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 40891
d57350ea 40892@item @w{}
9b224c5e
PA
40893An empty reply indicates that @samp{QProgramSignals} is not supported
40894by the stub.
40895@end table
40896
40897Use of this packet is controlled by the @code{set remote program-signals}
40898command (@pxref{Remote Configuration, set remote program-signals}).
40899This packet is not probed by default; the remote stub must request it,
40900by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40901
65706a29
PA
40902@anchor{QThreadEvents}
40903@item QThreadEvents:1
40904@itemx QThreadEvents:0
40905@cindex thread create/exit events, remote request
40906@cindex @samp{QThreadEvents} packet
40907
40908Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40909reporting of thread create and exit events. @xref{thread create
40910event}, for the reply specifications. For example, this is used in
40911non-stop mode when @value{GDBN} stops a set of threads and
40912synchronously waits for the their corresponding stop replies. Without
40913exit events, if one of the threads exits, @value{GDBN} would hang
40914forever not knowing that it should no longer expect a stop for that
40915same thread. @value{GDBN} does not enable this feature unless the
40916stub reports that it supports it by including @samp{QThreadEvents+} in
40917its @samp{qSupported} reply.
40918
40919Reply:
40920@table @samp
40921@item OK
40922The request succeeded.
40923
40924@item E @var{nn}
40925An error occurred. The error number @var{nn} is given as hex digits.
40926
40927@item @w{}
40928An empty reply indicates that @samp{QThreadEvents} is not supported by
40929the stub.
40930@end table
40931
40932Use of this packet is controlled by the @code{set remote thread-events}
40933command (@pxref{Remote Configuration, set remote thread-events}).
40934
b8ff78ce 40935@item qRcmd,@var{command}
ff2587ec 40936@cindex execute remote command, remote request
b8ff78ce 40937@cindex @samp{qRcmd} packet
ff2587ec 40938@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
40939execution. Invalid commands should be reported using the output
40940string. Before the final result packet, the target may also respond
40941with a number of intermediate @samp{O@var{output}} console output
40942packets. @emph{Implementors should note that providing access to a
40943stubs's interpreter may have security implications}.
fa93a9d8 40944
ff2587ec
WZ
40945Reply:
40946@table @samp
40947@item OK
40948A command response with no output.
40949@item @var{OUTPUT}
40950A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 40951@item E @var{NN}
ff2587ec 40952Indicate a badly formed request.
d57350ea 40953@item @w{}
b8ff78ce 40954An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 40955@end table
fa93a9d8 40956
aa56d27a
JB
40957(Note that the @code{qRcmd} packet's name is separated from the
40958command by a @samp{,}, not a @samp{:}, contrary to the naming
40959conventions above. Please don't use this packet as a model for new
40960packets.)
40961
08388c79
DE
40962@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40963@cindex searching memory, in remote debugging
5c4808ca 40964@ifnotinfo
08388c79 40965@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
40966@end ifnotinfo
40967@cindex @samp{qSearch memory} packet
08388c79
DE
40968@anchor{qSearch memory}
40969Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
40970Both @var{address} and @var{length} are encoded in hex;
40971@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
40972
40973Reply:
40974@table @samp
40975@item 0
40976The pattern was not found.
40977@item 1,address
40978The pattern was found at @var{address}.
40979@item E @var{NN}
40980A badly formed request or an error was encountered while searching memory.
d57350ea 40981@item @w{}
08388c79
DE
40982An empty reply indicates that @samp{qSearch:memory} is not recognized.
40983@end table
40984
a6f3e723
SL
40985@item QStartNoAckMode
40986@cindex @samp{QStartNoAckMode} packet
40987@anchor{QStartNoAckMode}
40988Request that the remote stub disable the normal @samp{+}/@samp{-}
40989protocol acknowledgments (@pxref{Packet Acknowledgment}).
40990
40991Reply:
40992@table @samp
40993@item OK
40994The stub has switched to no-acknowledgment mode.
6b92c0d3 40995@value{GDBN} acknowledges this response,
a6f3e723
SL
40996but neither the stub nor @value{GDBN} shall send or expect further
40997@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 40998@item @w{}
a6f3e723
SL
40999An empty reply indicates that the stub does not support no-acknowledgment mode.
41000@end table
41001
be2a5f71
DJ
41002@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41003@cindex supported packets, remote query
41004@cindex features of the remote protocol
41005@cindex @samp{qSupported} packet
0876f84a 41006@anchor{qSupported}
be2a5f71
DJ
41007Tell the remote stub about features supported by @value{GDBN}, and
41008query the stub for features it supports. This packet allows
41009@value{GDBN} and the remote stub to take advantage of each others'
41010features. @samp{qSupported} also consolidates multiple feature probes
41011at startup, to improve @value{GDBN} performance---a single larger
41012packet performs better than multiple smaller probe packets on
41013high-latency links. Some features may enable behavior which must not
41014be on by default, e.g.@: because it would confuse older clients or
41015stubs. Other features may describe packets which could be
41016automatically probed for, but are not. These features must be
41017reported before @value{GDBN} will use them. This ``default
41018unsupported'' behavior is not appropriate for all packets, but it
41019helps to keep the initial connection time under control with new
41020versions of @value{GDBN} which support increasing numbers of packets.
41021
41022Reply:
41023@table @samp
41024@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41025The stub supports or does not support each returned @var{stubfeature},
41026depending on the form of each @var{stubfeature} (see below for the
41027possible forms).
d57350ea 41028@item @w{}
be2a5f71
DJ
41029An empty reply indicates that @samp{qSupported} is not recognized,
41030or that no features needed to be reported to @value{GDBN}.
41031@end table
41032
41033The allowed forms for each feature (either a @var{gdbfeature} in the
41034@samp{qSupported} packet, or a @var{stubfeature} in the response)
41035are:
41036
41037@table @samp
41038@item @var{name}=@var{value}
41039The remote protocol feature @var{name} is supported, and associated
41040with the specified @var{value}. The format of @var{value} depends
41041on the feature, but it must not include a semicolon.
41042@item @var{name}+
41043The remote protocol feature @var{name} is supported, and does not
41044need an associated value.
41045@item @var{name}-
41046The remote protocol feature @var{name} is not supported.
41047@item @var{name}?
41048The remote protocol feature @var{name} may be supported, and
41049@value{GDBN} should auto-detect support in some other way when it is
41050needed. This form will not be used for @var{gdbfeature} notifications,
41051but may be used for @var{stubfeature} responses.
41052@end table
41053
41054Whenever the stub receives a @samp{qSupported} request, the
41055supplied set of @value{GDBN} features should override any previous
41056request. This allows @value{GDBN} to put the stub in a known
41057state, even if the stub had previously been communicating with
41058a different version of @value{GDBN}.
41059
b90a069a
SL
41060The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41061are defined:
41062
41063@table @samp
41064@item multiprocess
41065This feature indicates whether @value{GDBN} supports multiprocess
41066extensions to the remote protocol. @value{GDBN} does not use such
41067extensions unless the stub also reports that it supports them by
41068including @samp{multiprocess+} in its @samp{qSupported} reply.
41069@xref{multiprocess extensions}, for details.
c8d5aac9
L
41070
41071@item xmlRegisters
41072This feature indicates that @value{GDBN} supports the XML target
41073description. If the stub sees @samp{xmlRegisters=} with target
41074specific strings separated by a comma, it will report register
41075description.
dde08ee1
PA
41076
41077@item qRelocInsn
41078This feature indicates whether @value{GDBN} supports the
41079@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41080instruction reply packet}).
f7e6eed5
PA
41081
41082@item swbreak
41083This feature indicates whether @value{GDBN} supports the swbreak stop
41084reason in stop replies. @xref{swbreak stop reason}, for details.
41085
41086@item hwbreak
41087This feature indicates whether @value{GDBN} supports the hwbreak stop
41088reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
41089
41090@item fork-events
41091This feature indicates whether @value{GDBN} supports fork event
41092extensions to the remote protocol. @value{GDBN} does not use such
41093extensions unless the stub also reports that it supports them by
41094including @samp{fork-events+} in its @samp{qSupported} reply.
41095
41096@item vfork-events
41097This feature indicates whether @value{GDBN} supports vfork event
41098extensions to the remote protocol. @value{GDBN} does not use such
41099extensions unless the stub also reports that it supports them by
41100including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
41101
41102@item exec-events
41103This feature indicates whether @value{GDBN} supports exec event
41104extensions to the remote protocol. @value{GDBN} does not use such
41105extensions unless the stub also reports that it supports them by
41106including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
41107
41108@item vContSupported
41109This feature indicates whether @value{GDBN} wants to know the
41110supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
41111@end table
41112
41113Stubs should ignore any unknown values for
be2a5f71
DJ
41114@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41115packet supports receiving packets of unlimited length (earlier
b90a069a 41116versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
41117for @var{gdbfeature} may be defined in the future to let the stub take
41118advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
41119improvements in the remote protocol---the @samp{multiprocess} feature is
41120an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
41121of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41122describes all the features it supports, and then the stub replies with
41123all the features it supports.
41124
41125Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41126responses, as long as each response uses one of the standard forms.
41127
41128Some features are flags. A stub which supports a flag feature
41129should respond with a @samp{+} form response. Other features
41130require values, and the stub should respond with an @samp{=}
41131form response.
41132
41133Each feature has a default value, which @value{GDBN} will use if
41134@samp{qSupported} is not available or if the feature is not mentioned
41135in the @samp{qSupported} response. The default values are fixed; a
41136stub is free to omit any feature responses that match the defaults.
41137
41138Not all features can be probed, but for those which can, the probing
41139mechanism is useful: in some cases, a stub's internal
41140architecture may not allow the protocol layer to know some information
41141about the underlying target in advance. This is especially common in
41142stubs which may be configured for multiple targets.
41143
41144These are the currently defined stub features and their properties:
41145
cfa9d6d9 41146@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
41147@c NOTE: The first row should be @headitem, but we do not yet require
41148@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 41149@item Feature Name
be2a5f71
DJ
41150@tab Value Required
41151@tab Default
41152@tab Probe Allowed
41153
41154@item @samp{PacketSize}
41155@tab Yes
41156@tab @samp{-}
41157@tab No
41158
0876f84a
DJ
41159@item @samp{qXfer:auxv:read}
41160@tab No
41161@tab @samp{-}
41162@tab Yes
41163
2ae8c8e7
MM
41164@item @samp{qXfer:btrace:read}
41165@tab No
41166@tab @samp{-}
41167@tab Yes
41168
f4abbc16
MM
41169@item @samp{qXfer:btrace-conf:read}
41170@tab No
41171@tab @samp{-}
41172@tab Yes
41173
c78fa86a
GB
41174@item @samp{qXfer:exec-file:read}
41175@tab No
41176@tab @samp{-}
41177@tab Yes
41178
23181151
DJ
41179@item @samp{qXfer:features:read}
41180@tab No
41181@tab @samp{-}
41182@tab Yes
41183
cfa9d6d9
DJ
41184@item @samp{qXfer:libraries:read}
41185@tab No
41186@tab @samp{-}
41187@tab Yes
41188
85dc5a12
GB
41189@item @samp{qXfer:libraries-svr4:read}
41190@tab No
41191@tab @samp{-}
41192@tab Yes
41193
41194@item @samp{augmented-libraries-svr4-read}
41195@tab No
41196@tab @samp{-}
41197@tab No
41198
68437a39
DJ
41199@item @samp{qXfer:memory-map:read}
41200@tab No
41201@tab @samp{-}
41202@tab Yes
41203
0fb4aa4b
PA
41204@item @samp{qXfer:sdata:read}
41205@tab No
41206@tab @samp{-}
41207@tab Yes
41208
4aa995e1
PA
41209@item @samp{qXfer:siginfo:read}
41210@tab No
41211@tab @samp{-}
41212@tab Yes
41213
41214@item @samp{qXfer:siginfo:write}
41215@tab No
41216@tab @samp{-}
41217@tab Yes
41218
dc146f7c
VP
41219@item @samp{qXfer:threads:read}
41220@tab No
41221@tab @samp{-}
41222@tab Yes
41223
b3b9301e
PA
41224@item @samp{qXfer:traceframe-info:read}
41225@tab No
41226@tab @samp{-}
41227@tab Yes
41228
169081d0
TG
41229@item @samp{qXfer:uib:read}
41230@tab No
41231@tab @samp{-}
41232@tab Yes
41233
78d85199
YQ
41234@item @samp{qXfer:fdpic:read}
41235@tab No
41236@tab @samp{-}
41237@tab Yes
dc146f7c 41238
2ae8c8e7
MM
41239@item @samp{Qbtrace:off}
41240@tab Yes
41241@tab @samp{-}
41242@tab Yes
41243
41244@item @samp{Qbtrace:bts}
41245@tab Yes
41246@tab @samp{-}
41247@tab Yes
41248
b20a6524
MM
41249@item @samp{Qbtrace:pt}
41250@tab Yes
41251@tab @samp{-}
41252@tab Yes
41253
d33501a5
MM
41254@item @samp{Qbtrace-conf:bts:size}
41255@tab Yes
41256@tab @samp{-}
41257@tab Yes
41258
b20a6524
MM
41259@item @samp{Qbtrace-conf:pt:size}
41260@tab Yes
41261@tab @samp{-}
41262@tab Yes
41263
8b23ecc4
SL
41264@item @samp{QNonStop}
41265@tab No
41266@tab @samp{-}
41267@tab Yes
41268
82075af2
JS
41269@item @samp{QCatchSyscalls}
41270@tab No
41271@tab @samp{-}
41272@tab Yes
41273
89be2091
DJ
41274@item @samp{QPassSignals}
41275@tab No
41276@tab @samp{-}
41277@tab Yes
41278
a6f3e723
SL
41279@item @samp{QStartNoAckMode}
41280@tab No
41281@tab @samp{-}
41282@tab Yes
41283
b90a069a
SL
41284@item @samp{multiprocess}
41285@tab No
41286@tab @samp{-}
41287@tab No
41288
83364271
LM
41289@item @samp{ConditionalBreakpoints}
41290@tab No
41291@tab @samp{-}
41292@tab No
41293
782b2b07
SS
41294@item @samp{ConditionalTracepoints}
41295@tab No
41296@tab @samp{-}
41297@tab No
41298
0d772ac9
MS
41299@item @samp{ReverseContinue}
41300@tab No
2f8132f3 41301@tab @samp{-}
0d772ac9
MS
41302@tab No
41303
41304@item @samp{ReverseStep}
41305@tab No
2f8132f3 41306@tab @samp{-}
0d772ac9
MS
41307@tab No
41308
409873ef
SS
41309@item @samp{TracepointSource}
41310@tab No
41311@tab @samp{-}
41312@tab No
41313
d1feda86
YQ
41314@item @samp{QAgent}
41315@tab No
41316@tab @samp{-}
41317@tab No
41318
d914c394
SS
41319@item @samp{QAllow}
41320@tab No
41321@tab @samp{-}
41322@tab No
41323
03583c20
UW
41324@item @samp{QDisableRandomization}
41325@tab No
41326@tab @samp{-}
41327@tab No
41328
d248b706
KY
41329@item @samp{EnableDisableTracepoints}
41330@tab No
41331@tab @samp{-}
41332@tab No
41333
f6f899bf
HAQ
41334@item @samp{QTBuffer:size}
41335@tab No
41336@tab @samp{-}
41337@tab No
41338
3065dfb6
SS
41339@item @samp{tracenz}
41340@tab No
41341@tab @samp{-}
41342@tab No
41343
d3ce09f5
SS
41344@item @samp{BreakpointCommands}
41345@tab No
41346@tab @samp{-}
41347@tab No
41348
f7e6eed5
PA
41349@item @samp{swbreak}
41350@tab No
41351@tab @samp{-}
41352@tab No
41353
41354@item @samp{hwbreak}
41355@tab No
41356@tab @samp{-}
41357@tab No
41358
0d71eef5
DB
41359@item @samp{fork-events}
41360@tab No
41361@tab @samp{-}
41362@tab No
41363
41364@item @samp{vfork-events}
41365@tab No
41366@tab @samp{-}
41367@tab No
41368
b459a59b
DB
41369@item @samp{exec-events}
41370@tab No
41371@tab @samp{-}
41372@tab No
41373
65706a29
PA
41374@item @samp{QThreadEvents}
41375@tab No
41376@tab @samp{-}
41377@tab No
41378
f2faf941
PA
41379@item @samp{no-resumed}
41380@tab No
41381@tab @samp{-}
41382@tab No
41383
be2a5f71
DJ
41384@end multitable
41385
41386These are the currently defined stub features, in more detail:
41387
41388@table @samp
41389@cindex packet size, remote protocol
41390@item PacketSize=@var{bytes}
41391The remote stub can accept packets up to at least @var{bytes} in
41392length. @value{GDBN} will send packets up to this size for bulk
41393transfers, and will never send larger packets. This is a limit on the
41394data characters in the packet, including the frame and checksum.
41395There is no trailing NUL byte in a remote protocol packet; if the stub
41396stores packets in a NUL-terminated format, it should allow an extra
41397byte in its buffer for the NUL. If this stub feature is not supported,
41398@value{GDBN} guesses based on the size of the @samp{g} packet response.
41399
0876f84a
DJ
41400@item qXfer:auxv:read
41401The remote stub understands the @samp{qXfer:auxv:read} packet
41402(@pxref{qXfer auxiliary vector read}).
41403
2ae8c8e7
MM
41404@item qXfer:btrace:read
41405The remote stub understands the @samp{qXfer:btrace:read}
41406packet (@pxref{qXfer btrace read}).
41407
f4abbc16
MM
41408@item qXfer:btrace-conf:read
41409The remote stub understands the @samp{qXfer:btrace-conf:read}
41410packet (@pxref{qXfer btrace-conf read}).
41411
c78fa86a
GB
41412@item qXfer:exec-file:read
41413The remote stub understands the @samp{qXfer:exec-file:read} packet
41414(@pxref{qXfer executable filename read}).
41415
23181151
DJ
41416@item qXfer:features:read
41417The remote stub understands the @samp{qXfer:features:read} packet
41418(@pxref{qXfer target description read}).
41419
cfa9d6d9
DJ
41420@item qXfer:libraries:read
41421The remote stub understands the @samp{qXfer:libraries:read} packet
41422(@pxref{qXfer library list read}).
41423
2268b414
JK
41424@item qXfer:libraries-svr4:read
41425The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41426(@pxref{qXfer svr4 library list read}).
41427
85dc5a12
GB
41428@item augmented-libraries-svr4-read
41429The remote stub understands the augmented form of the
41430@samp{qXfer:libraries-svr4:read} packet
41431(@pxref{qXfer svr4 library list read}).
41432
23181151
DJ
41433@item qXfer:memory-map:read
41434The remote stub understands the @samp{qXfer:memory-map:read} packet
41435(@pxref{qXfer memory map read}).
41436
0fb4aa4b
PA
41437@item qXfer:sdata:read
41438The remote stub understands the @samp{qXfer:sdata:read} packet
41439(@pxref{qXfer sdata read}).
41440
4aa995e1
PA
41441@item qXfer:siginfo:read
41442The remote stub understands the @samp{qXfer:siginfo:read} packet
41443(@pxref{qXfer siginfo read}).
41444
41445@item qXfer:siginfo:write
41446The remote stub understands the @samp{qXfer:siginfo:write} packet
41447(@pxref{qXfer siginfo write}).
41448
dc146f7c
VP
41449@item qXfer:threads:read
41450The remote stub understands the @samp{qXfer:threads:read} packet
41451(@pxref{qXfer threads read}).
41452
b3b9301e
PA
41453@item qXfer:traceframe-info:read
41454The remote stub understands the @samp{qXfer:traceframe-info:read}
41455packet (@pxref{qXfer traceframe info read}).
41456
169081d0
TG
41457@item qXfer:uib:read
41458The remote stub understands the @samp{qXfer:uib:read}
41459packet (@pxref{qXfer unwind info block}).
41460
78d85199
YQ
41461@item qXfer:fdpic:read
41462The remote stub understands the @samp{qXfer:fdpic:read}
41463packet (@pxref{qXfer fdpic loadmap read}).
41464
8b23ecc4
SL
41465@item QNonStop
41466The remote stub understands the @samp{QNonStop} packet
41467(@pxref{QNonStop}).
41468
82075af2
JS
41469@item QCatchSyscalls
41470The remote stub understands the @samp{QCatchSyscalls} packet
41471(@pxref{QCatchSyscalls}).
41472
23181151
DJ
41473@item QPassSignals
41474The remote stub understands the @samp{QPassSignals} packet
41475(@pxref{QPassSignals}).
41476
a6f3e723
SL
41477@item QStartNoAckMode
41478The remote stub understands the @samp{QStartNoAckMode} packet and
41479prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41480
b90a069a
SL
41481@item multiprocess
41482@anchor{multiprocess extensions}
41483@cindex multiprocess extensions, in remote protocol
41484The remote stub understands the multiprocess extensions to the remote
41485protocol syntax. The multiprocess extensions affect the syntax of
41486thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41487add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41488replies. Note that reporting this feature indicates support for the
41489syntactic extensions only, not that the stub necessarily supports
41490debugging of more than one process at a time. The stub must not use
41491multiprocess extensions in packet replies unless @value{GDBN} has also
41492indicated it supports them in its @samp{qSupported} request.
41493
07e059b5
VP
41494@item qXfer:osdata:read
41495The remote stub understands the @samp{qXfer:osdata:read} packet
41496((@pxref{qXfer osdata read}).
41497
83364271
LM
41498@item ConditionalBreakpoints
41499The target accepts and implements evaluation of conditional expressions
41500defined for breakpoints. The target will only report breakpoint triggers
41501when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41502
782b2b07
SS
41503@item ConditionalTracepoints
41504The remote stub accepts and implements conditional expressions defined
41505for tracepoints (@pxref{Tracepoint Conditions}).
41506
0d772ac9
MS
41507@item ReverseContinue
41508The remote stub accepts and implements the reverse continue packet
41509(@pxref{bc}).
41510
41511@item ReverseStep
41512The remote stub accepts and implements the reverse step packet
41513(@pxref{bs}).
41514
409873ef
SS
41515@item TracepointSource
41516The remote stub understands the @samp{QTDPsrc} packet that supplies
41517the source form of tracepoint definitions.
41518
d1feda86
YQ
41519@item QAgent
41520The remote stub understands the @samp{QAgent} packet.
41521
d914c394
SS
41522@item QAllow
41523The remote stub understands the @samp{QAllow} packet.
41524
03583c20
UW
41525@item QDisableRandomization
41526The remote stub understands the @samp{QDisableRandomization} packet.
41527
0fb4aa4b
PA
41528@item StaticTracepoint
41529@cindex static tracepoints, in remote protocol
41530The remote stub supports static tracepoints.
41531
1e4d1764
YQ
41532@item InstallInTrace
41533@anchor{install tracepoint in tracing}
41534The remote stub supports installing tracepoint in tracing.
41535
d248b706
KY
41536@item EnableDisableTracepoints
41537The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41538@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41539to be enabled and disabled while a trace experiment is running.
41540
f6f899bf 41541@item QTBuffer:size
28abe188 41542The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41543packet that allows to change the size of the trace buffer.
41544
3065dfb6
SS
41545@item tracenz
41546@cindex string tracing, in remote protocol
41547The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41548See @ref{Bytecode Descriptions} for details about the bytecode.
41549
d3ce09f5
SS
41550@item BreakpointCommands
41551@cindex breakpoint commands, in remote protocol
41552The remote stub supports running a breakpoint's command list itself,
41553rather than reporting the hit to @value{GDBN}.
41554
2ae8c8e7
MM
41555@item Qbtrace:off
41556The remote stub understands the @samp{Qbtrace:off} packet.
41557
41558@item Qbtrace:bts
41559The remote stub understands the @samp{Qbtrace:bts} packet.
41560
b20a6524
MM
41561@item Qbtrace:pt
41562The remote stub understands the @samp{Qbtrace:pt} packet.
41563
d33501a5
MM
41564@item Qbtrace-conf:bts:size
41565The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41566
b20a6524
MM
41567@item Qbtrace-conf:pt:size
41568The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41569
f7e6eed5
PA
41570@item swbreak
41571The remote stub reports the @samp{swbreak} stop reason for memory
41572breakpoints.
41573
41574@item hwbreak
41575The remote stub reports the @samp{hwbreak} stop reason for hardware
41576breakpoints.
41577
0d71eef5
DB
41578@item fork-events
41579The remote stub reports the @samp{fork} stop reason for fork events.
41580
41581@item vfork-events
41582The remote stub reports the @samp{vfork} stop reason for vfork events
41583and vforkdone events.
41584
b459a59b
DB
41585@item exec-events
41586The remote stub reports the @samp{exec} stop reason for exec events.
41587
750ce8d1
YQ
41588@item vContSupported
41589The remote stub reports the supported actions in the reply to
41590@samp{vCont?} packet.
41591
65706a29
PA
41592@item QThreadEvents
41593The remote stub understands the @samp{QThreadEvents} packet.
41594
f2faf941
PA
41595@item no-resumed
41596The remote stub reports the @samp{N} stop reply.
41597
be2a5f71
DJ
41598@end table
41599
b8ff78ce 41600@item qSymbol::
ff2587ec 41601@cindex symbol lookup, remote request
b8ff78ce 41602@cindex @samp{qSymbol} packet
ff2587ec
WZ
41603Notify the target that @value{GDBN} is prepared to serve symbol lookup
41604requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41605
41606Reply:
ff2587ec 41607@table @samp
b8ff78ce 41608@item OK
ff2587ec 41609The target does not need to look up any (more) symbols.
b8ff78ce 41610@item qSymbol:@var{sym_name}
ff2587ec
WZ
41611The target requests the value of symbol @var{sym_name} (hex encoded).
41612@value{GDBN} may provide the value by using the
b8ff78ce
JB
41613@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41614below.
ff2587ec 41615@end table
83761cbd 41616
b8ff78ce 41617@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41618Set the value of @var{sym_name} to @var{sym_value}.
41619
41620@var{sym_name} (hex encoded) is the name of a symbol whose value the
41621target has previously requested.
41622
41623@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41624@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41625will be empty.
41626
41627Reply:
41628@table @samp
b8ff78ce 41629@item OK
ff2587ec 41630The target does not need to look up any (more) symbols.
b8ff78ce 41631@item qSymbol:@var{sym_name}
ff2587ec
WZ
41632The target requests the value of a new symbol @var{sym_name} (hex
41633encoded). @value{GDBN} will continue to supply the values of symbols
41634(if available), until the target ceases to request them.
fa93a9d8 41635@end table
0abb7bc7 41636
00bf0b85 41637@item qTBuffer
687e43a4
TT
41638@itemx QTBuffer
41639@itemx QTDisconnected
d5551862 41640@itemx QTDP
409873ef 41641@itemx QTDPsrc
d5551862 41642@itemx QTDV
00bf0b85
SS
41643@itemx qTfP
41644@itemx qTfV
9d29849a 41645@itemx QTFrame
405f8e94
SS
41646@itemx qTMinFTPILen
41647
9d29849a
JB
41648@xref{Tracepoint Packets}.
41649
b90a069a 41650@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41651@cindex thread attributes info, remote request
b8ff78ce 41652@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41653Obtain from the target OS a printable string description of thread
41654attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41655for the forms of @var{thread-id}. This
b8ff78ce
JB
41656string may contain anything that the target OS thinks is interesting
41657for @value{GDBN} to tell the user about the thread. The string is
41658displayed in @value{GDBN}'s @code{info threads} display. Some
41659examples of possible thread extra info strings are @samp{Runnable}, or
41660@samp{Blocked on Mutex}.
ff2587ec
WZ
41661
41662Reply:
41663@table @samp
b8ff78ce
JB
41664@item @var{XX}@dots{}
41665Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41666comprising the printable string containing the extra information about
41667the thread's attributes.
ff2587ec 41668@end table
814e32d7 41669
aa56d27a
JB
41670(Note that the @code{qThreadExtraInfo} packet's name is separated from
41671the command by a @samp{,}, not a @samp{:}, contrary to the naming
41672conventions above. Please don't use this packet as a model for new
41673packets.)
41674
f196051f 41675@item QTNotes
687e43a4
TT
41676@itemx qTP
41677@itemx QTSave
41678@itemx qTsP
41679@itemx qTsV
d5551862 41680@itemx QTStart
9d29849a 41681@itemx QTStop
d248b706
KY
41682@itemx QTEnable
41683@itemx QTDisable
9d29849a
JB
41684@itemx QTinit
41685@itemx QTro
41686@itemx qTStatus
d5551862 41687@itemx qTV
0fb4aa4b
PA
41688@itemx qTfSTM
41689@itemx qTsSTM
41690@itemx qTSTMat
9d29849a
JB
41691@xref{Tracepoint Packets}.
41692
0876f84a
DJ
41693@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41694@cindex read special object, remote request
41695@cindex @samp{qXfer} packet
68437a39 41696@anchor{qXfer read}
0876f84a
DJ
41697Read uninterpreted bytes from the target's special data area
41698identified by the keyword @var{object}. Request @var{length} bytes
41699starting at @var{offset} bytes into the data. The content and
0e7f50da 41700encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41701additional details about what data to access.
41702
c185ba27
EZ
41703Reply:
41704@table @samp
41705@item m @var{data}
41706Data @var{data} (@pxref{Binary Data}) has been read from the
41707target. There may be more data at a higher address (although
41708it is permitted to return @samp{m} even for the last valid
41709block of data, as long as at least one byte of data was read).
41710It is possible for @var{data} to have fewer bytes than the @var{length} in the
41711request.
41712
41713@item l @var{data}
41714Data @var{data} (@pxref{Binary Data}) has been read from the target.
41715There is no more data to be read. It is possible for @var{data} to
41716have fewer bytes than the @var{length} in the request.
41717
41718@item l
41719The @var{offset} in the request is at the end of the data.
41720There is no more data to be read.
41721
41722@item E00
41723The request was malformed, or @var{annex} was invalid.
41724
41725@item E @var{nn}
41726The offset was invalid, or there was an error encountered reading the data.
41727The @var{nn} part is a hex-encoded @code{errno} value.
41728
41729@item @w{}
41730An empty reply indicates the @var{object} string was not recognized by
41731the stub, or that the object does not support reading.
41732@end table
41733
41734Here are the specific requests of this form defined so far. All the
0876f84a 41735@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 41736formats, listed above.
0876f84a
DJ
41737
41738@table @samp
41739@item qXfer:auxv:read::@var{offset},@var{length}
41740@anchor{qXfer auxiliary vector read}
41741Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 41742auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
41743
41744This packet is not probed by default; the remote stub must request it,
89be2091 41745by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 41746
2ae8c8e7
MM
41747@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41748@anchor{qXfer btrace read}
41749
41750Return a description of the current branch trace.
41751@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41752packet may have one of the following values:
41753
41754@table @code
41755@item all
41756Returns all available branch trace.
41757
41758@item new
41759Returns all available branch trace if the branch trace changed since
41760the last read request.
969c39fb
MM
41761
41762@item delta
41763Returns the new branch trace since the last read request. Adds a new
41764block to the end of the trace that begins at zero and ends at the source
41765location of the first branch in the trace buffer. This extra block is
41766used to stitch traces together.
41767
41768If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
41769@end table
41770
41771This packet is not probed by default; the remote stub must request it
41772by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41773
f4abbc16
MM
41774@item qXfer:btrace-conf:read::@var{offset},@var{length}
41775@anchor{qXfer btrace-conf read}
41776
41777Return a description of the current branch trace configuration.
41778@xref{Branch Trace Configuration Format}.
41779
41780This packet is not probed by default; the remote stub must request it
41781by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
41782
41783@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41784@anchor{qXfer executable filename read}
41785Return the full absolute name of the file that was executed to create
41786a process running on the remote system. The annex specifies the
41787numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
41788number. If the annex part is empty the remote stub should return the
41789filename corresponding to the currently executing process.
c78fa86a
GB
41790
41791This packet is not probed by default; the remote stub must request it,
41792by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 41793
23181151
DJ
41794@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41795@anchor{qXfer target description read}
41796Access the @dfn{target description}. @xref{Target Descriptions}. The
41797annex specifies which XML document to access. The main description is
41798always loaded from the @samp{target.xml} annex.
41799
41800This packet is not probed by default; the remote stub must request it,
41801by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41802
cfa9d6d9
DJ
41803@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41804@anchor{qXfer library list read}
41805Access the target's list of loaded libraries. @xref{Library List Format}.
41806The annex part of the generic @samp{qXfer} packet must be empty
41807(@pxref{qXfer read}).
41808
41809Targets which maintain a list of libraries in the program's memory do
41810not need to implement this packet; it is designed for platforms where
41811the operating system manages the list of loaded libraries.
41812
41813This packet is not probed by default; the remote stub must request it,
41814by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41815
2268b414
JK
41816@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41817@anchor{qXfer svr4 library list read}
41818Access the target's list of loaded libraries when the target is an SVR4
41819platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
41820of the generic @samp{qXfer} packet must be empty unless the remote
41821stub indicated it supports the augmented form of this packet
41822by supplying an appropriate @samp{qSupported} response
41823(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
41824
41825This packet is optional for better performance on SVR4 targets.
41826@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41827
41828This packet is not probed by default; the remote stub must request it,
41829by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41830
85dc5a12
GB
41831If the remote stub indicates it supports the augmented form of this
41832packet then the annex part of the generic @samp{qXfer} packet may
41833contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41834arguments. The currently supported arguments are:
41835
41836@table @code
41837@item start=@var{address}
41838A hexadecimal number specifying the address of the @samp{struct
41839link_map} to start reading the library list from. If unset or zero
41840then the first @samp{struct link_map} in the library list will be
41841chosen as the starting point.
41842
41843@item prev=@var{address}
41844A hexadecimal number specifying the address of the @samp{struct
41845link_map} immediately preceding the @samp{struct link_map}
41846specified by the @samp{start} argument. If unset or zero then
41847the remote stub will expect that no @samp{struct link_map}
41848exists prior to the starting point.
41849
41850@end table
41851
41852Arguments that are not understood by the remote stub will be silently
41853ignored.
41854
68437a39
DJ
41855@item qXfer:memory-map:read::@var{offset},@var{length}
41856@anchor{qXfer memory map read}
79a6e687 41857Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
41858annex part of the generic @samp{qXfer} packet must be empty
41859(@pxref{qXfer read}).
41860
0e7f50da
UW
41861This packet is not probed by default; the remote stub must request it,
41862by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41863
0fb4aa4b
PA
41864@item qXfer:sdata:read::@var{offset},@var{length}
41865@anchor{qXfer sdata read}
41866
41867Read contents of the extra collected static tracepoint marker
41868information. The annex part of the generic @samp{qXfer} packet must
41869be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41870Action Lists}.
41871
41872This packet is not probed by default; the remote stub must request it,
41873by supplying an appropriate @samp{qSupported} response
41874(@pxref{qSupported}).
41875
4aa995e1
PA
41876@item qXfer:siginfo:read::@var{offset},@var{length}
41877@anchor{qXfer siginfo read}
41878Read contents of the extra signal information on the target
41879system. The annex part of the generic @samp{qXfer} packet must be
41880empty (@pxref{qXfer read}).
41881
41882This packet is not probed by default; the remote stub must request it,
41883by supplying an appropriate @samp{qSupported} response
41884(@pxref{qSupported}).
41885
dc146f7c
VP
41886@item qXfer:threads:read::@var{offset},@var{length}
41887@anchor{qXfer threads read}
41888Access the list of threads on target. @xref{Thread List Format}. The
41889annex part of the generic @samp{qXfer} packet must be empty
41890(@pxref{qXfer read}).
41891
41892This packet is not probed by default; the remote stub must request it,
41893by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41894
b3b9301e
PA
41895@item qXfer:traceframe-info:read::@var{offset},@var{length}
41896@anchor{qXfer traceframe info read}
41897
41898Return a description of the current traceframe's contents.
41899@xref{Traceframe Info Format}. The annex part of the generic
41900@samp{qXfer} packet must be empty (@pxref{qXfer read}).
41901
41902This packet is not probed by default; the remote stub must request it,
41903by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41904
169081d0
TG
41905@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41906@anchor{qXfer unwind info block}
41907
41908Return the unwind information block for @var{pc}. This packet is used
41909on OpenVMS/ia64 to ask the kernel unwind information.
41910
41911This packet is not probed by default.
41912
78d85199
YQ
41913@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41914@anchor{qXfer fdpic loadmap read}
41915Read contents of @code{loadmap}s on the target system. The
41916annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41917executable @code{loadmap} or interpreter @code{loadmap} to read.
41918
41919This packet is not probed by default; the remote stub must request it,
41920by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41921
07e059b5
VP
41922@item qXfer:osdata:read::@var{offset},@var{length}
41923@anchor{qXfer osdata read}
697aa1b7 41924Access the target's @dfn{operating system information}.
07e059b5
VP
41925@xref{Operating System Information}.
41926
68437a39
DJ
41927@end table
41928
c185ba27
EZ
41929@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41930@cindex write data into object, remote request
41931@anchor{qXfer write}
41932Write uninterpreted bytes into the target's special data area
41933identified by the keyword @var{object}, starting at @var{offset} bytes
41934into the data. The binary-encoded data (@pxref{Binary Data}) to be
41935written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41936is specific to @var{object}; it can supply additional details about what data
41937to access.
41938
0876f84a
DJ
41939Reply:
41940@table @samp
c185ba27
EZ
41941@item @var{nn}
41942@var{nn} (hex encoded) is the number of bytes written.
41943This may be fewer bytes than supplied in the request.
0876f84a
DJ
41944
41945@item E00
41946The request was malformed, or @var{annex} was invalid.
41947
41948@item E @var{nn}
c185ba27 41949The offset was invalid, or there was an error encountered writing the data.
697aa1b7 41950The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 41951
d57350ea 41952@item @w{}
c185ba27
EZ
41953An empty reply indicates the @var{object} string was not
41954recognized by the stub, or that the object does not support writing.
0876f84a
DJ
41955@end table
41956
c185ba27 41957Here are the specific requests of this form defined so far. All the
0e7f50da 41958@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 41959formats, listed above.
0e7f50da
UW
41960
41961@table @samp
4aa995e1
PA
41962@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41963@anchor{qXfer siginfo write}
41964Write @var{data} to the extra signal information on the target system.
41965The annex part of the generic @samp{qXfer} packet must be
41966empty (@pxref{qXfer write}).
41967
41968This packet is not probed by default; the remote stub must request it,
41969by supplying an appropriate @samp{qSupported} response
41970(@pxref{qSupported}).
0e7f50da 41971@end table
0876f84a 41972
0876f84a
DJ
41973@item qXfer:@var{object}:@var{operation}:@dots{}
41974Requests of this form may be added in the future. When a stub does
41975not recognize the @var{object} keyword, or its support for
41976@var{object} does not recognize the @var{operation} keyword, the stub
41977must respond with an empty packet.
41978
0b16c5cf
PA
41979@item qAttached:@var{pid}
41980@cindex query attached, remote request
41981@cindex @samp{qAttached} packet
41982Return an indication of whether the remote server attached to an
41983existing process or created a new process. When the multiprocess
41984protocol extensions are supported (@pxref{multiprocess extensions}),
41985@var{pid} is an integer in hexadecimal format identifying the target
41986process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41987the query packet will be simplified as @samp{qAttached}.
41988
41989This query is used, for example, to know whether the remote process
41990should be detached or killed when a @value{GDBN} session is ended with
41991the @code{quit} command.
41992
41993Reply:
41994@table @samp
41995@item 1
41996The remote server attached to an existing process.
41997@item 0
41998The remote server created a new process.
41999@item E @var{NN}
42000A badly formed request or an error was encountered.
42001@end table
42002
2ae8c8e7 42003@item Qbtrace:bts
b20a6524
MM
42004Enable branch tracing for the current thread using Branch Trace Store.
42005
42006Reply:
42007@table @samp
42008@item OK
42009Branch tracing has been enabled.
42010@item E.errtext
42011A badly formed request or an error was encountered.
42012@end table
42013
42014@item Qbtrace:pt
bc504a31 42015Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
42016
42017Reply:
42018@table @samp
42019@item OK
42020Branch tracing has been enabled.
42021@item E.errtext
42022A badly formed request or an error was encountered.
42023@end table
42024
42025@item Qbtrace:off
42026Disable branch tracing for the current thread.
42027
42028Reply:
42029@table @samp
42030@item OK
42031Branch tracing has been disabled.
42032@item E.errtext
42033A badly formed request or an error was encountered.
42034@end table
42035
d33501a5
MM
42036@item Qbtrace-conf:bts:size=@var{value}
42037Set the requested ring buffer size for new threads that use the
42038btrace recording method in bts format.
42039
42040Reply:
42041@table @samp
42042@item OK
42043The ring buffer size has been set.
42044@item E.errtext
42045A badly formed request or an error was encountered.
42046@end table
42047
b20a6524
MM
42048@item Qbtrace-conf:pt:size=@var{value}
42049Set the requested ring buffer size for new threads that use the
42050btrace recording method in pt format.
42051
42052Reply:
42053@table @samp
42054@item OK
42055The ring buffer size has been set.
42056@item E.errtext
42057A badly formed request or an error was encountered.
42058@end table
42059
ee2d5c50
AC
42060@end table
42061
a1dcb23a
DJ
42062@node Architecture-Specific Protocol Details
42063@section Architecture-Specific Protocol Details
42064
42065This section describes how the remote protocol is applied to specific
42066target architectures. Also see @ref{Standard Target Features}, for
42067details of XML target descriptions for each architecture.
42068
02b67415
MR
42069@menu
42070* ARM-Specific Protocol Details::
42071* MIPS-Specific Protocol Details::
42072@end menu
42073
42074@node ARM-Specific Protocol Details
42075@subsection @acronym{ARM}-specific Protocol Details
42076
42077@menu
42078* ARM Breakpoint Kinds::
42079@end menu
a1dcb23a 42080
02b67415
MR
42081@node ARM Breakpoint Kinds
42082@subsubsection @acronym{ARM} Breakpoint Kinds
42083@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
42084
42085These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42086
42087@table @r
42088
42089@item 2
4209016-bit Thumb mode breakpoint.
42091
42092@item 3
4209332-bit Thumb mode (Thumb-2) breakpoint.
42094
42095@item 4
02b67415 4209632-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
42097
42098@end table
42099
02b67415
MR
42100@node MIPS-Specific Protocol Details
42101@subsection @acronym{MIPS}-specific Protocol Details
42102
42103@menu
42104* MIPS Register packet Format::
4cc0665f 42105* MIPS Breakpoint Kinds::
02b67415 42106@end menu
a1dcb23a 42107
02b67415
MR
42108@node MIPS Register packet Format
42109@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 42110@cindex register packet format, @acronym{MIPS}
eb12ee30 42111
b8ff78ce 42112The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
42113In the below, some thirty-two bit registers are transferred as
42114sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
42115to fill the space allocated. Register bytes are transferred in target
42116byte order. The two nibbles within a register byte are transferred
02b67415 42117most-significant -- least-significant.
eb12ee30 42118
ee2d5c50 42119@table @r
eb12ee30 42120
8e04817f 42121@item MIPS32
599b237a 42122All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4212332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42124registers; fsr; fir; fp.
eb12ee30 42125
8e04817f 42126@item MIPS64
599b237a 42127All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
42128thirty-two bit registers such as @code{sr}). The ordering is the same
42129as @code{MIPS32}.
eb12ee30 42130
ee2d5c50
AC
42131@end table
42132
4cc0665f
MR
42133@node MIPS Breakpoint Kinds
42134@subsubsection @acronym{MIPS} Breakpoint Kinds
42135@cindex breakpoint kinds, @acronym{MIPS}
42136
42137These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42138
42139@table @r
42140
42141@item 2
4214216-bit @acronym{MIPS16} mode breakpoint.
42143
42144@item 3
4214516-bit @acronym{microMIPS} mode breakpoint.
42146
42147@item 4
4214832-bit standard @acronym{MIPS} mode breakpoint.
42149
42150@item 5
4215132-bit @acronym{microMIPS} mode breakpoint.
42152
42153@end table
42154
9d29849a
JB
42155@node Tracepoint Packets
42156@section Tracepoint Packets
42157@cindex tracepoint packets
42158@cindex packets, tracepoint
42159
42160Here we describe the packets @value{GDBN} uses to implement
42161tracepoints (@pxref{Tracepoints}).
42162
42163@table @samp
42164
7a697b8d 42165@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 42166@cindex @samp{QTDP} packet
9d29849a
JB
42167Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42168is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
42169the tracepoint is disabled. The @var{step} gives the tracepoint's step
42170count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
42171then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42172the number of bytes that the target should copy elsewhere to make room
42173for the tracepoint. If an @samp{X} is present, it introduces a
42174tracepoint condition, which consists of a hexadecimal length, followed
42175by a comma and hex-encoded bytes, in a manner similar to action
42176encodings as described below. If the trailing @samp{-} is present,
42177further @samp{QTDP} packets will follow to specify this tracepoint's
42178actions.
9d29849a
JB
42179
42180Replies:
42181@table @samp
42182@item OK
42183The packet was understood and carried out.
dde08ee1
PA
42184@item qRelocInsn
42185@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42186@item @w{}
9d29849a
JB
42187The packet was not recognized.
42188@end table
42189
42190@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 42191Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
42192@var{addr} must be the same as in the initial @samp{QTDP} packet for
42193this tracepoint. This packet may only be sent immediately after
42194another @samp{QTDP} packet that ended with a @samp{-}. If the
42195trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42196specifying more actions for this tracepoint.
42197
42198In the series of action packets for a given tracepoint, at most one
42199can have an @samp{S} before its first @var{action}. If such a packet
42200is sent, it and the following packets define ``while-stepping''
42201actions. Any prior packets define ordinary actions --- that is, those
42202taken when the tracepoint is first hit. If no action packet has an
42203@samp{S}, then all the packets in the series specify ordinary
42204tracepoint actions.
42205
42206The @samp{@var{action}@dots{}} portion of the packet is a series of
42207actions, concatenated without separators. Each action has one of the
42208following forms:
42209
42210@table @samp
42211
42212@item R @var{mask}
697aa1b7 42213Collect the registers whose bits are set in @var{mask},
599b237a 42214a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
42215@var{i} should be collected. (The least significant bit is numbered
42216zero.) Note that @var{mask} may be any number of digits long; it may
42217not fit in a 32-bit word.
42218
42219@item M @var{basereg},@var{offset},@var{len}
42220Collect @var{len} bytes of memory starting at the address in register
42221number @var{basereg}, plus @var{offset}. If @var{basereg} is
42222@samp{-1}, then the range has a fixed address: @var{offset} is the
42223address of the lowest byte to collect. The @var{basereg},
599b237a 42224@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
42225values (the @samp{-1} value for @var{basereg} is a special case).
42226
42227@item X @var{len},@var{expr}
42228Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 42229it directs. The agent expression @var{expr} is as described in
9d29849a
JB
42230@ref{Agent Expressions}. Each byte of the expression is encoded as a
42231two-digit hex number in the packet; @var{len} is the number of bytes
42232in the expression (and thus one-half the number of hex digits in the
42233packet).
42234
42235@end table
42236
42237Any number of actions may be packed together in a single @samp{QTDP}
42238packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
42239length (400 bytes, for many stubs). There may be only one @samp{R}
42240action per tracepoint, and it must precede any @samp{M} or @samp{X}
42241actions. Any registers referred to by @samp{M} and @samp{X} actions
42242must be collected by a preceding @samp{R} action. (The
42243``while-stepping'' actions are treated as if they were attached to a
42244separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
42245
42246Replies:
42247@table @samp
42248@item OK
42249The packet was understood and carried out.
dde08ee1
PA
42250@item qRelocInsn
42251@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42252@item @w{}
9d29849a
JB
42253The packet was not recognized.
42254@end table
42255
409873ef
SS
42256@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42257@cindex @samp{QTDPsrc} packet
42258Specify a source string of tracepoint @var{n} at address @var{addr}.
42259This is useful to get accurate reproduction of the tracepoints
697aa1b7 42260originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
42261is the name of the tracepoint part, such as @samp{cond} for the
42262tracepoint's conditional expression (see below for a list of types), while
42263@var{bytes} is the string, encoded in hexadecimal.
42264
42265@var{start} is the offset of the @var{bytes} within the overall source
42266string, while @var{slen} is the total length of the source string.
42267This is intended for handling source strings that are longer than will
42268fit in a single packet.
42269@c Add detailed example when this info is moved into a dedicated
42270@c tracepoint descriptions section.
42271
42272The available string types are @samp{at} for the location,
42273@samp{cond} for the conditional, and @samp{cmd} for an action command.
42274@value{GDBN} sends a separate packet for each command in the action
42275list, in the same order in which the commands are stored in the list.
42276
42277The target does not need to do anything with source strings except
42278report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42279query packets.
42280
42281Although this packet is optional, and @value{GDBN} will only send it
42282if the target replies with @samp{TracepointSource} @xref{General
42283Query Packets}, it makes both disconnected tracing and trace files
42284much easier to use. Otherwise the user must be careful that the
42285tracepoints in effect while looking at trace frames are identical to
42286the ones in effect during the trace run; even a small discrepancy
42287could cause @samp{tdump} not to work, or a particular trace frame not
42288be found.
42289
fa3f8d5a 42290@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
42291@cindex define trace state variable, remote request
42292@cindex @samp{QTDV} packet
42293Create a new trace state variable, number @var{n}, with an initial
42294value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42295and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42296the option of not using this packet for initial values of zero; the
42297target should simply create the trace state variables as they are
fa3f8d5a
DT
42298mentioned in expressions. The value @var{builtin} should be 1 (one)
42299if the trace state variable is builtin and 0 (zero) if it is not builtin.
42300@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42301@samp{qTsV} packet had it set. The contents of @var{name} is the
42302hex-encoded name (without the leading @samp{$}) of the trace state
42303variable.
f61e138d 42304
9d29849a 42305@item QTFrame:@var{n}
c614397c 42306@cindex @samp{QTFrame} packet
9d29849a
JB
42307Select the @var{n}'th tracepoint frame from the buffer, and use the
42308register and memory contents recorded there to answer subsequent
42309request packets from @value{GDBN}.
42310
42311A successful reply from the stub indicates that the stub has found the
42312requested frame. The response is a series of parts, concatenated
42313without separators, describing the frame we selected. Each part has
42314one of the following forms:
42315
42316@table @samp
42317@item F @var{f}
42318The selected frame is number @var{n} in the trace frame buffer;
599b237a 42319@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42320was no frame matching the criteria in the request packet.
42321
42322@item T @var{t}
42323The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42324@var{t} is a hexadecimal number.
9d29849a
JB
42325
42326@end table
42327
42328@item QTFrame:pc:@var{addr}
42329Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42330currently selected frame whose PC is @var{addr};
599b237a 42331@var{addr} is a hexadecimal number.
9d29849a
JB
42332
42333@item QTFrame:tdp:@var{t}
42334Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42335currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42336is a hexadecimal number.
9d29849a
JB
42337
42338@item QTFrame:range:@var{start}:@var{end}
42339Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42340currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42341and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42342numbers.
42343
42344@item QTFrame:outside:@var{start}:@var{end}
42345Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42346frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42347
405f8e94 42348@item qTMinFTPILen
c614397c 42349@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42350This packet requests the minimum length of instruction at which a fast
42351tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42352the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42353it depends on the target system being able to create trampolines in
42354the first 64K of memory, which might or might not be possible for that
42355system. So the reply to this packet will be 4 if it is able to
42356arrange for that.
42357
42358Replies:
42359
42360@table @samp
42361@item 0
42362The minimum instruction length is currently unknown.
42363@item @var{length}
697aa1b7
EZ
42364The minimum instruction length is @var{length}, where @var{length}
42365is a hexadecimal number greater or equal to 1. A reply
42366of 1 means that a fast tracepoint may be placed on any instruction
42367regardless of size.
405f8e94
SS
42368@item E
42369An error has occurred.
d57350ea 42370@item @w{}
405f8e94
SS
42371An empty reply indicates that the request is not supported by the stub.
42372@end table
42373
9d29849a 42374@item QTStart
c614397c 42375@cindex @samp{QTStart} packet
dde08ee1
PA
42376Begin the tracepoint experiment. Begin collecting data from
42377tracepoint hits in the trace frame buffer. This packet supports the
42378@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42379instruction reply packet}).
9d29849a
JB
42380
42381@item QTStop
c614397c 42382@cindex @samp{QTStop} packet
9d29849a
JB
42383End the tracepoint experiment. Stop collecting trace frames.
42384
d248b706
KY
42385@item QTEnable:@var{n}:@var{addr}
42386@anchor{QTEnable}
c614397c 42387@cindex @samp{QTEnable} packet
d248b706
KY
42388Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42389experiment. If the tracepoint was previously disabled, then collection
42390of data from it will resume.
42391
42392@item QTDisable:@var{n}:@var{addr}
42393@anchor{QTDisable}
c614397c 42394@cindex @samp{QTDisable} packet
d248b706
KY
42395Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42396experiment. No more data will be collected from the tracepoint unless
42397@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42398
9d29849a 42399@item QTinit
c614397c 42400@cindex @samp{QTinit} packet
9d29849a
JB
42401Clear the table of tracepoints, and empty the trace frame buffer.
42402
42403@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42404@cindex @samp{QTro} packet
9d29849a
JB
42405Establish the given ranges of memory as ``transparent''. The stub
42406will answer requests for these ranges from memory's current contents,
42407if they were not collected as part of the tracepoint hit.
42408
42409@value{GDBN} uses this to mark read-only regions of memory, like those
42410containing program code. Since these areas never change, they should
42411still have the same contents they did when the tracepoint was hit, so
42412there's no reason for the stub to refuse to provide their contents.
42413
d5551862 42414@item QTDisconnected:@var{value}
c614397c 42415@cindex @samp{QTDisconnected} packet
d5551862
SS
42416Set the choice to what to do with the tracing run when @value{GDBN}
42417disconnects from the target. A @var{value} of 1 directs the target to
42418continue the tracing run, while 0 tells the target to stop tracing if
42419@value{GDBN} is no longer in the picture.
42420
9d29849a 42421@item qTStatus
c614397c 42422@cindex @samp{qTStatus} packet
9d29849a
JB
42423Ask the stub if there is a trace experiment running right now.
42424
4daf5ac0
SS
42425The reply has the form:
42426
42427@table @samp
42428
42429@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42430@var{running} is a single digit @code{1} if the trace is presently
42431running, or @code{0} if not. It is followed by semicolon-separated
42432optional fields that an agent may use to report additional status.
42433
42434@end table
42435
42436If the trace is not running, the agent may report any of several
42437explanations as one of the optional fields:
42438
42439@table @samp
42440
42441@item tnotrun:0
42442No trace has been run yet.
42443
f196051f
SS
42444@item tstop[:@var{text}]:0
42445The trace was stopped by a user-originated stop command. The optional
42446@var{text} field is a user-supplied string supplied as part of the
42447stop command (for instance, an explanation of why the trace was
42448stopped manually). It is hex-encoded.
4daf5ac0
SS
42449
42450@item tfull:0
42451The trace stopped because the trace buffer filled up.
42452
42453@item tdisconnected:0
42454The trace stopped because @value{GDBN} disconnected from the target.
42455
42456@item tpasscount:@var{tpnum}
42457The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42458
6c28cbf2
SS
42459@item terror:@var{text}:@var{tpnum}
42460The trace stopped because tracepoint @var{tpnum} had an error. The
42461string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42462(for instance, a divide by zero in the condition expression); it
42463is hex encoded.
6c28cbf2 42464
4daf5ac0
SS
42465@item tunknown:0
42466The trace stopped for some other reason.
42467
42468@end table
42469
33da3f1c
SS
42470Additional optional fields supply statistical and other information.
42471Although not required, they are extremely useful for users monitoring
42472the progress of a trace run. If a trace has stopped, and these
42473numbers are reported, they must reflect the state of the just-stopped
42474trace.
4daf5ac0 42475
9d29849a 42476@table @samp
4daf5ac0
SS
42477
42478@item tframes:@var{n}
42479The number of trace frames in the buffer.
42480
42481@item tcreated:@var{n}
42482The total number of trace frames created during the run. This may
42483be larger than the trace frame count, if the buffer is circular.
42484
42485@item tsize:@var{n}
42486The total size of the trace buffer, in bytes.
42487
42488@item tfree:@var{n}
42489The number of bytes still unused in the buffer.
42490
33da3f1c
SS
42491@item circular:@var{n}
42492The value of the circular trace buffer flag. @code{1} means that the
42493trace buffer is circular and old trace frames will be discarded if
42494necessary to make room, @code{0} means that the trace buffer is linear
42495and may fill up.
42496
42497@item disconn:@var{n}
42498The value of the disconnected tracing flag. @code{1} means that
42499tracing will continue after @value{GDBN} disconnects, @code{0} means
42500that the trace run will stop.
42501
9d29849a
JB
42502@end table
42503
f196051f
SS
42504@item qTP:@var{tp}:@var{addr}
42505@cindex tracepoint status, remote request
42506@cindex @samp{qTP} packet
42507Ask the stub for the current state of tracepoint number @var{tp} at
42508address @var{addr}.
42509
42510Replies:
42511@table @samp
42512@item V@var{hits}:@var{usage}
42513The tracepoint has been hit @var{hits} times so far during the trace
42514run, and accounts for @var{usage} in the trace buffer. Note that
42515@code{while-stepping} steps are not counted as separate hits, but the
42516steps' space consumption is added into the usage number.
42517
42518@end table
42519
f61e138d
SS
42520@item qTV:@var{var}
42521@cindex trace state variable value, remote request
42522@cindex @samp{qTV} packet
42523Ask the stub for the value of the trace state variable number @var{var}.
42524
42525Replies:
42526@table @samp
42527@item V@var{value}
42528The value of the variable is @var{value}. This will be the current
42529value of the variable if the user is examining a running target, or a
42530saved value if the variable was collected in the trace frame that the
42531user is looking at. Note that multiple requests may result in
42532different reply values, such as when requesting values while the
42533program is running.
42534
42535@item U
42536The value of the variable is unknown. This would occur, for example,
42537if the user is examining a trace frame in which the requested variable
42538was not collected.
9d29849a
JB
42539@end table
42540
d5551862 42541@item qTfP
c614397c 42542@cindex @samp{qTfP} packet
d5551862 42543@itemx qTsP
c614397c 42544@cindex @samp{qTsP} packet
d5551862
SS
42545These packets request data about tracepoints that are being used by
42546the target. @value{GDBN} sends @code{qTfP} to get the first piece
42547of data, and multiple @code{qTsP} to get additional pieces. Replies
42548to these packets generally take the form of the @code{QTDP} packets
42549that define tracepoints. (FIXME add detailed syntax)
42550
00bf0b85 42551@item qTfV
c614397c 42552@cindex @samp{qTfV} packet
00bf0b85 42553@itemx qTsV
c614397c 42554@cindex @samp{qTsV} packet
00bf0b85
SS
42555These packets request data about trace state variables that are on the
42556target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42557and multiple @code{qTsV} to get additional variables. Replies to
42558these packets follow the syntax of the @code{QTDV} packets that define
42559trace state variables.
42560
0fb4aa4b
PA
42561@item qTfSTM
42562@itemx qTsSTM
16bdd41f
YQ
42563@anchor{qTfSTM}
42564@anchor{qTsSTM}
c614397c
YQ
42565@cindex @samp{qTfSTM} packet
42566@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42567These packets request data about static tracepoint markers that exist
42568in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42569first piece of data, and multiple @code{qTsSTM} to get additional
42570pieces. Replies to these packets take the following form:
42571
42572Reply:
42573@table @samp
42574@item m @var{address}:@var{id}:@var{extra}
42575A single marker
42576@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42577a comma-separated list of markers
42578@item l
42579(lower case letter @samp{L}) denotes end of list.
42580@item E @var{nn}
697aa1b7 42581An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42582@item @w{}
0fb4aa4b
PA
42583An empty reply indicates that the request is not supported by the
42584stub.
42585@end table
42586
697aa1b7 42587The @var{address} is encoded in hex;
0fb4aa4b
PA
42588@var{id} and @var{extra} are strings encoded in hex.
42589
42590In response to each query, the target will reply with a list of one or
42591more markers, separated by commas. @value{GDBN} will respond to each
42592reply with a request for more markers (using the @samp{qs} form of the
42593query), until the target responds with @samp{l} (lower-case ell, for
42594@dfn{last}).
42595
42596@item qTSTMat:@var{address}
16bdd41f 42597@anchor{qTSTMat}
c614397c 42598@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42599This packets requests data about static tracepoint markers in the
42600target program at @var{address}. Replies to this packet follow the
42601syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42602tracepoint markers.
42603
00bf0b85 42604@item QTSave:@var{filename}
c614397c 42605@cindex @samp{QTSave} packet
00bf0b85 42606This packet directs the target to save trace data to the file name
697aa1b7 42607@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42608as a hex string; the interpretation of the file name (relative vs
42609absolute, wild cards, etc) is up to the target.
42610
42611@item qTBuffer:@var{offset},@var{len}
c614397c 42612@cindex @samp{qTBuffer} packet
00bf0b85
SS
42613Return up to @var{len} bytes of the current contents of trace buffer,
42614starting at @var{offset}. The trace buffer is treated as if it were
42615a contiguous collection of traceframes, as per the trace file format.
42616The reply consists as many hex-encoded bytes as the target can deliver
42617in a packet; it is not an error to return fewer than were asked for.
42618A reply consisting of just @code{l} indicates that no bytes are
42619available.
42620
4daf5ac0
SS
42621@item QTBuffer:circular:@var{value}
42622This packet directs the target to use a circular trace buffer if
42623@var{value} is 1, or a linear buffer if the value is 0.
42624
f6f899bf 42625@item QTBuffer:size:@var{size}
28abe188
EZ
42626@anchor{QTBuffer-size}
42627@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42628This packet directs the target to make the trace buffer be of size
42629@var{size} if possible. A value of @code{-1} tells the target to
42630use whatever size it prefers.
42631
f196051f 42632@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42633@cindex @samp{QTNotes} packet
f196051f
SS
42634This packet adds optional textual notes to the trace run. Allowable
42635types include @code{user}, @code{notes}, and @code{tstop}, the
42636@var{text} fields are arbitrary strings, hex-encoded.
42637
f61e138d 42638@end table
9d29849a 42639
dde08ee1
PA
42640@subsection Relocate instruction reply packet
42641When installing fast tracepoints in memory, the target may need to
42642relocate the instruction currently at the tracepoint address to a
42643different address in memory. For most instructions, a simple copy is
42644enough, but, for example, call instructions that implicitly push the
42645return address on the stack, and relative branches or other
42646PC-relative instructions require offset adjustment, so that the effect
42647of executing the instruction at a different address is the same as if
42648it had executed in the original location.
42649
42650In response to several of the tracepoint packets, the target may also
42651respond with a number of intermediate @samp{qRelocInsn} request
42652packets before the final result packet, to have @value{GDBN} handle
42653this relocation operation. If a packet supports this mechanism, its
42654documentation will explicitly say so. See for example the above
42655descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42656format of the request is:
42657
42658@table @samp
42659@item qRelocInsn:@var{from};@var{to}
42660
42661This requests @value{GDBN} to copy instruction at address @var{from}
42662to address @var{to}, possibly adjusted so that executing the
42663instruction at @var{to} has the same effect as executing it at
42664@var{from}. @value{GDBN} writes the adjusted instruction to target
42665memory starting at @var{to}.
42666@end table
42667
42668Replies:
42669@table @samp
42670@item qRelocInsn:@var{adjusted_size}
697aa1b7 42671Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42672the length in bytes of resulting relocated instruction sequence.
42673@item E @var{NN}
42674A badly formed request was detected, or an error was encountered while
42675relocating the instruction.
42676@end table
42677
a6b151f1
DJ
42678@node Host I/O Packets
42679@section Host I/O Packets
42680@cindex Host I/O, remote protocol
42681@cindex file transfer, remote protocol
42682
42683The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42684operations on the far side of a remote link. For example, Host I/O is
42685used to upload and download files to a remote target with its own
42686filesystem. Host I/O uses the same constant values and data structure
42687layout as the target-initiated File-I/O protocol. However, the
42688Host I/O packets are structured differently. The target-initiated
42689protocol relies on target memory to store parameters and buffers.
42690Host I/O requests are initiated by @value{GDBN}, and the
42691target's memory is not involved. @xref{File-I/O Remote Protocol
42692Extension}, for more details on the target-initiated protocol.
42693
42694The Host I/O request packets all encode a single operation along with
42695its arguments. They have this format:
42696
42697@table @samp
42698
42699@item vFile:@var{operation}: @var{parameter}@dots{}
42700@var{operation} is the name of the particular request; the target
42701should compare the entire packet name up to the second colon when checking
42702for a supported operation. The format of @var{parameter} depends on
42703the operation. Numbers are always passed in hexadecimal. Negative
42704numbers have an explicit minus sign (i.e.@: two's complement is not
42705used). Strings (e.g.@: filenames) are encoded as a series of
42706hexadecimal bytes. The last argument to a system call may be a
42707buffer of escaped binary data (@pxref{Binary Data}).
42708
42709@end table
42710
42711The valid responses to Host I/O packets are:
42712
42713@table @samp
42714
42715@item F @var{result} [, @var{errno}] [; @var{attachment}]
42716@var{result} is the integer value returned by this operation, usually
42717non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42718@var{errno} will be included in the result specifying a
a6b151f1
DJ
42719value defined by the File-I/O protocol (@pxref{Errno Values}). For
42720operations which return data, @var{attachment} supplies the data as a
42721binary buffer. Binary buffers in response packets are escaped in the
42722normal way (@pxref{Binary Data}). See the individual packet
42723documentation for the interpretation of @var{result} and
42724@var{attachment}.
42725
d57350ea 42726@item @w{}
a6b151f1
DJ
42727An empty response indicates that this operation is not recognized.
42728
42729@end table
42730
42731These are the supported Host I/O operations:
42732
42733@table @samp
697aa1b7
EZ
42734@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42735Open a file at @var{filename} and return a file descriptor for it, or
42736return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
42737@var{flags} is an integer indicating a mask of open flags
42738(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42739of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 42740@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
42741
42742@item vFile:close: @var{fd}
42743Close the open file corresponding to @var{fd} and return 0, or
42744-1 if an error occurs.
42745
42746@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42747Read data from the open file corresponding to @var{fd}. Up to
42748@var{count} bytes will be read from the file, starting at @var{offset}
42749relative to the start of the file. The target may read fewer bytes;
42750common reasons include packet size limits and an end-of-file
42751condition. The number of bytes read is returned. Zero should only be
42752returned for a successful read at the end of the file, or if
42753@var{count} was zero.
42754
42755The data read should be returned as a binary attachment on success.
42756If zero bytes were read, the response should include an empty binary
42757attachment (i.e.@: a trailing semicolon). The return value is the
42758number of target bytes read; the binary attachment may be longer if
42759some characters were escaped.
42760
42761@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42762Write @var{data} (a binary buffer) to the open file corresponding
42763to @var{fd}. Start the write at @var{offset} from the start of the
42764file. Unlike many @code{write} system calls, there is no
42765separate @var{count} argument; the length of @var{data} in the
fb092e09 42766packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
42767which may be shorter than the length of @var{data}, or -1 if an
42768error occurred.
42769
0a93529c
GB
42770@item vFile:fstat: @var{fd}
42771Get information about the open file corresponding to @var{fd}.
42772On success the information is returned as a binary attachment
42773and the return value is the size of this attachment in bytes.
42774If an error occurs the return value is -1. The format of the
42775returned binary attachment is as described in @ref{struct stat}.
42776
697aa1b7
EZ
42777@item vFile:unlink: @var{filename}
42778Delete the file at @var{filename} on the target. Return 0,
42779or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 42780
b9e7b9c3
UW
42781@item vFile:readlink: @var{filename}
42782Read value of symbolic link @var{filename} on the target. Return
42783the number of bytes read, or -1 if an error occurs.
42784
42785The data read should be returned as a binary attachment on success.
42786If zero bytes were read, the response should include an empty binary
42787attachment (i.e.@: a trailing semicolon). The return value is the
42788number of target bytes read; the binary attachment may be longer if
42789some characters were escaped.
42790
15a201c8
GB
42791@item vFile:setfs: @var{pid}
42792Select the filesystem on which @code{vFile} operations with
42793@var{filename} arguments will operate. This is required for
42794@value{GDBN} to be able to access files on remote targets where
42795the remote stub does not share a common filesystem with the
42796inferior(s).
42797
42798If @var{pid} is nonzero, select the filesystem as seen by process
42799@var{pid}. If @var{pid} is zero, select the filesystem as seen by
42800the remote stub. Return 0 on success, or -1 if an error occurs.
42801If @code{vFile:setfs:} indicates success, the selected filesystem
42802remains selected until the next successful @code{vFile:setfs:}
42803operation.
42804
a6b151f1
DJ
42805@end table
42806
9a6253be
KB
42807@node Interrupts
42808@section Interrupts
42809@cindex interrupts (remote protocol)
de979965 42810@anchor{interrupting remote targets}
9a6253be 42811
de979965
PA
42812In all-stop mode, when a program on the remote target is running,
42813@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42814@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42815is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
42816
42817The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
42818mechanism and may, in fact, be undefined. @value{GDBN} does not
42819currently define a @code{BREAK} mechanism for any of the network
42820interfaces except for TCP, in which case @value{GDBN} sends the
42821@code{telnet} BREAK sequence.
9a6253be
KB
42822
42823@samp{Ctrl-C}, on the other hand, is defined and implemented for all
42824transport mechanisms. It is represented by sending the single byte
42825@code{0x03} without any of the usual packet overhead described in
42826the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42827transmitted as part of a packet, it is considered to be packet data
42828and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 42829(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
42830@code{0x03} as part of its packet.
42831
9a7071a8
JB
42832@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42833When Linux kernel receives this sequence from serial port,
42834it stops execution and connects to gdb.
42835
de979965
PA
42836In non-stop mode, because packet resumptions are asynchronous
42837(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42838command to the remote stub, even when the target is running. For that
42839reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42840packet}) with the usual packet framing instead of the single byte
42841@code{0x03}.
42842
9a6253be
KB
42843Stubs are not required to recognize these interrupt mechanisms and the
42844precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
42845implementation defined. If the target supports debugging of multiple
42846threads and/or processes, it should attempt to interrupt all
42847currently-executing threads and processes.
42848If the stub is successful at interrupting the
42849running program, it should send one of the stop
42850reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42851of successfully stopping the program in all-stop mode, and a stop reply
42852for each stopped thread in non-stop mode.
42853Interrupts received while the
cde67b27
YQ
42854program is stopped are queued and the program will be interrupted when
42855it is resumed next time.
8b23ecc4
SL
42856
42857@node Notification Packets
42858@section Notification Packets
42859@cindex notification packets
42860@cindex packets, notification
42861
42862The @value{GDBN} remote serial protocol includes @dfn{notifications},
42863packets that require no acknowledgment. Both the GDB and the stub
42864may send notifications (although the only notifications defined at
42865present are sent by the stub). Notifications carry information
42866without incurring the round-trip latency of an acknowledgment, and so
42867are useful for low-impact communications where occasional packet loss
42868is not a problem.
42869
42870A notification packet has the form @samp{% @var{data} #
42871@var{checksum}}, where @var{data} is the content of the notification,
42872and @var{checksum} is a checksum of @var{data}, computed and formatted
42873as for ordinary @value{GDBN} packets. A notification's @var{data}
42874never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42875receiving a notification, the recipient sends no @samp{+} or @samp{-}
42876to acknowledge the notification's receipt or to report its corruption.
42877
42878Every notification's @var{data} begins with a name, which contains no
42879colon characters, followed by a colon character.
42880
42881Recipients should silently ignore corrupted notifications and
42882notifications they do not understand. Recipients should restart
42883timeout periods on receipt of a well-formed notification, whether or
42884not they understand it.
42885
42886Senders should only send the notifications described here when this
42887protocol description specifies that they are permitted. In the
42888future, we may extend the protocol to permit existing notifications in
42889new contexts; this rule helps older senders avoid confusing newer
42890recipients.
42891
42892(Older versions of @value{GDBN} ignore bytes received until they see
42893the @samp{$} byte that begins an ordinary packet, so new stubs may
42894transmit notifications without fear of confusing older clients. There
42895are no notifications defined for @value{GDBN} to send at the moment, but we
42896assume that most older stubs would ignore them, as well.)
42897
8dbe8ece 42898Each notification is comprised of three parts:
8b23ecc4 42899@table @samp
8dbe8ece
YQ
42900@item @var{name}:@var{event}
42901The notification packet is sent by the side that initiates the
42902exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
42903carrying the specific information about the notification, and
42904@var{name} specifying the name of the notification.
8dbe8ece
YQ
42905@item @var{ack}
42906The acknowledge sent by the other side, usually @value{GDBN}, to
42907acknowledge the exchange and request the event.
42908@end table
42909
42910The purpose of an asynchronous notification mechanism is to report to
42911@value{GDBN} that something interesting happened in the remote stub.
42912
42913The remote stub may send notification @var{name}:@var{event}
42914at any time, but @value{GDBN} acknowledges the notification when
42915appropriate. The notification event is pending before @value{GDBN}
42916acknowledges. Only one notification at a time may be pending; if
42917additional events occur before @value{GDBN} has acknowledged the
42918previous notification, they must be queued by the stub for later
42919synchronous transmission in response to @var{ack} packets from
42920@value{GDBN}. Because the notification mechanism is unreliable,
42921the stub is permitted to resend a notification if it believes
42922@value{GDBN} may not have received it.
42923
42924Specifically, notifications may appear when @value{GDBN} is not
42925otherwise reading input from the stub, or when @value{GDBN} is
42926expecting to read a normal synchronous response or a
42927@samp{+}/@samp{-} acknowledgment to a packet it has sent.
42928Notification packets are distinct from any other communication from
42929the stub so there is no ambiguity.
42930
42931After receiving a notification, @value{GDBN} shall acknowledge it by
42932sending a @var{ack} packet as a regular, synchronous request to the
42933stub. Such acknowledgment is not required to happen immediately, as
42934@value{GDBN} is permitted to send other, unrelated packets to the
42935stub first, which the stub should process normally.
42936
42937Upon receiving a @var{ack} packet, if the stub has other queued
42938events to report to @value{GDBN}, it shall respond by sending a
42939normal @var{event}. @value{GDBN} shall then send another @var{ack}
42940packet to solicit further responses; again, it is permitted to send
42941other, unrelated packets as well which the stub should process
42942normally.
42943
42944If the stub receives a @var{ack} packet and there are no additional
42945@var{event} to report, the stub shall return an @samp{OK} response.
42946At this point, @value{GDBN} has finished processing a notification
42947and the stub has completed sending any queued events. @value{GDBN}
42948won't accept any new notifications until the final @samp{OK} is
42949received . If further notification events occur, the stub shall send
42950a new notification, @value{GDBN} shall accept the notification, and
42951the process shall be repeated.
42952
42953The process of asynchronous notification can be illustrated by the
42954following example:
42955@smallexample
4435e1cc 42956<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
42957@code{...}
42958-> @code{vStopped}
42959<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42960-> @code{vStopped}
42961<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42962-> @code{vStopped}
42963<- @code{OK}
42964@end smallexample
42965
42966The following notifications are defined:
42967@multitable @columnfractions 0.12 0.12 0.38 0.38
42968
42969@item Notification
42970@tab Ack
42971@tab Event
42972@tab Description
42973
42974@item Stop
42975@tab vStopped
42976@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
42977described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42978for information on how these notifications are acknowledged by
42979@value{GDBN}.
8dbe8ece
YQ
42980@tab Report an asynchronous stop event in non-stop mode.
42981
42982@end multitable
8b23ecc4
SL
42983
42984@node Remote Non-Stop
42985@section Remote Protocol Support for Non-Stop Mode
42986
42987@value{GDBN}'s remote protocol supports non-stop debugging of
42988multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42989supports non-stop mode, it should report that to @value{GDBN} by including
42990@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42991
42992@value{GDBN} typically sends a @samp{QNonStop} packet only when
42993establishing a new connection with the stub. Entering non-stop mode
42994does not alter the state of any currently-running threads, but targets
42995must stop all threads in any already-attached processes when entering
42996all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42997probe the target state after a mode change.
42998
42999In non-stop mode, when an attached process encounters an event that
43000would otherwise be reported with a stop reply, it uses the
43001asynchronous notification mechanism (@pxref{Notification Packets}) to
43002inform @value{GDBN}. In contrast to all-stop mode, where all threads
43003in all processes are stopped when a stop reply is sent, in non-stop
43004mode only the thread reporting the stop event is stopped. That is,
43005when reporting a @samp{S} or @samp{T} response to indicate completion
43006of a step operation, hitting a breakpoint, or a fault, only the
43007affected thread is stopped; any other still-running threads continue
43008to run. When reporting a @samp{W} or @samp{X} response, all running
43009threads belonging to other attached processes continue to run.
43010
8b23ecc4
SL
43011In non-stop mode, the target shall respond to the @samp{?} packet as
43012follows. First, any incomplete stop reply notification/@samp{vStopped}
43013sequence in progress is abandoned. The target must begin a new
43014sequence reporting stop events for all stopped threads, whether or not
43015it has previously reported those events to @value{GDBN}. The first
43016stop reply is sent as a synchronous reply to the @samp{?} packet, and
43017subsequent stop replies are sent as responses to @samp{vStopped} packets
43018using the mechanism described above. The target must not send
43019asynchronous stop reply notifications until the sequence is complete.
43020If all threads are running when the target receives the @samp{?} packet,
43021or if the target is not attached to any process, it shall respond
43022@samp{OK}.
9a6253be 43023
f7e6eed5
PA
43024If the stub supports non-stop mode, it should also support the
43025@samp{swbreak} stop reason if software breakpoints are supported, and
43026the @samp{hwbreak} stop reason if hardware breakpoints are supported
43027(@pxref{swbreak stop reason}). This is because given the asynchronous
43028nature of non-stop mode, between the time a thread hits a breakpoint
43029and the time the event is finally processed by @value{GDBN}, the
43030breakpoint may have already been removed from the target. Due to
43031this, @value{GDBN} needs to be able to tell whether a trap stop was
43032caused by a delayed breakpoint event, which should be ignored, as
43033opposed to a random trap signal, which should be reported to the user.
43034Note the @samp{swbreak} feature implies that the target is responsible
43035for adjusting the PC when a software breakpoint triggers, if
43036necessary, such as on the x86 architecture.
43037
a6f3e723
SL
43038@node Packet Acknowledgment
43039@section Packet Acknowledgment
43040
43041@cindex acknowledgment, for @value{GDBN} remote
43042@cindex packet acknowledgment, for @value{GDBN} remote
43043By default, when either the host or the target machine receives a packet,
43044the first response expected is an acknowledgment: either @samp{+} (to indicate
43045the package was received correctly) or @samp{-} (to request retransmission).
43046This mechanism allows the @value{GDBN} remote protocol to operate over
43047unreliable transport mechanisms, such as a serial line.
43048
43049In cases where the transport mechanism is itself reliable (such as a pipe or
43050TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43051It may be desirable to disable them in that case to reduce communication
43052overhead, or for other reasons. This can be accomplished by means of the
43053@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43054
43055When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43056expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43057and response format still includes the normal checksum, as described in
43058@ref{Overview}, but the checksum may be ignored by the receiver.
43059
43060If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43061no-acknowledgment mode, it should report that to @value{GDBN}
43062by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43063@pxref{qSupported}.
43064If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43065disabled via the @code{set remote noack-packet off} command
43066(@pxref{Remote Configuration}),
43067@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43068Only then may the stub actually turn off packet acknowledgments.
43069@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43070response, which can be safely ignored by the stub.
43071
43072Note that @code{set remote noack-packet} command only affects negotiation
43073between @value{GDBN} and the stub when subsequent connections are made;
43074it does not affect the protocol acknowledgment state for any current
43075connection.
43076Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43077new connection is established,
43078there is also no protocol request to re-enable the acknowledgments
43079for the current connection, once disabled.
43080
ee2d5c50
AC
43081@node Examples
43082@section Examples
eb12ee30 43083
8e04817f
AC
43084Example sequence of a target being re-started. Notice how the restart
43085does not get any direct output:
eb12ee30 43086
474c8240 43087@smallexample
d2c6833e
AC
43088-> @code{R00}
43089<- @code{+}
8e04817f 43090@emph{target restarts}
d2c6833e 43091-> @code{?}
8e04817f 43092<- @code{+}
d2c6833e
AC
43093<- @code{T001:1234123412341234}
43094-> @code{+}
474c8240 43095@end smallexample
eb12ee30 43096
8e04817f 43097Example sequence of a target being stepped by a single instruction:
eb12ee30 43098
474c8240 43099@smallexample
d2c6833e 43100-> @code{G1445@dots{}}
8e04817f 43101<- @code{+}
d2c6833e
AC
43102-> @code{s}
43103<- @code{+}
43104@emph{time passes}
43105<- @code{T001:1234123412341234}
8e04817f 43106-> @code{+}
d2c6833e 43107-> @code{g}
8e04817f 43108<- @code{+}
d2c6833e
AC
43109<- @code{1455@dots{}}
43110-> @code{+}
474c8240 43111@end smallexample
eb12ee30 43112
79a6e687
BW
43113@node File-I/O Remote Protocol Extension
43114@section File-I/O Remote Protocol Extension
0ce1b118
CV
43115@cindex File-I/O remote protocol extension
43116
43117@menu
43118* File-I/O Overview::
79a6e687
BW
43119* Protocol Basics::
43120* The F Request Packet::
43121* The F Reply Packet::
43122* The Ctrl-C Message::
0ce1b118 43123* Console I/O::
79a6e687 43124* List of Supported Calls::
db2e3e2e 43125* Protocol-specific Representation of Datatypes::
0ce1b118
CV
43126* Constants::
43127* File-I/O Examples::
43128@end menu
43129
43130@node File-I/O Overview
43131@subsection File-I/O Overview
43132@cindex file-i/o overview
43133
9c16f35a 43134The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 43135target to use the host's file system and console I/O to perform various
0ce1b118 43136system calls. System calls on the target system are translated into a
fc320d37
SL
43137remote protocol packet to the host system, which then performs the needed
43138actions and returns a response packet to the target system.
0ce1b118
CV
43139This simulates file system operations even on targets that lack file systems.
43140
fc320d37
SL
43141The protocol is defined to be independent of both the host and target systems.
43142It uses its own internal representation of datatypes and values. Both
0ce1b118 43143@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
43144translating the system-dependent value representations into the internal
43145protocol representations when data is transmitted.
0ce1b118 43146
fc320d37
SL
43147The communication is synchronous. A system call is possible only when
43148@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43149or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 43150the target is stopped to allow deterministic access to the target's
fc320d37
SL
43151memory. Therefore File-I/O is not interruptible by target signals. On
43152the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 43153(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
43154
43155The target's request to perform a host system call does not finish
43156the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43157after finishing the system call, the target returns to continuing the
43158previous activity (continue, step). No additional continue or step
43159request from @value{GDBN} is required.
43160
43161@smallexample
f7dc1244 43162(@value{GDBP}) continue
0ce1b118
CV
43163 <- target requests 'system call X'
43164 target is stopped, @value{GDBN} executes system call
3f94c067
BW
43165 -> @value{GDBN} returns result
43166 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
43167 <- target hits breakpoint and sends a Txx packet
43168@end smallexample
43169
fc320d37
SL
43170The protocol only supports I/O on the console and to regular files on
43171the host file system. Character or block special devices, pipes,
43172named pipes, sockets or any other communication method on the host
0ce1b118
CV
43173system are not supported by this protocol.
43174
8b23ecc4
SL
43175File I/O is not supported in non-stop mode.
43176
79a6e687
BW
43177@node Protocol Basics
43178@subsection Protocol Basics
0ce1b118
CV
43179@cindex protocol basics, file-i/o
43180
fc320d37
SL
43181The File-I/O protocol uses the @code{F} packet as the request as well
43182as reply packet. Since a File-I/O system call can only occur when
43183@value{GDBN} is waiting for a response from the continuing or stepping target,
43184the File-I/O request is a reply that @value{GDBN} has to expect as a result
43185of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
43186This @code{F} packet contains all information needed to allow @value{GDBN}
43187to call the appropriate host system call:
43188
43189@itemize @bullet
b383017d 43190@item
0ce1b118
CV
43191A unique identifier for the requested system call.
43192
43193@item
43194All parameters to the system call. Pointers are given as addresses
43195in the target memory address space. Pointers to strings are given as
b383017d 43196pointer/length pair. Numerical values are given as they are.
db2e3e2e 43197Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
43198
43199@end itemize
43200
fc320d37 43201At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
43202
43203@itemize @bullet
b383017d 43204@item
fc320d37
SL
43205If the parameters include pointer values to data needed as input to a
43206system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
43207standard @code{m} packet request. This additional communication has to be
43208expected by the target implementation and is handled as any other @code{m}
43209packet.
43210
43211@item
43212@value{GDBN} translates all value from protocol representation to host
43213representation as needed. Datatypes are coerced into the host types.
43214
43215@item
fc320d37 43216@value{GDBN} calls the system call.
0ce1b118
CV
43217
43218@item
43219It then coerces datatypes back to protocol representation.
43220
43221@item
fc320d37
SL
43222If the system call is expected to return data in buffer space specified
43223by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
43224target using a @code{M} or @code{X} packet. This packet has to be expected
43225by the target implementation and is handled as any other @code{M} or @code{X}
43226packet.
43227
43228@end itemize
43229
43230Eventually @value{GDBN} replies with another @code{F} packet which contains all
43231necessary information for the target to continue. This at least contains
43232
43233@itemize @bullet
43234@item
43235Return value.
43236
43237@item
43238@code{errno}, if has been changed by the system call.
43239
43240@item
43241``Ctrl-C'' flag.
43242
43243@end itemize
43244
43245After having done the needed type and value coercion, the target continues
43246the latest continue or step action.
43247
79a6e687
BW
43248@node The F Request Packet
43249@subsection The @code{F} Request Packet
0ce1b118
CV
43250@cindex file-i/o request packet
43251@cindex @code{F} request packet
43252
43253The @code{F} request packet has the following format:
43254
43255@table @samp
fc320d37 43256@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
43257
43258@var{call-id} is the identifier to indicate the host system call to be called.
43259This is just the name of the function.
43260
fc320d37
SL
43261@var{parameter@dots{}} are the parameters to the system call.
43262Parameters are hexadecimal integer values, either the actual values in case
43263of scalar datatypes, pointers to target buffer space in case of compound
43264datatypes and unspecified memory areas, or pointer/length pairs in case
43265of string parameters. These are appended to the @var{call-id} as a
43266comma-delimited list. All values are transmitted in ASCII
43267string representation, pointer/length pairs separated by a slash.
0ce1b118 43268
b383017d 43269@end table
0ce1b118 43270
fc320d37 43271
0ce1b118 43272
79a6e687
BW
43273@node The F Reply Packet
43274@subsection The @code{F} Reply Packet
0ce1b118
CV
43275@cindex file-i/o reply packet
43276@cindex @code{F} reply packet
43277
43278The @code{F} reply packet has the following format:
43279
43280@table @samp
43281
d3bdde98 43282@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
43283
43284@var{retcode} is the return code of the system call as hexadecimal value.
43285
db2e3e2e
BW
43286@var{errno} is the @code{errno} set by the call, in protocol-specific
43287representation.
0ce1b118
CV
43288This parameter can be omitted if the call was successful.
43289
fc320d37
SL
43290@var{Ctrl-C flag} is only sent if the user requested a break. In this
43291case, @var{errno} must be sent as well, even if the call was successful.
43292The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
43293
43294@smallexample
43295F0,0,C
43296@end smallexample
43297
43298@noindent
fc320d37 43299or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43300
43301@smallexample
43302F-1,4,C
43303@end smallexample
43304
43305@noindent
db2e3e2e 43306assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43307
43308@end table
43309
0ce1b118 43310
79a6e687
BW
43311@node The Ctrl-C Message
43312@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43313@cindex ctrl-c message, in file-i/o protocol
43314
c8aa23ab 43315If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43316reply packet (@pxref{The F Reply Packet}),
fc320d37 43317the target should behave as if it had
0ce1b118 43318gotten a break message. The meaning for the target is ``system call
fc320d37 43319interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43320(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43321packet.
fc320d37
SL
43322
43323It's important for the target to know in which
43324state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43325
43326@itemize @bullet
43327@item
43328The system call hasn't been performed on the host yet.
43329
43330@item
43331The system call on the host has been finished.
43332
43333@end itemize
43334
43335These two states can be distinguished by the target by the value of the
43336returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43337call hasn't been performed. This is equivalent to the @code{EINTR} handling
43338on POSIX systems. In any other case, the target may presume that the
fc320d37 43339system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43340as if the break message arrived right after the system call.
43341
fc320d37 43342@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43343yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43344@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43345before the user requests a break, the full action must be finished by
43346@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43347The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43348or the full action has been completed.
43349
43350@node Console I/O
43351@subsection Console I/O
43352@cindex console i/o as part of file-i/o
43353
d3e8051b 43354By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43355descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43356on the @value{GDBN} console is handled as any other file output operation
43357(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43358by @value{GDBN} so that after the target read request from file descriptor
433590 all following typing is buffered until either one of the following
43360conditions is met:
43361
43362@itemize @bullet
43363@item
c8aa23ab 43364The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43365@code{read}
43366system call is treated as finished.
43367
43368@item
7f9087cb 43369The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43370newline.
0ce1b118
CV
43371
43372@item
c8aa23ab
EZ
43373The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43374character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43375
43376@end itemize
43377
fc320d37
SL
43378If the user has typed more characters than fit in the buffer given to
43379the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43380either another @code{read(0, @dots{})} is requested by the target, or debugging
43381is stopped at the user's request.
0ce1b118 43382
0ce1b118 43383
79a6e687
BW
43384@node List of Supported Calls
43385@subsection List of Supported Calls
0ce1b118
CV
43386@cindex list of supported file-i/o calls
43387
43388@menu
43389* open::
43390* close::
43391* read::
43392* write::
43393* lseek::
43394* rename::
43395* unlink::
43396* stat/fstat::
43397* gettimeofday::
43398* isatty::
43399* system::
43400@end menu
43401
43402@node open
43403@unnumberedsubsubsec open
43404@cindex open, file-i/o system call
43405
fc320d37
SL
43406@table @asis
43407@item Synopsis:
0ce1b118 43408@smallexample
0ce1b118
CV
43409int open(const char *pathname, int flags);
43410int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43411@end smallexample
43412
fc320d37
SL
43413@item Request:
43414@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43415
0ce1b118 43416@noindent
fc320d37 43417@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43418
43419@table @code
b383017d 43420@item O_CREAT
0ce1b118
CV
43421If the file does not exist it will be created. The host
43422rules apply as far as file ownership and time stamps
43423are concerned.
43424
b383017d 43425@item O_EXCL
fc320d37 43426When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43427an error and open() fails.
43428
b383017d 43429@item O_TRUNC
0ce1b118 43430If the file already exists and the open mode allows
fc320d37
SL
43431writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43432truncated to zero length.
0ce1b118 43433
b383017d 43434@item O_APPEND
0ce1b118
CV
43435The file is opened in append mode.
43436
b383017d 43437@item O_RDONLY
0ce1b118
CV
43438The file is opened for reading only.
43439
b383017d 43440@item O_WRONLY
0ce1b118
CV
43441The file is opened for writing only.
43442
b383017d 43443@item O_RDWR
0ce1b118 43444The file is opened for reading and writing.
fc320d37 43445@end table
0ce1b118
CV
43446
43447@noindent
fc320d37 43448Other bits are silently ignored.
0ce1b118 43449
0ce1b118
CV
43450
43451@noindent
fc320d37 43452@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43453
43454@table @code
b383017d 43455@item S_IRUSR
0ce1b118
CV
43456User has read permission.
43457
b383017d 43458@item S_IWUSR
0ce1b118
CV
43459User has write permission.
43460
b383017d 43461@item S_IRGRP
0ce1b118
CV
43462Group has read permission.
43463
b383017d 43464@item S_IWGRP
0ce1b118
CV
43465Group has write permission.
43466
b383017d 43467@item S_IROTH
0ce1b118
CV
43468Others have read permission.
43469
b383017d 43470@item S_IWOTH
0ce1b118 43471Others have write permission.
fc320d37 43472@end table
0ce1b118
CV
43473
43474@noindent
fc320d37 43475Other bits are silently ignored.
0ce1b118 43476
0ce1b118 43477
fc320d37
SL
43478@item Return value:
43479@code{open} returns the new file descriptor or -1 if an error
43480occurred.
0ce1b118 43481
fc320d37 43482@item Errors:
0ce1b118
CV
43483
43484@table @code
b383017d 43485@item EEXIST
fc320d37 43486@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43487
b383017d 43488@item EISDIR
fc320d37 43489@var{pathname} refers to a directory.
0ce1b118 43490
b383017d 43491@item EACCES
0ce1b118
CV
43492The requested access is not allowed.
43493
43494@item ENAMETOOLONG
fc320d37 43495@var{pathname} was too long.
0ce1b118 43496
b383017d 43497@item ENOENT
fc320d37 43498A directory component in @var{pathname} does not exist.
0ce1b118 43499
b383017d 43500@item ENODEV
fc320d37 43501@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43502
b383017d 43503@item EROFS
fc320d37 43504@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43505write access was requested.
43506
b383017d 43507@item EFAULT
fc320d37 43508@var{pathname} is an invalid pointer value.
0ce1b118 43509
b383017d 43510@item ENOSPC
0ce1b118
CV
43511No space on device to create the file.
43512
b383017d 43513@item EMFILE
0ce1b118
CV
43514The process already has the maximum number of files open.
43515
b383017d 43516@item ENFILE
0ce1b118
CV
43517The limit on the total number of files open on the system
43518has been reached.
43519
b383017d 43520@item EINTR
0ce1b118
CV
43521The call was interrupted by the user.
43522@end table
43523
fc320d37
SL
43524@end table
43525
0ce1b118
CV
43526@node close
43527@unnumberedsubsubsec close
43528@cindex close, file-i/o system call
43529
fc320d37
SL
43530@table @asis
43531@item Synopsis:
0ce1b118 43532@smallexample
0ce1b118 43533int close(int fd);
fc320d37 43534@end smallexample
0ce1b118 43535
fc320d37
SL
43536@item Request:
43537@samp{Fclose,@var{fd}}
0ce1b118 43538
fc320d37
SL
43539@item Return value:
43540@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43541
fc320d37 43542@item Errors:
0ce1b118
CV
43543
43544@table @code
b383017d 43545@item EBADF
fc320d37 43546@var{fd} isn't a valid open file descriptor.
0ce1b118 43547
b383017d 43548@item EINTR
0ce1b118
CV
43549The call was interrupted by the user.
43550@end table
43551
fc320d37
SL
43552@end table
43553
0ce1b118
CV
43554@node read
43555@unnumberedsubsubsec read
43556@cindex read, file-i/o system call
43557
fc320d37
SL
43558@table @asis
43559@item Synopsis:
0ce1b118 43560@smallexample
0ce1b118 43561int read(int fd, void *buf, unsigned int count);
fc320d37 43562@end smallexample
0ce1b118 43563
fc320d37
SL
43564@item Request:
43565@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43566
fc320d37 43567@item Return value:
0ce1b118
CV
43568On success, the number of bytes read is returned.
43569Zero indicates end of file. If count is zero, read
b383017d 43570returns zero as well. On error, -1 is returned.
0ce1b118 43571
fc320d37 43572@item Errors:
0ce1b118
CV
43573
43574@table @code
b383017d 43575@item EBADF
fc320d37 43576@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43577reading.
43578
b383017d 43579@item EFAULT
fc320d37 43580@var{bufptr} is an invalid pointer value.
0ce1b118 43581
b383017d 43582@item EINTR
0ce1b118
CV
43583The call was interrupted by the user.
43584@end table
43585
fc320d37
SL
43586@end table
43587
0ce1b118
CV
43588@node write
43589@unnumberedsubsubsec write
43590@cindex write, file-i/o system call
43591
fc320d37
SL
43592@table @asis
43593@item Synopsis:
0ce1b118 43594@smallexample
0ce1b118 43595int write(int fd, const void *buf, unsigned int count);
fc320d37 43596@end smallexample
0ce1b118 43597
fc320d37
SL
43598@item Request:
43599@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43600
fc320d37 43601@item Return value:
0ce1b118
CV
43602On success, the number of bytes written are returned.
43603Zero indicates nothing was written. On error, -1
43604is returned.
43605
fc320d37 43606@item Errors:
0ce1b118
CV
43607
43608@table @code
b383017d 43609@item EBADF
fc320d37 43610@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43611writing.
43612
b383017d 43613@item EFAULT
fc320d37 43614@var{bufptr} is an invalid pointer value.
0ce1b118 43615
b383017d 43616@item EFBIG
0ce1b118 43617An attempt was made to write a file that exceeds the
db2e3e2e 43618host-specific maximum file size allowed.
0ce1b118 43619
b383017d 43620@item ENOSPC
0ce1b118
CV
43621No space on device to write the data.
43622
b383017d 43623@item EINTR
0ce1b118
CV
43624The call was interrupted by the user.
43625@end table
43626
fc320d37
SL
43627@end table
43628
0ce1b118
CV
43629@node lseek
43630@unnumberedsubsubsec lseek
43631@cindex lseek, file-i/o system call
43632
fc320d37
SL
43633@table @asis
43634@item Synopsis:
0ce1b118 43635@smallexample
0ce1b118 43636long lseek (int fd, long offset, int flag);
0ce1b118
CV
43637@end smallexample
43638
fc320d37
SL
43639@item Request:
43640@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43641
43642@var{flag} is one of:
0ce1b118
CV
43643
43644@table @code
b383017d 43645@item SEEK_SET
fc320d37 43646The offset is set to @var{offset} bytes.
0ce1b118 43647
b383017d 43648@item SEEK_CUR
fc320d37 43649The offset is set to its current location plus @var{offset}
0ce1b118
CV
43650bytes.
43651
b383017d 43652@item SEEK_END
fc320d37 43653The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43654bytes.
43655@end table
43656
fc320d37 43657@item Return value:
0ce1b118
CV
43658On success, the resulting unsigned offset in bytes from
43659the beginning of the file is returned. Otherwise, a
43660value of -1 is returned.
43661
fc320d37 43662@item Errors:
0ce1b118
CV
43663
43664@table @code
b383017d 43665@item EBADF
fc320d37 43666@var{fd} is not a valid open file descriptor.
0ce1b118 43667
b383017d 43668@item ESPIPE
fc320d37 43669@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43670
b383017d 43671@item EINVAL
fc320d37 43672@var{flag} is not a proper value.
0ce1b118 43673
b383017d 43674@item EINTR
0ce1b118
CV
43675The call was interrupted by the user.
43676@end table
43677
fc320d37
SL
43678@end table
43679
0ce1b118
CV
43680@node rename
43681@unnumberedsubsubsec rename
43682@cindex rename, file-i/o system call
43683
fc320d37
SL
43684@table @asis
43685@item Synopsis:
0ce1b118 43686@smallexample
0ce1b118 43687int rename(const char *oldpath, const char *newpath);
fc320d37 43688@end smallexample
0ce1b118 43689
fc320d37
SL
43690@item Request:
43691@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43692
fc320d37 43693@item Return value:
0ce1b118
CV
43694On success, zero is returned. On error, -1 is returned.
43695
fc320d37 43696@item Errors:
0ce1b118
CV
43697
43698@table @code
b383017d 43699@item EISDIR
fc320d37 43700@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43701directory.
43702
b383017d 43703@item EEXIST
fc320d37 43704@var{newpath} is a non-empty directory.
0ce1b118 43705
b383017d 43706@item EBUSY
fc320d37 43707@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43708process.
43709
b383017d 43710@item EINVAL
0ce1b118
CV
43711An attempt was made to make a directory a subdirectory
43712of itself.
43713
b383017d 43714@item ENOTDIR
fc320d37
SL
43715A component used as a directory in @var{oldpath} or new
43716path is not a directory. Or @var{oldpath} is a directory
43717and @var{newpath} exists but is not a directory.
0ce1b118 43718
b383017d 43719@item EFAULT
fc320d37 43720@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43721
b383017d 43722@item EACCES
0ce1b118
CV
43723No access to the file or the path of the file.
43724
43725@item ENAMETOOLONG
b383017d 43726
fc320d37 43727@var{oldpath} or @var{newpath} was too long.
0ce1b118 43728
b383017d 43729@item ENOENT
fc320d37 43730A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 43731
b383017d 43732@item EROFS
0ce1b118
CV
43733The file is on a read-only filesystem.
43734
b383017d 43735@item ENOSPC
0ce1b118
CV
43736The device containing the file has no room for the new
43737directory entry.
43738
b383017d 43739@item EINTR
0ce1b118
CV
43740The call was interrupted by the user.
43741@end table
43742
fc320d37
SL
43743@end table
43744
0ce1b118
CV
43745@node unlink
43746@unnumberedsubsubsec unlink
43747@cindex unlink, file-i/o system call
43748
fc320d37
SL
43749@table @asis
43750@item Synopsis:
0ce1b118 43751@smallexample
0ce1b118 43752int unlink(const char *pathname);
fc320d37 43753@end smallexample
0ce1b118 43754
fc320d37
SL
43755@item Request:
43756@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 43757
fc320d37 43758@item Return value:
0ce1b118
CV
43759On success, zero is returned. On error, -1 is returned.
43760
fc320d37 43761@item Errors:
0ce1b118
CV
43762
43763@table @code
b383017d 43764@item EACCES
0ce1b118
CV
43765No access to the file or the path of the file.
43766
b383017d 43767@item EPERM
0ce1b118
CV
43768The system does not allow unlinking of directories.
43769
b383017d 43770@item EBUSY
fc320d37 43771The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
43772being used by another process.
43773
b383017d 43774@item EFAULT
fc320d37 43775@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
43776
43777@item ENAMETOOLONG
fc320d37 43778@var{pathname} was too long.
0ce1b118 43779
b383017d 43780@item ENOENT
fc320d37 43781A directory component in @var{pathname} does not exist.
0ce1b118 43782
b383017d 43783@item ENOTDIR
0ce1b118
CV
43784A component of the path is not a directory.
43785
b383017d 43786@item EROFS
0ce1b118
CV
43787The file is on a read-only filesystem.
43788
b383017d 43789@item EINTR
0ce1b118
CV
43790The call was interrupted by the user.
43791@end table
43792
fc320d37
SL
43793@end table
43794
0ce1b118
CV
43795@node stat/fstat
43796@unnumberedsubsubsec stat/fstat
43797@cindex fstat, file-i/o system call
43798@cindex stat, file-i/o system call
43799
fc320d37
SL
43800@table @asis
43801@item Synopsis:
0ce1b118 43802@smallexample
0ce1b118
CV
43803int stat(const char *pathname, struct stat *buf);
43804int fstat(int fd, struct stat *buf);
fc320d37 43805@end smallexample
0ce1b118 43806
fc320d37
SL
43807@item Request:
43808@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43809@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 43810
fc320d37 43811@item Return value:
0ce1b118
CV
43812On success, zero is returned. On error, -1 is returned.
43813
fc320d37 43814@item Errors:
0ce1b118
CV
43815
43816@table @code
b383017d 43817@item EBADF
fc320d37 43818@var{fd} is not a valid open file.
0ce1b118 43819
b383017d 43820@item ENOENT
fc320d37 43821A directory component in @var{pathname} does not exist or the
0ce1b118
CV
43822path is an empty string.
43823
b383017d 43824@item ENOTDIR
0ce1b118
CV
43825A component of the path is not a directory.
43826
b383017d 43827@item EFAULT
fc320d37 43828@var{pathnameptr} is an invalid pointer value.
0ce1b118 43829
b383017d 43830@item EACCES
0ce1b118
CV
43831No access to the file or the path of the file.
43832
43833@item ENAMETOOLONG
fc320d37 43834@var{pathname} was too long.
0ce1b118 43835
b383017d 43836@item EINTR
0ce1b118
CV
43837The call was interrupted by the user.
43838@end table
43839
fc320d37
SL
43840@end table
43841
0ce1b118
CV
43842@node gettimeofday
43843@unnumberedsubsubsec gettimeofday
43844@cindex gettimeofday, file-i/o system call
43845
fc320d37
SL
43846@table @asis
43847@item Synopsis:
0ce1b118 43848@smallexample
0ce1b118 43849int gettimeofday(struct timeval *tv, void *tz);
fc320d37 43850@end smallexample
0ce1b118 43851
fc320d37
SL
43852@item Request:
43853@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 43854
fc320d37 43855@item Return value:
0ce1b118
CV
43856On success, 0 is returned, -1 otherwise.
43857
fc320d37 43858@item Errors:
0ce1b118
CV
43859
43860@table @code
b383017d 43861@item EINVAL
fc320d37 43862@var{tz} is a non-NULL pointer.
0ce1b118 43863
b383017d 43864@item EFAULT
fc320d37
SL
43865@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43866@end table
43867
0ce1b118
CV
43868@end table
43869
43870@node isatty
43871@unnumberedsubsubsec isatty
43872@cindex isatty, file-i/o system call
43873
fc320d37
SL
43874@table @asis
43875@item Synopsis:
0ce1b118 43876@smallexample
0ce1b118 43877int isatty(int fd);
fc320d37 43878@end smallexample
0ce1b118 43879
fc320d37
SL
43880@item Request:
43881@samp{Fisatty,@var{fd}}
0ce1b118 43882
fc320d37
SL
43883@item Return value:
43884Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 43885
fc320d37 43886@item Errors:
0ce1b118
CV
43887
43888@table @code
b383017d 43889@item EINTR
0ce1b118
CV
43890The call was interrupted by the user.
43891@end table
43892
fc320d37
SL
43893@end table
43894
43895Note that the @code{isatty} call is treated as a special case: it returns
438961 to the target if the file descriptor is attached
43897to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43898would require implementing @code{ioctl} and would be more complex than
43899needed.
43900
43901
0ce1b118
CV
43902@node system
43903@unnumberedsubsubsec system
43904@cindex system, file-i/o system call
43905
fc320d37
SL
43906@table @asis
43907@item Synopsis:
0ce1b118 43908@smallexample
0ce1b118 43909int system(const char *command);
fc320d37 43910@end smallexample
0ce1b118 43911
fc320d37
SL
43912@item Request:
43913@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 43914
fc320d37 43915@item Return value:
5600ea19
NS
43916If @var{len} is zero, the return value indicates whether a shell is
43917available. A zero return value indicates a shell is not available.
43918For non-zero @var{len}, the value returned is -1 on error and the
43919return status of the command otherwise. Only the exit status of the
43920command is returned, which is extracted from the host's @code{system}
43921return value by calling @code{WEXITSTATUS(retval)}. In case
43922@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 43923
fc320d37 43924@item Errors:
0ce1b118
CV
43925
43926@table @code
b383017d 43927@item EINTR
0ce1b118
CV
43928The call was interrupted by the user.
43929@end table
43930
fc320d37
SL
43931@end table
43932
43933@value{GDBN} takes over the full task of calling the necessary host calls
43934to perform the @code{system} call. The return value of @code{system} on
43935the host is simplified before it's returned
43936to the target. Any termination signal information from the child process
43937is discarded, and the return value consists
43938entirely of the exit status of the called command.
43939
43940Due to security concerns, the @code{system} call is by default refused
43941by @value{GDBN}. The user has to allow this call explicitly with the
43942@code{set remote system-call-allowed 1} command.
43943
43944@table @code
43945@item set remote system-call-allowed
43946@kindex set remote system-call-allowed
43947Control whether to allow the @code{system} calls in the File I/O
43948protocol for the remote target. The default is zero (disabled).
43949
43950@item show remote system-call-allowed
43951@kindex show remote system-call-allowed
43952Show whether the @code{system} calls are allowed in the File I/O
43953protocol.
43954@end table
43955
db2e3e2e
BW
43956@node Protocol-specific Representation of Datatypes
43957@subsection Protocol-specific Representation of Datatypes
43958@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
43959
43960@menu
79a6e687
BW
43961* Integral Datatypes::
43962* Pointer Values::
43963* Memory Transfer::
0ce1b118
CV
43964* struct stat::
43965* struct timeval::
43966@end menu
43967
79a6e687
BW
43968@node Integral Datatypes
43969@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
43970@cindex integral datatypes, in file-i/o protocol
43971
fc320d37
SL
43972The integral datatypes used in the system calls are @code{int},
43973@code{unsigned int}, @code{long}, @code{unsigned long},
43974@code{mode_t}, and @code{time_t}.
0ce1b118 43975
fc320d37 43976@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
43977implemented as 32 bit values in this protocol.
43978
fc320d37 43979@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 43980
0ce1b118
CV
43981@xref{Limits}, for corresponding MIN and MAX values (similar to those
43982in @file{limits.h}) to allow range checking on host and target.
43983
43984@code{time_t} datatypes are defined as seconds since the Epoch.
43985
43986All integral datatypes transferred as part of a memory read or write of a
43987structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43988byte order.
43989
79a6e687
BW
43990@node Pointer Values
43991@unnumberedsubsubsec Pointer Values
0ce1b118
CV
43992@cindex pointer values, in file-i/o protocol
43993
43994Pointers to target data are transmitted as they are. An exception
43995is made for pointers to buffers for which the length isn't
43996transmitted as part of the function call, namely strings. Strings
43997are transmitted as a pointer/length pair, both as hex values, e.g.@:
43998
43999@smallexample
44000@code{1aaf/12}
44001@end smallexample
44002
44003@noindent
44004which is a pointer to data of length 18 bytes at position 0x1aaf.
44005The length is defined as the full string length in bytes, including
fc320d37
SL
44006the trailing null byte. For example, the string @code{"hello world"}
44007at address 0x123456 is transmitted as
0ce1b118
CV
44008
44009@smallexample
fc320d37 44010@code{123456/d}
0ce1b118
CV
44011@end smallexample
44012
79a6e687
BW
44013@node Memory Transfer
44014@unnumberedsubsubsec Memory Transfer
fc320d37
SL
44015@cindex memory transfer, in file-i/o protocol
44016
44017Structured data which is transferred using a memory read or write (for
db2e3e2e 44018example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
44019with all scalar multibyte datatypes being big endian. Translation to
44020this representation needs to be done both by the target before the @code{F}
44021packet is sent, and by @value{GDBN} before
44022it transfers memory to the target. Transferred pointers to structured
44023data should point to the already-coerced data at any time.
0ce1b118 44024
0ce1b118
CV
44025
44026@node struct stat
44027@unnumberedsubsubsec struct stat
44028@cindex struct stat, in file-i/o protocol
44029
fc320d37
SL
44030The buffer of type @code{struct stat} used by the target and @value{GDBN}
44031is defined as follows:
0ce1b118
CV
44032
44033@smallexample
44034struct stat @{
44035 unsigned int st_dev; /* device */
44036 unsigned int st_ino; /* inode */
44037 mode_t st_mode; /* protection */
44038 unsigned int st_nlink; /* number of hard links */
44039 unsigned int st_uid; /* user ID of owner */
44040 unsigned int st_gid; /* group ID of owner */
44041 unsigned int st_rdev; /* device type (if inode device) */
44042 unsigned long st_size; /* total size, in bytes */
44043 unsigned long st_blksize; /* blocksize for filesystem I/O */
44044 unsigned long st_blocks; /* number of blocks allocated */
44045 time_t st_atime; /* time of last access */
44046 time_t st_mtime; /* time of last modification */
44047 time_t st_ctime; /* time of last change */
44048@};
44049@end smallexample
44050
fc320d37 44051The integral datatypes conform to the definitions given in the
79a6e687 44052appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44053structure is of size 64 bytes.
44054
44055The values of several fields have a restricted meaning and/or
44056range of values.
44057
fc320d37 44058@table @code
0ce1b118 44059
fc320d37
SL
44060@item st_dev
44061A value of 0 represents a file, 1 the console.
0ce1b118 44062
fc320d37
SL
44063@item st_ino
44064No valid meaning for the target. Transmitted unchanged.
0ce1b118 44065
fc320d37
SL
44066@item st_mode
44067Valid mode bits are described in @ref{Constants}. Any other
44068bits have currently no meaning for the target.
0ce1b118 44069
fc320d37
SL
44070@item st_uid
44071@itemx st_gid
44072@itemx st_rdev
44073No valid meaning for the target. Transmitted unchanged.
0ce1b118 44074
fc320d37
SL
44075@item st_atime
44076@itemx st_mtime
44077@itemx st_ctime
44078These values have a host and file system dependent
44079accuracy. Especially on Windows hosts, the file system may not
44080support exact timing values.
44081@end table
0ce1b118 44082
fc320d37
SL
44083The target gets a @code{struct stat} of the above representation and is
44084responsible for coercing it to the target representation before
0ce1b118
CV
44085continuing.
44086
fc320d37
SL
44087Note that due to size differences between the host, target, and protocol
44088representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
44089get truncated on the target.
44090
44091@node struct timeval
44092@unnumberedsubsubsec struct timeval
44093@cindex struct timeval, in file-i/o protocol
44094
fc320d37 44095The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
44096is defined as follows:
44097
44098@smallexample
b383017d 44099struct timeval @{
0ce1b118
CV
44100 time_t tv_sec; /* second */
44101 long tv_usec; /* microsecond */
44102@};
44103@end smallexample
44104
fc320d37 44105The integral datatypes conform to the definitions given in the
79a6e687 44106appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44107structure is of size 8 bytes.
44108
44109@node Constants
44110@subsection Constants
44111@cindex constants, in file-i/o protocol
44112
44113The following values are used for the constants inside of the
fc320d37 44114protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
44115values before and after the call as needed.
44116
44117@menu
79a6e687
BW
44118* Open Flags::
44119* mode_t Values::
44120* Errno Values::
44121* Lseek Flags::
0ce1b118
CV
44122* Limits::
44123@end menu
44124
79a6e687
BW
44125@node Open Flags
44126@unnumberedsubsubsec Open Flags
0ce1b118
CV
44127@cindex open flags, in file-i/o protocol
44128
44129All values are given in hexadecimal representation.
44130
44131@smallexample
44132 O_RDONLY 0x0
44133 O_WRONLY 0x1
44134 O_RDWR 0x2
44135 O_APPEND 0x8
44136 O_CREAT 0x200
44137 O_TRUNC 0x400
44138 O_EXCL 0x800
44139@end smallexample
44140
79a6e687
BW
44141@node mode_t Values
44142@unnumberedsubsubsec mode_t Values
0ce1b118
CV
44143@cindex mode_t values, in file-i/o protocol
44144
44145All values are given in octal representation.
44146
44147@smallexample
44148 S_IFREG 0100000
44149 S_IFDIR 040000
44150 S_IRUSR 0400
44151 S_IWUSR 0200
44152 S_IXUSR 0100
44153 S_IRGRP 040
44154 S_IWGRP 020
44155 S_IXGRP 010
44156 S_IROTH 04
44157 S_IWOTH 02
44158 S_IXOTH 01
44159@end smallexample
44160
79a6e687
BW
44161@node Errno Values
44162@unnumberedsubsubsec Errno Values
0ce1b118
CV
44163@cindex errno values, in file-i/o protocol
44164
44165All values are given in decimal representation.
44166
44167@smallexample
44168 EPERM 1
44169 ENOENT 2
44170 EINTR 4
44171 EBADF 9
44172 EACCES 13
44173 EFAULT 14
44174 EBUSY 16
44175 EEXIST 17
44176 ENODEV 19
44177 ENOTDIR 20
44178 EISDIR 21
44179 EINVAL 22
44180 ENFILE 23
44181 EMFILE 24
44182 EFBIG 27
44183 ENOSPC 28
44184 ESPIPE 29
44185 EROFS 30
44186 ENAMETOOLONG 91
44187 EUNKNOWN 9999
44188@end smallexample
44189
fc320d37 44190 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
44191 any error value not in the list of supported error numbers.
44192
79a6e687
BW
44193@node Lseek Flags
44194@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
44195@cindex lseek flags, in file-i/o protocol
44196
44197@smallexample
44198 SEEK_SET 0
44199 SEEK_CUR 1
44200 SEEK_END 2
44201@end smallexample
44202
44203@node Limits
44204@unnumberedsubsubsec Limits
44205@cindex limits, in file-i/o protocol
44206
44207All values are given in decimal representation.
44208
44209@smallexample
44210 INT_MIN -2147483648
44211 INT_MAX 2147483647
44212 UINT_MAX 4294967295
44213 LONG_MIN -9223372036854775808
44214 LONG_MAX 9223372036854775807
44215 ULONG_MAX 18446744073709551615
44216@end smallexample
44217
44218@node File-I/O Examples
44219@subsection File-I/O Examples
44220@cindex file-i/o examples
44221
44222Example sequence of a write call, file descriptor 3, buffer is at target
44223address 0x1234, 6 bytes should be written:
44224
44225@smallexample
44226<- @code{Fwrite,3,1234,6}
44227@emph{request memory read from target}
44228-> @code{m1234,6}
44229<- XXXXXX
44230@emph{return "6 bytes written"}
44231-> @code{F6}
44232@end smallexample
44233
44234Example sequence of a read call, file descriptor 3, buffer is at target
44235address 0x1234, 6 bytes should be read:
44236
44237@smallexample
44238<- @code{Fread,3,1234,6}
44239@emph{request memory write to target}
44240-> @code{X1234,6:XXXXXX}
44241@emph{return "6 bytes read"}
44242-> @code{F6}
44243@end smallexample
44244
44245Example sequence of a read call, call fails on the host due to invalid
fc320d37 44246file descriptor (@code{EBADF}):
0ce1b118
CV
44247
44248@smallexample
44249<- @code{Fread,3,1234,6}
44250-> @code{F-1,9}
44251@end smallexample
44252
c8aa23ab 44253Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
44254host is called:
44255
44256@smallexample
44257<- @code{Fread,3,1234,6}
44258-> @code{F-1,4,C}
44259<- @code{T02}
44260@end smallexample
44261
c8aa23ab 44262Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
44263host is called:
44264
44265@smallexample
44266<- @code{Fread,3,1234,6}
44267-> @code{X1234,6:XXXXXX}
44268<- @code{T02}
44269@end smallexample
44270
cfa9d6d9
DJ
44271@node Library List Format
44272@section Library List Format
44273@cindex library list format, remote protocol
44274
44275On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44276same process as your application to manage libraries. In this case,
44277@value{GDBN} can use the loader's symbol table and normal memory
44278operations to maintain a list of shared libraries. On other
44279platforms, the operating system manages loaded libraries.
44280@value{GDBN} can not retrieve the list of currently loaded libraries
44281through memory operations, so it uses the @samp{qXfer:libraries:read}
44282packet (@pxref{qXfer library list read}) instead. The remote stub
44283queries the target's operating system and reports which libraries
44284are loaded.
44285
44286The @samp{qXfer:libraries:read} packet returns an XML document which
44287lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
44288associated name and one or more segment or section base addresses,
44289which report where the library was loaded in memory.
44290
44291For the common case of libraries that are fully linked binaries, the
44292library should have a list of segments. If the target supports
44293dynamic linking of a relocatable object file, its library XML element
44294should instead include a list of allocated sections. The segment or
44295section bases are start addresses, not relocation offsets; they do not
44296depend on the library's link-time base addresses.
cfa9d6d9 44297
9cceb671
DJ
44298@value{GDBN} must be linked with the Expat library to support XML
44299library lists. @xref{Expat}.
44300
cfa9d6d9
DJ
44301A simple memory map, with one loaded library relocated by a single
44302offset, looks like this:
44303
44304@smallexample
44305<library-list>
44306 <library name="/lib/libc.so.6">
44307 <segment address="0x10000000"/>
44308 </library>
44309</library-list>
44310@end smallexample
44311
1fddbabb
PA
44312Another simple memory map, with one loaded library with three
44313allocated sections (.text, .data, .bss), looks like this:
44314
44315@smallexample
44316<library-list>
44317 <library name="sharedlib.o">
44318 <section address="0x10000000"/>
44319 <section address="0x20000000"/>
44320 <section address="0x30000000"/>
44321 </library>
44322</library-list>
44323@end smallexample
44324
cfa9d6d9
DJ
44325The format of a library list is described by this DTD:
44326
44327@smallexample
44328<!-- library-list: Root element with versioning -->
44329<!ELEMENT library-list (library)*>
44330<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44331<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44332<!ATTLIST library name CDATA #REQUIRED>
44333<!ELEMENT segment EMPTY>
44334<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44335<!ELEMENT section EMPTY>
44336<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44337@end smallexample
44338
1fddbabb
PA
44339In addition, segments and section descriptors cannot be mixed within a
44340single library element, and you must supply at least one segment or
44341section for each library.
44342
2268b414
JK
44343@node Library List Format for SVR4 Targets
44344@section Library List Format for SVR4 Targets
44345@cindex library list format, remote protocol
44346
44347On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44348(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44349shared libraries. Still a special library list provided by this packet is
44350more efficient for the @value{GDBN} remote protocol.
44351
44352The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44353loaded libraries and their SVR4 linker parameters. For each library on SVR4
44354target, the following parameters are reported:
44355
44356@itemize @minus
44357@item
44358@code{name}, the absolute file name from the @code{l_name} field of
44359@code{struct link_map}.
44360@item
44361@code{lm} with address of @code{struct link_map} used for TLS
44362(Thread Local Storage) access.
44363@item
44364@code{l_addr}, the displacement as read from the field @code{l_addr} of
44365@code{struct link_map}. For prelinked libraries this is not an absolute
44366memory address. It is a displacement of absolute memory address against
44367address the file was prelinked to during the library load.
44368@item
44369@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44370@end itemize
44371
44372Additionally the single @code{main-lm} attribute specifies address of
44373@code{struct link_map} used for the main executable. This parameter is used
44374for TLS access and its presence is optional.
44375
44376@value{GDBN} must be linked with the Expat library to support XML
44377SVR4 library lists. @xref{Expat}.
44378
44379A simple memory map, with two loaded libraries (which do not use prelink),
44380looks like this:
44381
44382@smallexample
44383<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44384 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44385 l_ld="0xe4eefc"/>
44386 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44387 l_ld="0x152350"/>
2268b414
JK
44388</library-list-svr>
44389@end smallexample
44390
44391The format of an SVR4 library list is described by this DTD:
44392
44393@smallexample
44394<!-- library-list-svr4: Root element with versioning -->
44395<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44396<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44397<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44398<!ELEMENT library EMPTY>
db1ff28b
JK
44399<!ATTLIST library name CDATA #REQUIRED>
44400<!ATTLIST library lm CDATA #REQUIRED>
44401<!ATTLIST library l_addr CDATA #REQUIRED>
44402<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44403@end smallexample
44404
79a6e687
BW
44405@node Memory Map Format
44406@section Memory Map Format
68437a39
DJ
44407@cindex memory map format
44408
44409To be able to write into flash memory, @value{GDBN} needs to obtain a
44410memory map from the target. This section describes the format of the
44411memory map.
44412
44413The memory map is obtained using the @samp{qXfer:memory-map:read}
44414(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44415lists memory regions.
44416
44417@value{GDBN} must be linked with the Expat library to support XML
44418memory maps. @xref{Expat}.
44419
44420The top-level structure of the document is shown below:
68437a39
DJ
44421
44422@smallexample
44423<?xml version="1.0"?>
44424<!DOCTYPE memory-map
44425 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44426 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44427<memory-map>
44428 region...
44429</memory-map>
44430@end smallexample
44431
44432Each region can be either:
44433
44434@itemize
44435
44436@item
44437A region of RAM starting at @var{addr} and extending for @var{length}
44438bytes from there:
44439
44440@smallexample
44441<memory type="ram" start="@var{addr}" length="@var{length}"/>
44442@end smallexample
44443
44444
44445@item
44446A region of read-only memory:
44447
44448@smallexample
44449<memory type="rom" start="@var{addr}" length="@var{length}"/>
44450@end smallexample
44451
44452
44453@item
44454A region of flash memory, with erasure blocks @var{blocksize}
44455bytes in length:
44456
44457@smallexample
44458<memory type="flash" start="@var{addr}" length="@var{length}">
44459 <property name="blocksize">@var{blocksize}</property>
44460</memory>
44461@end smallexample
44462
44463@end itemize
44464
44465Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44466by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44467packets to write to addresses in such ranges.
44468
44469The formal DTD for memory map format is given below:
44470
44471@smallexample
44472<!-- ................................................... -->
44473<!-- Memory Map XML DTD ................................ -->
44474<!-- File: memory-map.dtd .............................. -->
44475<!-- .................................... .............. -->
44476<!-- memory-map.dtd -->
44477<!-- memory-map: Root element with versioning -->
5f1ca24a 44478<!ELEMENT memory-map (memory)*>
68437a39 44479<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44480<!ELEMENT memory (property)*>
68437a39
DJ
44481<!-- memory: Specifies a memory region,
44482 and its type, or device. -->
5f1ca24a 44483<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44484 start CDATA #REQUIRED
5f1ca24a 44485 length CDATA #REQUIRED>
68437a39
DJ
44486<!-- property: Generic attribute tag -->
44487<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44488<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44489@end smallexample
44490
dc146f7c
VP
44491@node Thread List Format
44492@section Thread List Format
44493@cindex thread list format
44494
44495To efficiently update the list of threads and their attributes,
44496@value{GDBN} issues the @samp{qXfer:threads:read} packet
44497(@pxref{qXfer threads read}) and obtains the XML document with
44498the following structure:
44499
44500@smallexample
44501<?xml version="1.0"?>
44502<threads>
79efa585 44503 <thread id="id" core="0" name="name">
dc146f7c
VP
44504 ... description ...
44505 </thread>
44506</threads>
44507@end smallexample
44508
44509Each @samp{thread} element must have the @samp{id} attribute that
44510identifies the thread (@pxref{thread-id syntax}). The
44511@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44512the thread was last executing on. The @samp{name} attribute, if
44513present, specifies the human-readable name of the thread. The content
44514of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44515auxiliary information. The @samp{handle} attribute, if present,
44516is a hex encoded representation of the thread handle.
44517
dc146f7c 44518
b3b9301e
PA
44519@node Traceframe Info Format
44520@section Traceframe Info Format
44521@cindex traceframe info format
44522
44523To be able to know which objects in the inferior can be examined when
44524inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44525memory ranges, registers and trace state variables that have been
44526collected in a traceframe.
44527
44528This list is obtained using the @samp{qXfer:traceframe-info:read}
44529(@pxref{qXfer traceframe info read}) packet and is an XML document.
44530
44531@value{GDBN} must be linked with the Expat library to support XML
44532traceframe info discovery. @xref{Expat}.
44533
44534The top-level structure of the document is shown below:
44535
44536@smallexample
44537<?xml version="1.0"?>
44538<!DOCTYPE traceframe-info
44539 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44540 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44541<traceframe-info>
44542 block...
44543</traceframe-info>
44544@end smallexample
44545
44546Each traceframe block can be either:
44547
44548@itemize
44549
44550@item
44551A region of collected memory starting at @var{addr} and extending for
44552@var{length} bytes from there:
44553
44554@smallexample
44555<memory start="@var{addr}" length="@var{length}"/>
44556@end smallexample
44557
28a93511
YQ
44558@item
44559A block indicating trace state variable numbered @var{number} has been
44560collected:
44561
44562@smallexample
44563<tvar id="@var{number}"/>
44564@end smallexample
44565
b3b9301e
PA
44566@end itemize
44567
44568The formal DTD for the traceframe info format is given below:
44569
44570@smallexample
28a93511 44571<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44572<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44573
44574<!ELEMENT memory EMPTY>
44575<!ATTLIST memory start CDATA #REQUIRED
44576 length CDATA #REQUIRED>
28a93511
YQ
44577<!ELEMENT tvar>
44578<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44579@end smallexample
44580
2ae8c8e7
MM
44581@node Branch Trace Format
44582@section Branch Trace Format
44583@cindex branch trace format
44584
44585In order to display the branch trace of an inferior thread,
44586@value{GDBN} needs to obtain the list of branches. This list is
44587represented as list of sequential code blocks that are connected via
44588branches. The code in each block has been executed sequentially.
44589
44590This list is obtained using the @samp{qXfer:btrace:read}
44591(@pxref{qXfer btrace read}) packet and is an XML document.
44592
44593@value{GDBN} must be linked with the Expat library to support XML
44594traceframe info discovery. @xref{Expat}.
44595
44596The top-level structure of the document is shown below:
44597
44598@smallexample
44599<?xml version="1.0"?>
44600<!DOCTYPE btrace
44601 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44602 "http://sourceware.org/gdb/gdb-btrace.dtd">
44603<btrace>
44604 block...
44605</btrace>
44606@end smallexample
44607
44608@itemize
44609
44610@item
44611A block of sequentially executed instructions starting at @var{begin}
44612and ending at @var{end}:
44613
44614@smallexample
44615<block begin="@var{begin}" end="@var{end}"/>
44616@end smallexample
44617
44618@end itemize
44619
44620The formal DTD for the branch trace format is given below:
44621
44622@smallexample
b20a6524 44623<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44624<!ATTLIST btrace version CDATA #FIXED "1.0">
44625
44626<!ELEMENT block EMPTY>
44627<!ATTLIST block begin CDATA #REQUIRED
44628 end CDATA #REQUIRED>
b20a6524
MM
44629
44630<!ELEMENT pt (pt-config?, raw?)>
44631
44632<!ELEMENT pt-config (cpu?)>
44633
44634<!ELEMENT cpu EMPTY>
44635<!ATTLIST cpu vendor CDATA #REQUIRED
44636 family CDATA #REQUIRED
44637 model CDATA #REQUIRED
44638 stepping CDATA #REQUIRED>
44639
44640<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44641@end smallexample
44642
f4abbc16
MM
44643@node Branch Trace Configuration Format
44644@section Branch Trace Configuration Format
44645@cindex branch trace configuration format
44646
44647For each inferior thread, @value{GDBN} can obtain the branch trace
44648configuration using the @samp{qXfer:btrace-conf:read}
44649(@pxref{qXfer btrace-conf read}) packet.
44650
44651The configuration describes the branch trace format and configuration
d33501a5
MM
44652settings for that format. The following information is described:
44653
44654@table @code
44655@item bts
44656This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44657@table @code
44658@item size
44659The size of the @acronym{BTS} ring buffer in bytes.
44660@end table
b20a6524 44661@item pt
bc504a31 44662This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44663PT}) format.
44664@table @code
44665@item size
bc504a31 44666The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44667@end table
d33501a5 44668@end table
f4abbc16
MM
44669
44670@value{GDBN} must be linked with the Expat library to support XML
44671branch trace configuration discovery. @xref{Expat}.
44672
44673The formal DTD for the branch trace configuration format is given below:
44674
44675@smallexample
b20a6524 44676<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44677<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44678
44679<!ELEMENT bts EMPTY>
d33501a5 44680<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44681
44682<!ELEMENT pt EMPTY>
44683<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44684@end smallexample
44685
f418dd93
DJ
44686@include agentexpr.texi
44687
23181151
DJ
44688@node Target Descriptions
44689@appendix Target Descriptions
44690@cindex target descriptions
44691
23181151
DJ
44692One of the challenges of using @value{GDBN} to debug embedded systems
44693is that there are so many minor variants of each processor
44694architecture in use. It is common practice for vendors to start with
eb17f351 44695a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44696and then make changes to adapt it to a particular market niche. Some
44697architectures have hundreds of variants, available from dozens of
44698vendors. This leads to a number of problems:
44699
44700@itemize @bullet
44701@item
44702With so many different customized processors, it is difficult for
44703the @value{GDBN} maintainers to keep up with the changes.
44704@item
44705Since individual variants may have short lifetimes or limited
44706audiences, it may not be worthwhile to carry information about every
44707variant in the @value{GDBN} source tree.
44708@item
44709When @value{GDBN} does support the architecture of the embedded system
44710at hand, the task of finding the correct architecture name to give the
44711@command{set architecture} command can be error-prone.
44712@end itemize
44713
44714To address these problems, the @value{GDBN} remote protocol allows a
44715target system to not only identify itself to @value{GDBN}, but to
44716actually describe its own features. This lets @value{GDBN} support
44717processor variants it has never seen before --- to the extent that the
44718descriptions are accurate, and that @value{GDBN} understands them.
44719
9cceb671
DJ
44720@value{GDBN} must be linked with the Expat library to support XML
44721target descriptions. @xref{Expat}.
123dc839 44722
23181151
DJ
44723@menu
44724* Retrieving Descriptions:: How descriptions are fetched from a target.
44725* Target Description Format:: The contents of a target description.
123dc839
DJ
44726* Predefined Target Types:: Standard types available for target
44727 descriptions.
81516450 44728* Enum Target Types:: How to define enum target types.
123dc839 44729* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
44730@end menu
44731
44732@node Retrieving Descriptions
44733@section Retrieving Descriptions
44734
44735Target descriptions can be read from the target automatically, or
44736specified by the user manually. The default behavior is to read the
44737description from the target. @value{GDBN} retrieves it via the remote
44738protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44739qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44740@samp{target.xml}. The contents of the @samp{target.xml} annex are an
44741XML document, of the form described in @ref{Target Description
44742Format}.
44743
44744Alternatively, you can specify a file to read for the target description.
44745If a file is set, the target will not be queried. The commands to
44746specify a file are:
44747
44748@table @code
44749@cindex set tdesc filename
44750@item set tdesc filename @var{path}
44751Read the target description from @var{path}.
44752
44753@cindex unset tdesc filename
44754@item unset tdesc filename
44755Do not read the XML target description from a file. @value{GDBN}
44756will use the description supplied by the current target.
44757
44758@cindex show tdesc filename
44759@item show tdesc filename
44760Show the filename to read for a target description, if any.
44761@end table
44762
44763
44764@node Target Description Format
44765@section Target Description Format
44766@cindex target descriptions, XML format
44767
44768A target description annex is an @uref{http://www.w3.org/XML/, XML}
44769document which complies with the Document Type Definition provided in
44770the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44771means you can use generally available tools like @command{xmllint} to
44772check that your feature descriptions are well-formed and valid.
44773However, to help people unfamiliar with XML write descriptions for
44774their targets, we also describe the grammar here.
44775
123dc839
DJ
44776Target descriptions can identify the architecture of the remote target
44777and (for some architectures) provide information about custom register
08d16641
PA
44778sets. They can also identify the OS ABI of the remote target.
44779@value{GDBN} can use this information to autoconfigure for your
123dc839 44780target, or to warn you if you connect to an unsupported target.
23181151
DJ
44781
44782Here is a simple target description:
44783
123dc839 44784@smallexample
1780a0ed 44785<target version="1.0">
23181151
DJ
44786 <architecture>i386:x86-64</architecture>
44787</target>
123dc839 44788@end smallexample
23181151
DJ
44789
44790@noindent
44791This minimal description only says that the target uses
44792the x86-64 architecture.
44793
123dc839
DJ
44794A target description has the following overall form, with [ ] marking
44795optional elements and @dots{} marking repeatable elements. The elements
44796are explained further below.
23181151 44797
123dc839 44798@smallexample
23181151
DJ
44799<?xml version="1.0"?>
44800<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 44801<target version="1.0">
123dc839 44802 @r{[}@var{architecture}@r{]}
08d16641 44803 @r{[}@var{osabi}@r{]}
e35359c5 44804 @r{[}@var{compatible}@r{]}
123dc839 44805 @r{[}@var{feature}@dots{}@r{]}
23181151 44806</target>
123dc839 44807@end smallexample
23181151
DJ
44808
44809@noindent
44810The description is generally insensitive to whitespace and line
44811breaks, under the usual common-sense rules. The XML version
44812declaration and document type declaration can generally be omitted
44813(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
44814useful for XML validation tools. The @samp{version} attribute for
44815@samp{<target>} may also be omitted, but we recommend
44816including it; if future versions of @value{GDBN} use an incompatible
44817revision of @file{gdb-target.dtd}, they will detect and report
44818the version mismatch.
23181151 44819
108546a0
DJ
44820@subsection Inclusion
44821@cindex target descriptions, inclusion
44822@cindex XInclude
44823@ifnotinfo
44824@cindex <xi:include>
44825@end ifnotinfo
44826
44827It can sometimes be valuable to split a target description up into
44828several different annexes, either for organizational purposes, or to
44829share files between different possible target descriptions. You can
44830divide a description into multiple files by replacing any element of
44831the target description with an inclusion directive of the form:
44832
123dc839 44833@smallexample
108546a0 44834<xi:include href="@var{document}"/>
123dc839 44835@end smallexample
108546a0
DJ
44836
44837@noindent
44838When @value{GDBN} encounters an element of this form, it will retrieve
44839the named XML @var{document}, and replace the inclusion directive with
44840the contents of that document. If the current description was read
44841using @samp{qXfer}, then so will be the included document;
44842@var{document} will be interpreted as the name of an annex. If the
44843current description was read from a file, @value{GDBN} will look for
44844@var{document} as a file in the same directory where it found the
44845original description.
44846
123dc839
DJ
44847@subsection Architecture
44848@cindex <architecture>
44849
44850An @samp{<architecture>} element has this form:
44851
44852@smallexample
44853 <architecture>@var{arch}</architecture>
44854@end smallexample
44855
e35359c5
UW
44856@var{arch} is one of the architectures from the set accepted by
44857@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 44858
08d16641
PA
44859@subsection OS ABI
44860@cindex @code{<osabi>}
44861
44862This optional field was introduced in @value{GDBN} version 7.0.
44863Previous versions of @value{GDBN} ignore it.
44864
44865An @samp{<osabi>} element has this form:
44866
44867@smallexample
44868 <osabi>@var{abi-name}</osabi>
44869@end smallexample
44870
44871@var{abi-name} is an OS ABI name from the same selection accepted by
44872@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44873
e35359c5
UW
44874@subsection Compatible Architecture
44875@cindex @code{<compatible>}
44876
44877This optional field was introduced in @value{GDBN} version 7.0.
44878Previous versions of @value{GDBN} ignore it.
44879
44880A @samp{<compatible>} element has this form:
44881
44882@smallexample
44883 <compatible>@var{arch}</compatible>
44884@end smallexample
44885
44886@var{arch} is one of the architectures from the set accepted by
44887@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44888
44889A @samp{<compatible>} element is used to specify that the target
44890is able to run binaries in some other than the main target architecture
44891given by the @samp{<architecture>} element. For example, on the
44892Cell Broadband Engine, the main architecture is @code{powerpc:common}
44893or @code{powerpc:common64}, but the system is able to run binaries
44894in the @code{spu} architecture as well. The way to describe this
44895capability with @samp{<compatible>} is as follows:
44896
44897@smallexample
44898 <architecture>powerpc:common</architecture>
44899 <compatible>spu</compatible>
44900@end smallexample
44901
123dc839
DJ
44902@subsection Features
44903@cindex <feature>
44904
44905Each @samp{<feature>} describes some logical portion of the target
44906system. Features are currently used to describe available CPU
44907registers and the types of their contents. A @samp{<feature>} element
44908has this form:
44909
44910@smallexample
44911<feature name="@var{name}">
44912 @r{[}@var{type}@dots{}@r{]}
44913 @var{reg}@dots{}
44914</feature>
44915@end smallexample
44916
44917@noindent
44918Each feature's name should be unique within the description. The name
44919of a feature does not matter unless @value{GDBN} has some special
44920knowledge of the contents of that feature; if it does, the feature
44921should have its standard name. @xref{Standard Target Features}.
44922
44923@subsection Types
44924
44925Any register's value is a collection of bits which @value{GDBN} must
44926interpret. The default interpretation is a two's complement integer,
44927but other types can be requested by name in the register description.
44928Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
44929Target Types}), and the description can define additional composite
44930and enum types.
123dc839
DJ
44931
44932Each type element must have an @samp{id} attribute, which gives
44933a unique (within the containing @samp{<feature>}) name to the type.
44934Types must be defined before they are used.
44935
44936@cindex <vector>
44937Some targets offer vector registers, which can be treated as arrays
44938of scalar elements. These types are written as @samp{<vector>} elements,
44939specifying the array element type, @var{type}, and the number of elements,
44940@var{count}:
44941
44942@smallexample
44943<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44944@end smallexample
44945
44946@cindex <union>
44947If a register's value is usefully viewed in multiple ways, define it
44948with a union type containing the useful representations. The
44949@samp{<union>} element contains one or more @samp{<field>} elements,
44950each of which has a @var{name} and a @var{type}:
44951
44952@smallexample
44953<union id="@var{id}">
44954 <field name="@var{name}" type="@var{type}"/>
44955 @dots{}
44956</union>
44957@end smallexample
44958
f5dff777 44959@cindex <struct>
81516450 44960@cindex <flags>
f5dff777 44961If a register's value is composed from several separate values, define
81516450
DE
44962it with either a structure type or a flags type.
44963A flags type may only contain bitfields.
44964A structure type may either contain only bitfields or contain no bitfields.
44965If the value contains only bitfields, its total size in bytes must be
44966specified.
44967
44968Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
44969
44970@smallexample
81516450
DE
44971<struct id="@var{id}">
44972 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
44973 @dots{}
44974</struct>
44975@end smallexample
44976
81516450
DE
44977Both @var{name} and @var{type} values are required.
44978No implicit padding is added.
44979
44980Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
44981
44982@smallexample
81516450
DE
44983<struct id="@var{id}" size="@var{size}">
44984 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44985 @dots{}
44986</struct>
44987@end smallexample
44988
f5dff777
DJ
44989@smallexample
44990<flags id="@var{id}" size="@var{size}">
81516450 44991 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44992 @dots{}
44993</flags>
44994@end smallexample
44995
81516450
DE
44996The @var{name} value is required.
44997Bitfield values may be named with the empty string, @samp{""},
44998in which case the field is ``filler'' and its value is not printed.
44999Not all bits need to be specified, so ``filler'' fields are optional.
45000
ee8da4b8
DE
45001The @var{start} and @var{end} values are required, and @var{type}
45002is optional.
81516450
DE
45003The field's @var{start} must be less than or equal to its @var{end},
45004and zero represents the least significant bit.
81516450 45005
ee8da4b8
DE
45006The default value of @var{type} is @code{bool} for single bit fields,
45007and an unsigned integer otherwise.
81516450
DE
45008
45009Which to choose? Structures or flags?
45010
45011Registers defined with @samp{flags} have these advantages over
45012defining them with @samp{struct}:
45013
45014@itemize @bullet
45015@item
45016Arithmetic may be performed on them as if they were integers.
45017@item
45018They are printed in a more readable fashion.
45019@end itemize
45020
45021Registers defined with @samp{struct} have one advantage over
45022defining them with @samp{flags}:
45023
45024@itemize @bullet
45025@item
45026One can fetch individual fields like in @samp{C}.
45027
45028@smallexample
45029(gdb) print $my_struct_reg.field3
45030$1 = 42
45031@end smallexample
45032
45033@end itemize
45034
123dc839
DJ
45035@subsection Registers
45036@cindex <reg>
45037
45038Each register is represented as an element with this form:
45039
45040@smallexample
45041<reg name="@var{name}"
45042 bitsize="@var{size}"
45043 @r{[}regnum="@var{num}"@r{]}
45044 @r{[}save-restore="@var{save-restore}"@r{]}
45045 @r{[}type="@var{type}"@r{]}
45046 @r{[}group="@var{group}"@r{]}/>
45047@end smallexample
45048
45049@noindent
45050The components are as follows:
45051
45052@table @var
45053
45054@item name
45055The register's name; it must be unique within the target description.
45056
45057@item bitsize
45058The register's size, in bits.
45059
45060@item regnum
45061The register's number. If omitted, a register's number is one greater
45062than that of the previous register (either in the current feature or in
177b42fe 45063a preceding feature); the first register in the target description
123dc839
DJ
45064defaults to zero. This register number is used to read or write
45065the register; e.g.@: it is used in the remote @code{p} and @code{P}
45066packets, and registers appear in the @code{g} and @code{G} packets
45067in order of increasing register number.
45068
45069@item save-restore
45070Whether the register should be preserved across inferior function
45071calls; this must be either @code{yes} or @code{no}. The default is
45072@code{yes}, which is appropriate for most registers except for
45073some system control registers; this is not related to the target's
45074ABI.
45075
45076@item type
697aa1b7 45077The type of the register. It may be a predefined type, a type
123dc839
DJ
45078defined in the current feature, or one of the special types @code{int}
45079and @code{float}. @code{int} is an integer type of the correct size
45080for @var{bitsize}, and @code{float} is a floating point type (in the
45081architecture's normal floating point format) of the correct size for
45082@var{bitsize}. The default is @code{int}.
45083
45084@item group
cef0f868
SH
45085The register group to which this register belongs. It can be one of the
45086standard register groups @code{general}, @code{float}, @code{vector} or an
45087arbitrary string. Group names should be limited to alphanumeric characters.
45088If a group name is made up of multiple words the words may be separated by
45089hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45090@var{group} is specified, @value{GDBN} will not display the register in
45091@code{info registers}.
123dc839
DJ
45092
45093@end table
45094
45095@node Predefined Target Types
45096@section Predefined Target Types
45097@cindex target descriptions, predefined types
45098
45099Type definitions in the self-description can build up composite types
45100from basic building blocks, but can not define fundamental types. Instead,
45101standard identifiers are provided by @value{GDBN} for the fundamental
45102types. The currently supported types are:
45103
45104@table @code
45105
81516450
DE
45106@item bool
45107Boolean type, occupying a single bit.
45108
123dc839
DJ
45109@item int8
45110@itemx int16
d1908f2d 45111@itemx int24
123dc839
DJ
45112@itemx int32
45113@itemx int64
7cc46491 45114@itemx int128
123dc839
DJ
45115Signed integer types holding the specified number of bits.
45116
45117@item uint8
45118@itemx uint16
d1908f2d 45119@itemx uint24
123dc839
DJ
45120@itemx uint32
45121@itemx uint64
7cc46491 45122@itemx uint128
123dc839
DJ
45123Unsigned integer types holding the specified number of bits.
45124
45125@item code_ptr
45126@itemx data_ptr
45127Pointers to unspecified code and data. The program counter and
45128any dedicated return address register may be marked as code
45129pointers; printing a code pointer converts it into a symbolic
45130address. The stack pointer and any dedicated address registers
45131may be marked as data pointers.
45132
6e3bbd1a
PB
45133@item ieee_single
45134Single precision IEEE floating point.
45135
45136@item ieee_double
45137Double precision IEEE floating point.
45138
123dc839
DJ
45139@item arm_fpa_ext
45140The 12-byte extended precision format used by ARM FPA registers.
45141
075b51b7
L
45142@item i387_ext
45143The 10-byte extended precision format used by x87 registers.
45144
45145@item i386_eflags
4514632bit @sc{eflags} register used by x86.
45147
45148@item i386_mxcsr
4514932bit @sc{mxcsr} register used by x86.
45150
123dc839
DJ
45151@end table
45152
81516450
DE
45153@node Enum Target Types
45154@section Enum Target Types
45155@cindex target descriptions, enum types
45156
45157Enum target types are useful in @samp{struct} and @samp{flags}
45158register descriptions. @xref{Target Description Format}.
45159
45160Enum types have a name, size and a list of name/value pairs.
45161
45162@smallexample
45163<enum id="@var{id}" size="@var{size}">
45164 <evalue name="@var{name}" value="@var{value}"/>
45165 @dots{}
45166</enum>
45167@end smallexample
45168
45169Enums must be defined before they are used.
45170
45171@smallexample
45172<enum id="levels_type" size="4">
45173 <evalue name="low" value="0"/>
45174 <evalue name="high" value="1"/>
45175</enum>
45176<flags id="flags_type" size="4">
45177 <field name="X" start="0"/>
45178 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45179</flags>
45180<reg name="flags" bitsize="32" type="flags_type"/>
45181@end smallexample
45182
45183Given that description, a value of 3 for the @samp{flags} register
45184would be printed as:
45185
45186@smallexample
45187(gdb) info register flags
45188flags 0x3 [ X LEVEL=high ]
45189@end smallexample
45190
123dc839
DJ
45191@node Standard Target Features
45192@section Standard Target Features
45193@cindex target descriptions, standard features
45194
45195A target description must contain either no registers or all the
45196target's registers. If the description contains no registers, then
45197@value{GDBN} will assume a default register layout, selected based on
45198the architecture. If the description contains any registers, the
45199default layout will not be used; the standard registers must be
45200described in the target description, in such a way that @value{GDBN}
45201can recognize them.
45202
45203This is accomplished by giving specific names to feature elements
45204which contain standard registers. @value{GDBN} will look for features
45205with those names and verify that they contain the expected registers;
45206if any known feature is missing required registers, or if any required
45207feature is missing, @value{GDBN} will reject the target
45208description. You can add additional registers to any of the
45209standard features --- @value{GDBN} will display them just as if
45210they were added to an unrecognized feature.
45211
45212This section lists the known features and their expected contents.
45213Sample XML documents for these features are included in the
45214@value{GDBN} source tree, in the directory @file{gdb/features}.
45215
45216Names recognized by @value{GDBN} should include the name of the
45217company or organization which selected the name, and the overall
45218architecture to which the feature applies; so e.g.@: the feature
45219containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45220
ff6f572f
DJ
45221The names of registers are not case sensitive for the purpose
45222of recognizing standard features, but @value{GDBN} will only display
45223registers using the capitalization used in the description.
45224
e9c17194 45225@menu
430ed3f0 45226* AArch64 Features::
ad0a504f 45227* ARC Features::
e9c17194 45228* ARM Features::
3bb8d5c3 45229* i386 Features::
164224e9 45230* MicroBlaze Features::
1e26b4f8 45231* MIPS Features::
e9c17194 45232* M68K Features::
a28d8e50 45233* NDS32 Features::
a1217d97 45234* Nios II Features::
a994fec4 45235* OpenRISC 1000 Features::
1e26b4f8 45236* PowerPC Features::
b5ffee31 45237* RISC-V Features::
e3ec872f 45238* RX Features::
4ac33720 45239* S/390 and System z Features::
3f7b46f2 45240* Sparc Features::
224bbe49 45241* TIC6x Features::
e9c17194
VP
45242@end menu
45243
45244
430ed3f0
MS
45245@node AArch64 Features
45246@subsection AArch64 Features
45247@cindex target descriptions, AArch64 features
45248
45249The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45250targets. It should contain registers @samp{x0} through @samp{x30},
45251@samp{sp}, @samp{pc}, and @samp{cpsr}.
45252
45253The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45254it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45255and @samp{fpcr}.
45256
95228a0d
AH
45257The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45258it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45259through @samp{p15}, @samp{ffr} and @samp{vg}.
45260
6dc0ebde
AH
45261The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45262it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45263
ad0a504f
AK
45264@node ARC Features
45265@subsection ARC Features
45266@cindex target descriptions, ARC Features
45267
995d3a19
SV
45268ARC processors are so configurable that even core registers and their numbers
45269are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45270registers, which are important to @value{GDBN}, are not ``core'' registers in
45271ARC. Therefore, there are two features that their presence is mandatory:
45272@samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45273
45274The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45275contain registers:
45276
45277@itemize @minus
45278@item
45279@samp{r0} through @samp{r25} for normal register file targets.
45280@item
45281@samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45282register file targets.
45283@item
45284@samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45285@samp{blink}, @samp{lp_count}, @samp{pcl}.
45286@end itemize
45287
45288In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45289feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45290of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45291The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45292and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45293are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45294@samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45295because of their inaccessibility during user space debugging sessions.
45296
45297Extension core registers @samp{r32} through @samp{r59} are optional and their
45298existence depends on the configuration. When debugging GNU/Linux applications,
45299i.e.@: user space debugging, these core registers are not available.
45300
45301The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. It
45302should at least contain @samp{pc} and @samp{status32} registers.
ad0a504f 45303
e9c17194 45304@node ARM Features
123dc839
DJ
45305@subsection ARM Features
45306@cindex target descriptions, ARM features
45307
9779414d
DJ
45308The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45309ARM targets.
123dc839
DJ
45310It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45311@samp{lr}, @samp{pc}, and @samp{cpsr}.
45312
9779414d
DJ
45313For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45314feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45315registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45316and @samp{xpsr}.
45317
123dc839
DJ
45318The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45319should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45320
ff6f572f
DJ
45321The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45322it should contain at least registers @samp{wR0} through @samp{wR15} and
45323@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45324@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45325
58d6951d
DJ
45326The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45327should contain at least registers @samp{d0} through @samp{d15}. If
45328they are present, @samp{d16} through @samp{d31} should also be included.
45329@value{GDBN} will synthesize the single-precision registers from
45330halves of the double-precision registers.
45331
45332The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45333need to contain registers; it instructs @value{GDBN} to display the
45334VFP double-precision registers as vectors and to synthesize the
45335quad-precision registers from pairs of double-precision registers.
45336If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45337be present and include 32 double-precision registers.
45338
3bb8d5c3
L
45339@node i386 Features
45340@subsection i386 Features
45341@cindex target descriptions, i386 features
45342
45343The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45344targets. It should describe the following registers:
45345
45346@itemize @minus
45347@item
45348@samp{eax} through @samp{edi} plus @samp{eip} for i386
45349@item
45350@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45351@item
45352@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45353@samp{fs}, @samp{gs}
45354@item
45355@samp{st0} through @samp{st7}
45356@item
45357@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45358@samp{foseg}, @samp{fooff} and @samp{fop}
45359@end itemize
45360
45361The register sets may be different, depending on the target.
45362
3a13a53b 45363The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45364describe registers:
45365
45366@itemize @minus
45367@item
45368@samp{xmm0} through @samp{xmm7} for i386
45369@item
45370@samp{xmm0} through @samp{xmm15} for amd64
45371@item
45372@samp{mxcsr}
45373@end itemize
45374
3a13a53b
L
45375The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45376@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45377describe the upper 128 bits of @sc{ymm} registers:
45378
45379@itemize @minus
45380@item
45381@samp{ymm0h} through @samp{ymm7h} for i386
45382@item
45383@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45384@end itemize
45385
bc504a31 45386The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45387Memory Protection Extension (MPX). It should describe the following registers:
45388
45389@itemize @minus
45390@item
45391@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45392@item
45393@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45394@end itemize
45395
3bb8d5c3
L
45396The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45397describe a single register, @samp{orig_eax}.
45398
2735833d
WT
45399The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45400describe two system registers: @samp{fs_base} and @samp{gs_base}.
45401
01f9f808
MS
45402The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45403@samp{org.gnu.gdb.i386.avx} feature. It should
45404describe additional @sc{xmm} registers:
45405
45406@itemize @minus
45407@item
45408@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45409@end itemize
45410
45411It should describe the upper 128 bits of additional @sc{ymm} registers:
45412
45413@itemize @minus
45414@item
45415@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45416@end itemize
45417
45418It should
45419describe the upper 256 bits of @sc{zmm} registers:
45420
45421@itemize @minus
45422@item
45423@samp{zmm0h} through @samp{zmm7h} for i386.
45424@item
45425@samp{zmm0h} through @samp{zmm15h} for amd64.
45426@end itemize
45427
45428It should
45429describe the additional @sc{zmm} registers:
45430
45431@itemize @minus
45432@item
45433@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45434@end itemize
45435
51547df6
MS
45436The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45437describe a single register, @samp{pkru}. It is a 32-bit register
45438valid for i386 and amd64.
45439
164224e9
ME
45440@node MicroBlaze Features
45441@subsection MicroBlaze Features
45442@cindex target descriptions, MicroBlaze features
45443
45444The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45445targets. It should contain registers @samp{r0} through @samp{r31},
45446@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45447@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45448@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45449
45450The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45451If present, it should contain registers @samp{rshr} and @samp{rslr}
45452
1e26b4f8 45453@node MIPS Features
eb17f351
EZ
45454@subsection @acronym{MIPS} Features
45455@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45456
eb17f351 45457The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45458It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45459@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45460on the target.
45461
45462The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45463contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45464registers. They may be 32-bit or 64-bit depending on the target.
45465
45466The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45467it may be optional in a future version of @value{GDBN}. It should
45468contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45469@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45470
1faeff08
MR
45471The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45472contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45473@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45474be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45475
822b6570
DJ
45476The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45477contain a single register, @samp{restart}, which is used by the
45478Linux kernel to control restartable syscalls.
45479
e9c17194
VP
45480@node M68K Features
45481@subsection M68K Features
45482@cindex target descriptions, M68K features
45483
45484@table @code
45485@item @samp{org.gnu.gdb.m68k.core}
45486@itemx @samp{org.gnu.gdb.coldfire.core}
45487@itemx @samp{org.gnu.gdb.fido.core}
45488One of those features must be always present.
249e1128 45489The feature that is present determines which flavor of m68k is
e9c17194
VP
45490used. The feature that is present should contain registers
45491@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45492@samp{sp}, @samp{ps} and @samp{pc}.
45493
45494@item @samp{org.gnu.gdb.coldfire.fp}
45495This feature is optional. If present, it should contain registers
45496@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45497@samp{fpiaddr}.
b7d2fe14
TT
45498
45499Note that, despite the fact that this feature's name says
45500@samp{coldfire}, it is used to describe any floating point registers.
45501The size of the registers must match the main m68k flavor; so, for
45502example, if the primary feature is reported as @samp{coldfire}, then
4550364-bit floating point registers are required.
e9c17194
VP
45504@end table
45505
a28d8e50
YTL
45506@node NDS32 Features
45507@subsection NDS32 Features
45508@cindex target descriptions, NDS32 features
45509
45510The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45511targets. It should contain at least registers @samp{r0} through
45512@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45513and @samp{pc}.
45514
45515The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45516it should contain 64-bit double-precision floating-point registers
45517@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45518@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45519
45520@emph{Note:} The first sixteen 64-bit double-precision floating-point
45521registers are overlapped with the thirty-two 32-bit single-precision
45522floating-point registers. The 32-bit single-precision registers, if
45523not being listed explicitly, will be synthesized from halves of the
45524overlapping 64-bit double-precision registers. Listing 32-bit
45525single-precision registers explicitly is deprecated, and the
45526support to it could be totally removed some day.
45527
a1217d97
SL
45528@node Nios II Features
45529@subsection Nios II Features
45530@cindex target descriptions, Nios II features
45531
45532The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45533targets. It should contain the 32 core registers (@samp{zero},
45534@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45535@samp{pc}, and the 16 control registers (@samp{status} through
45536@samp{mpuacc}).
45537
a994fec4
FJ
45538@node OpenRISC 1000 Features
45539@subsection Openrisc 1000 Features
45540@cindex target descriptions, OpenRISC 1000 features
45541
45542The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45543targets. It should contain the 32 general purpose registers (@samp{r0}
45544through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45545
1e26b4f8 45546@node PowerPC Features
7cc46491
DJ
45547@subsection PowerPC Features
45548@cindex target descriptions, PowerPC features
45549
45550The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45551targets. It should contain registers @samp{r0} through @samp{r31},
45552@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45553@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45554
45555The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45556contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45557
45558The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45559contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45560@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45561through @samp{v31} as aliases for the corresponding @samp{vrX}
45562registers.
7cc46491 45563
677c5bb1 45564The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45565contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45566combine these registers with the floating point registers (@samp{f0}
45567through @samp{f31}) and the altivec registers (@samp{vr0} through
45568@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45569@samp{vs63}, the set of vector-scalar registers for POWER7.
45570Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45571@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45572
7cc46491
DJ
45573The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45574contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45575@samp{spefscr}. SPE targets should provide 32-bit registers in
45576@samp{org.gnu.gdb.power.core} and provide the upper halves in
45577@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45578these to present registers @samp{ev0} through @samp{ev31} to the
45579user.
45580
7ca18ed6
EBM
45581The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45582contain the 64-bit register @samp{ppr}.
45583
45584The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45585contain the 64-bit register @samp{dscr}.
45586
f2cf6173
EBM
45587The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45588contain the 64-bit register @samp{tar}.
45589
232bfb86
EBM
45590The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45591contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4559264-bit wide.
45593
45594The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45595contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45596and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45597server PMU registers provided by @sc{gnu}/Linux.
45598
8d619c01
EBM
45599The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45600contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4560164-bit wide.
45602
45603The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45604contain the checkpointed general-purpose registers @samp{cr0} through
45605@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45606@samp{cctr}. These registers may all be either 32-bit or 64-bit
45607depending on the target. It should also contain the checkpointed
45608registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45609wide.
45610
45611The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45612contain the checkpointed 64-bit floating-point registers @samp{cf0}
45613through @samp{cf31}, as well as the checkpointed 64-bit register
45614@samp{cfpscr}.
45615
45616The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45617should contain the checkpointed altivec registers @samp{cvr0} through
45618@samp{cvr31}, all 128-bit wide. It should also contain the
45619checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45620wide.
45621
45622The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45623contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45624will combine these registers with the checkpointed floating point
45625registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45626altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45627128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45628@samp{cvs63}. Therefore, this feature requires both
45629@samp{org.gnu.gdb.power.htm.altivec} and
45630@samp{org.gnu.gdb.power.htm.fpu}.
45631
45632The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45633contain the 64-bit checkpointed register @samp{cppr}.
45634
45635The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45636contain the 64-bit checkpointed register @samp{cdscr}.
45637
45638The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45639contain the 64-bit checkpointed register @samp{ctar}.
45640
b5ffee31
AB
45641
45642@node RISC-V Features
45643@subsection RISC-V Features
45644@cindex target descriptions, RISC-V Features
45645
45646The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45647targets. It should contain the registers @samp{x0} through
45648@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45649@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45650etc).
45651
45652The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45653should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45654@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45655architectural register names, or the ABI names can be used.
45656
45657The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45658it should contain registers that are not backed by real registers on
45659the target, but are instead virtual, where the register value is
45660derived from other target state. In many ways these are like
45661@value{GDBN}s pseudo-registers, except implemented by the target.
45662Currently the only register expected in this set is the one byte
45663@samp{priv} register that contains the target's privilege level in the
45664least significant two bits.
45665
45666The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45667should contain all of the target's standard CSRs. Standard CSRs are
45668those defined in the RISC-V specification documents. There is some
45669overlap between this feature and the fpu feature; the @samp{fflags},
45670@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45671expectation is that these registers will be in the fpu feature if the
45672target has floating point hardware, but can be moved into the csr
45673feature if the target has the floating point control registers, but no
45674other floating point hardware.
45675
e3ec872f
YS
45676@node RX Features
45677@subsection RX Features
45678@cindex target descriptions, RX Features
45679
45680The @samp{org.gnu.gdb.rx.core} feature is required for RX
45681targets. It should contain the registers @samp{r0} through
45682@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45683@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45684
4ac33720
UW
45685@node S/390 and System z Features
45686@subsection S/390 and System z Features
45687@cindex target descriptions, S/390 features
45688@cindex target descriptions, System z features
45689
45690The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45691System z targets. It should contain the PSW and the 16 general
45692registers. In particular, System z targets should provide the 64-bit
45693registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45694S/390 targets should provide the 32-bit versions of these registers.
45695A System z target that runs in 31-bit addressing mode should provide
4569632-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45697register's upper halves @samp{r0h} through @samp{r15h}, and their
45698lower halves @samp{r0l} through @samp{r15l}.
45699
45700The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45701contain the 64-bit registers @samp{f0} through @samp{f15}, and
45702@samp{fpc}.
45703
45704The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45705contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45706
45707The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45708contain the register @samp{orig_r2}, which is 64-bit wide on System z
45709targets and 32-bit otherwise. In addition, the feature may contain
45710the @samp{last_break} register, whose width depends on the addressing
45711mode, as well as the @samp{system_call} register, which is always
4571232-bit wide.
45713
45714The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45715contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45716@samp{atia}, and @samp{tr0} through @samp{tr15}.
45717
446899e4
AA
45718The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4571964-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45720combined by @value{GDBN} with the floating point registers @samp{f0}
45721through @samp{f15} to present the 128-bit wide vector registers
45722@samp{v0} through @samp{v15}. In addition, this feature should
45723contain the 128-bit wide vector registers @samp{v16} through
45724@samp{v31}.
45725
289e23aa
AA
45726The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45727the 64-bit wide guarded-storage-control registers @samp{gsd},
45728@samp{gssm}, and @samp{gsepla}.
45729
45730The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45731the 64-bit wide guarded-storage broadcast control registers
45732@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45733
3f7b46f2
IR
45734@node Sparc Features
45735@subsection Sparc Features
45736@cindex target descriptions, sparc32 features
45737@cindex target descriptions, sparc64 features
45738The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45739targets. It should describe the following registers:
45740
45741@itemize @minus
45742@item
45743@samp{g0} through @samp{g7}
45744@item
45745@samp{o0} through @samp{o7}
45746@item
45747@samp{l0} through @samp{l7}
45748@item
45749@samp{i0} through @samp{i7}
45750@end itemize
45751
45752They may be 32-bit or 64-bit depending on the target.
45753
45754Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45755targets. It should describe the following registers:
45756
45757@itemize @minus
45758@item
45759@samp{f0} through @samp{f31}
45760@item
45761@samp{f32} through @samp{f62} for sparc64
45762@end itemize
45763
45764The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45765targets. It should describe the following registers:
45766
45767@itemize @minus
45768@item
45769@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45770@samp{fsr}, and @samp{csr} for sparc32
45771@item
45772@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45773for sparc64
45774@end itemize
45775
224bbe49
YQ
45776@node TIC6x Features
45777@subsection TMS320C6x Features
45778@cindex target descriptions, TIC6x features
45779@cindex target descriptions, TMS320C6x features
45780The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45781targets. It should contain registers @samp{A0} through @samp{A15},
45782registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45783
45784The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45785contain registers @samp{A16} through @samp{A31} and @samp{B16}
45786through @samp{B31}.
45787
45788The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45789contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45790
07e059b5
VP
45791@node Operating System Information
45792@appendix Operating System Information
45793@cindex operating system information
45794
45795@menu
45796* Process list::
45797@end menu
45798
45799Users of @value{GDBN} often wish to obtain information about the state of
45800the operating system running on the target---for example the list of
45801processes, or the list of open files. This section describes the
45802mechanism that makes it possible. This mechanism is similar to the
45803target features mechanism (@pxref{Target Descriptions}), but focuses
45804on a different aspect of target.
45805
6b92c0d3 45806Operating system information is retrieved from the target via the
07e059b5
VP
45807remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45808read}). The object name in the request should be @samp{osdata}, and
45809the @var{annex} identifies the data to be fetched.
45810
45811@node Process list
45812@appendixsection Process list
45813@cindex operating system information, process list
45814
45815When requesting the process list, the @var{annex} field in the
45816@samp{qXfer} request should be @samp{processes}. The returned data is
45817an XML document. The formal syntax of this document is defined in
45818@file{gdb/features/osdata.dtd}.
45819
45820An example document is:
45821
45822@smallexample
45823<?xml version="1.0"?>
45824<!DOCTYPE target SYSTEM "osdata.dtd">
45825<osdata type="processes">
45826 <item>
45827 <column name="pid">1</column>
45828 <column name="user">root</column>
45829 <column name="command">/sbin/init</column>
dc146f7c 45830 <column name="cores">1,2,3</column>
07e059b5
VP
45831 </item>
45832</osdata>
45833@end smallexample
45834
45835Each item should include a column whose name is @samp{pid}. The value
45836of that column should identify the process on the target. The
45837@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
45838displayed by @value{GDBN}. The @samp{cores} column, if present,
45839should contain a comma-separated list of cores that this process
45840is running on. Target may provide additional columns,
07e059b5
VP
45841which @value{GDBN} currently ignores.
45842
05c8c3f5
TT
45843@node Trace File Format
45844@appendix Trace File Format
45845@cindex trace file format
45846
45847The trace file comes in three parts: a header, a textual description
45848section, and a trace frame section with binary data.
45849
45850The header has the form @code{\x7fTRACE0\n}. The first byte is
45851@code{0x7f} so as to indicate that the file contains binary data,
45852while the @code{0} is a version number that may have different values
45853in the future.
45854
45855The description section consists of multiple lines of @sc{ascii} text
45856separated by newline characters (@code{0xa}). The lines may include a
45857variety of optional descriptive or context-setting information, such
45858as tracepoint definitions or register set size. @value{GDBN} will
45859ignore any line that it does not recognize. An empty line marks the end
45860of this section.
45861
0748bf3e
MK
45862@table @code
45863@item R @var{size}
45864Specifies the size of a register block in bytes. This is equal to the
45865size of a @code{g} packet payload in the remote protocol. @var{size}
45866is an ascii decimal number. There should be only one such line in
45867a single trace file.
45868
45869@item status @var{status}
45870Trace status. @var{status} has the same format as a @code{qTStatus}
45871remote packet reply. There should be only one such line in a single trace
45872file.
45873
45874@item tp @var{payload}
45875Tracepoint definition. The @var{payload} has the same format as
45876@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45877may take multiple lines of definition, corresponding to the multiple
45878reply packets.
45879
45880@item tsv @var{payload}
45881Trace state variable definition. The @var{payload} has the same format as
45882@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45883may take multiple lines of definition, corresponding to the multiple
45884reply packets.
45885
45886@item tdesc @var{payload}
45887Target description in XML format. The @var{payload} is a single line of
45888the XML file. All such lines should be concatenated together to get
45889the original XML file. This file is in the same format as @code{qXfer}
45890@code{features} payload, and corresponds to the main @code{target.xml}
45891file. Includes are not allowed.
45892
45893@end table
05c8c3f5
TT
45894
45895The trace frame section consists of a number of consecutive frames.
45896Each frame begins with a two-byte tracepoint number, followed by a
45897four-byte size giving the amount of data in the frame. The data in
45898the frame consists of a number of blocks, each introduced by a
45899character indicating its type (at least register, memory, and trace
45900state variable). The data in this section is raw binary, not a
45901hexadecimal or other encoding; its endianness matches the target's
45902endianness.
45903
45904@c FIXME bi-arch may require endianness/arch info in description section
45905
45906@table @code
45907@item R @var{bytes}
45908Register block. The number and ordering of bytes matches that of a
45909@code{g} packet in the remote protocol. Note that these are the
e909d859 45910actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
45911
45912@item M @var{address} @var{length} @var{bytes}...
45913Memory block. This is a contiguous block of memory, at the 8-byte
45914address @var{address}, with a 2-byte length @var{length}, followed by
45915@var{length} bytes.
45916
45917@item V @var{number} @var{value}
45918Trace state variable block. This records the 8-byte signed value
45919@var{value} of trace state variable numbered @var{number}.
45920
45921@end table
45922
45923Future enhancements of the trace file format may include additional types
45924of blocks.
45925
90476074
TT
45926@node Index Section Format
45927@appendix @code{.gdb_index} section format
45928@cindex .gdb_index section format
45929@cindex index section format
45930
45931This section documents the index section that is created by @code{save
45932gdb-index} (@pxref{Index Files}). The index section is
45933DWARF-specific; some knowledge of DWARF is assumed in this
45934description.
45935
45936The mapped index file format is designed to be directly
45937@code{mmap}able on any architecture. In most cases, a datum is
45938represented using a little-endian 32-bit integer value, called an
45939@code{offset_type}. Big endian machines must byte-swap the values
45940before using them. Exceptions to this rule are noted. The data is
45941laid out such that alignment is always respected.
45942
45943A mapped index consists of several areas, laid out in order.
45944
45945@enumerate
45946@item
45947The file header. This is a sequence of values, of @code{offset_type}
45948unless otherwise noted:
45949
45950@enumerate
45951@item
796a7ff8 45952The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 45953Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
45954Version 6 includes symbols for inlined functions, whereas versions 4
45955and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
45956symbol table. Version 8 specifies that symbols from DWARF type units
45957(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45958compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45959
45960@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 45961by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
45962GDB has a workaround for potentially broken version 7 indices so it is
45963currently not flagged as deprecated.
90476074
TT
45964
45965@item
45966The offset, from the start of the file, of the CU list.
45967
45968@item
45969The offset, from the start of the file, of the types CU list. Note
45970that this area can be empty, in which case this offset will be equal
45971to the next offset.
45972
45973@item
45974The offset, from the start of the file, of the address area.
45975
45976@item
45977The offset, from the start of the file, of the symbol table.
45978
45979@item
45980The offset, from the start of the file, of the constant pool.
45981@end enumerate
45982
45983@item
45984The CU list. This is a sequence of pairs of 64-bit little-endian
45985values, sorted by the CU offset. The first element in each pair is
45986the offset of a CU in the @code{.debug_info} section. The second
45987element in each pair is the length of that CU. References to a CU
45988elsewhere in the map are done using a CU index, which is just the
459890-based index into this table. Note that if there are type CUs, then
45990conceptually CUs and type CUs form a single list for the purposes of
45991CU indices.
45992
45993@item
45994The types CU list. This is a sequence of triplets of 64-bit
45995little-endian values. In a triplet, the first value is the CU offset,
45996the second value is the type offset in the CU, and the third value is
45997the type signature. The types CU list is not sorted.
45998
45999@item
46000The address area. The address area consists of a sequence of address
46001entries. Each address entry has three elements:
46002
46003@enumerate
46004@item
46005The low address. This is a 64-bit little-endian value.
46006
46007@item
46008The high address. This is a 64-bit little-endian value. Like
46009@code{DW_AT_high_pc}, the value is one byte beyond the end.
46010
46011@item
46012The CU index. This is an @code{offset_type} value.
46013@end enumerate
46014
46015@item
46016The symbol table. This is an open-addressed hash table. The size of
46017the hash table is always a power of 2.
46018
46019Each slot in the hash table consists of a pair of @code{offset_type}
46020values. The first value is the offset of the symbol's name in the
46021constant pool. The second value is the offset of the CU vector in the
46022constant pool.
46023
46024If both values are 0, then this slot in the hash table is empty. This
46025is ok because while 0 is a valid constant pool index, it cannot be a
46026valid index for both a string and a CU vector.
46027
46028The hash value for a table entry is computed by applying an
46029iterative hash function to the symbol's name. Starting with an
46030initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
46031the string is incorporated into the hash using the formula depending on the
46032index version:
46033
46034@table @asis
46035@item Version 4
46036The formula is @code{r = r * 67 + c - 113}.
46037
156942c7 46038@item Versions 5 to 7
559a7a62
JK
46039The formula is @code{r = r * 67 + tolower (c) - 113}.
46040@end table
46041
46042The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
46043
46044The step size used in the hash table is computed via
46045@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46046value, and @samp{size} is the size of the hash table. The step size
46047is used to find the next candidate slot when handling a hash
46048collision.
46049
46050The names of C@t{++} symbols in the hash table are canonicalized. We
46051don't currently have a simple description of the canonicalization
46052algorithm; if you intend to create new index sections, you must read
46053the code.
46054
46055@item
46056The constant pool. This is simply a bunch of bytes. It is organized
46057so that alignment is correct: CU vectors are stored first, followed by
46058strings.
46059
46060A CU vector in the constant pool is a sequence of @code{offset_type}
46061values. The first value is the number of CU indices in the vector.
156942c7
DE
46062Each subsequent value is the index and symbol attributes of a CU in
46063the CU list. This element in the hash table is used to indicate which
46064CUs define the symbol and how the symbol is used.
46065See below for the format of each CU index+attributes entry.
90476074
TT
46066
46067A string in the constant pool is zero-terminated.
46068@end enumerate
46069
156942c7
DE
46070Attributes were added to CU index values in @code{.gdb_index} version 7.
46071If a symbol has multiple uses within a CU then there is one
46072CU index+attributes value for each use.
46073
46074The format of each CU index+attributes entry is as follows
46075(bit 0 = LSB):
46076
46077@table @asis
46078
46079@item Bits 0-23
46080This is the index of the CU in the CU list.
46081@item Bits 24-27
46082These bits are reserved for future purposes and must be zero.
46083@item Bits 28-30
46084The kind of the symbol in the CU.
46085
46086@table @asis
46087@item 0
46088This value is reserved and should not be used.
46089By reserving zero the full @code{offset_type} value is backwards compatible
46090with previous versions of the index.
46091@item 1
46092The symbol is a type.
46093@item 2
46094The symbol is a variable or an enum value.
46095@item 3
46096The symbol is a function.
46097@item 4
46098Any other kind of symbol.
46099@item 5,6,7
46100These values are reserved.
46101@end table
46102
46103@item Bit 31
46104This bit is zero if the value is global and one if it is static.
46105
46106The determination of whether a symbol is global or static is complicated.
46107The authorative reference is the file @file{dwarf2read.c} in
46108@value{GDBN} sources.
46109
46110@end table
46111
46112This pseudo-code describes the computation of a symbol's kind and
46113global/static attributes in the index.
46114
46115@smallexample
46116is_external = get_attribute (die, DW_AT_external);
46117language = get_attribute (cu_die, DW_AT_language);
46118switch (die->tag)
46119 @{
46120 case DW_TAG_typedef:
46121 case DW_TAG_base_type:
46122 case DW_TAG_subrange_type:
46123 kind = TYPE;
46124 is_static = 1;
46125 break;
46126 case DW_TAG_enumerator:
46127 kind = VARIABLE;
9c37b5ae 46128 is_static = language != CPLUS;
156942c7
DE
46129 break;
46130 case DW_TAG_subprogram:
46131 kind = FUNCTION;
46132 is_static = ! (is_external || language == ADA);
46133 break;
46134 case DW_TAG_constant:
46135 kind = VARIABLE;
46136 is_static = ! is_external;
46137 break;
46138 case DW_TAG_variable:
46139 kind = VARIABLE;
46140 is_static = ! is_external;
46141 break;
46142 case DW_TAG_namespace:
46143 kind = TYPE;
46144 is_static = 0;
46145 break;
46146 case DW_TAG_class_type:
46147 case DW_TAG_interface_type:
46148 case DW_TAG_structure_type:
46149 case DW_TAG_union_type:
46150 case DW_TAG_enumeration_type:
46151 kind = TYPE;
9c37b5ae 46152 is_static = language != CPLUS;
156942c7
DE
46153 break;
46154 default:
46155 assert (0);
46156 @}
46157@end smallexample
46158
43662968
JK
46159@node Man Pages
46160@appendix Manual pages
46161@cindex Man pages
46162
46163@menu
46164* gdb man:: The GNU Debugger man page
46165* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 46166* gcore man:: Generate a core file of a running program
43662968 46167* gdbinit man:: gdbinit scripts
ba643918 46168* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
46169@end menu
46170
46171@node gdb man
46172@heading gdb man
46173
46174@c man title gdb The GNU Debugger
46175
46176@c man begin SYNOPSIS gdb
46177gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46178[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46179[@option{-b}@w{ }@var{bps}]
46180 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46181[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
46182[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46183 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46184[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
46185@c man end
46186
46187@c man begin DESCRIPTION gdb
46188The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46189going on ``inside'' another program while it executes -- or what another
46190program was doing at the moment it crashed.
46191
46192@value{GDBN} can do four main kinds of things (plus other things in support of
46193these) to help you catch bugs in the act:
46194
46195@itemize @bullet
46196@item
46197Start your program, specifying anything that might affect its behavior.
46198
46199@item
46200Make your program stop on specified conditions.
46201
46202@item
46203Examine what has happened, when your program has stopped.
46204
46205@item
46206Change things in your program, so you can experiment with correcting the
46207effects of one bug and go on to learn about another.
46208@end itemize
46209
906ccdf0
JK
46210You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46211Modula-2.
43662968
JK
46212
46213@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46214commands from the terminal until you tell it to exit with the @value{GDBN}
46215command @code{quit}. You can get online help from @value{GDBN} itself
46216by using the command @code{help}.
46217
46218You can run @code{gdb} with no arguments or options; but the most
46219usual way to start @value{GDBN} is with one argument or two, specifying an
46220executable program as the argument:
46221
46222@smallexample
46223gdb program
46224@end smallexample
46225
46226You can also start with both an executable program and a core file specified:
46227
46228@smallexample
46229gdb program core
46230@end smallexample
46231
4ed4690f
SM
46232You can, instead, specify a process ID as a second argument or use option
46233@code{-p}, if you want to debug a running process:
43662968
JK
46234
46235@smallexample
46236gdb program 1234
906ccdf0 46237gdb -p 1234
43662968
JK
46238@end smallexample
46239
46240@noindent
4ed4690f
SM
46241would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46242can omit the @var{program} filename.
43662968
JK
46243
46244Here are some of the most frequently needed @value{GDBN} commands:
46245
46246@c pod2man highlights the right hand side of the @item lines.
46247@table @env
224f10c1 46248@item break [@var{file}:]@var{function}
43662968
JK
46249Set a breakpoint at @var{function} (in @var{file}).
46250
46251@item run [@var{arglist}]
46252Start your program (with @var{arglist}, if specified).
46253
46254@item bt
46255Backtrace: display the program stack.
46256
46257@item print @var{expr}
46258Display the value of an expression.
46259
46260@item c
46261Continue running your program (after stopping, e.g. at a breakpoint).
46262
46263@item next
46264Execute next program line (after stopping); step @emph{over} any
46265function calls in the line.
46266
46267@item edit [@var{file}:]@var{function}
46268look at the program line where it is presently stopped.
46269
46270@item list [@var{file}:]@var{function}
46271type the text of the program in the vicinity of where it is presently stopped.
46272
46273@item step
46274Execute next program line (after stopping); step @emph{into} any
46275function calls in the line.
46276
46277@item help [@var{name}]
46278Show information about @value{GDBN} command @var{name}, or general information
46279about using @value{GDBN}.
46280
46281@item quit
46282Exit from @value{GDBN}.
46283@end table
46284
46285@ifset man
46286For full details on @value{GDBN},
46287see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46288by Richard M. Stallman and Roland H. Pesch. The same text is available online
46289as the @code{gdb} entry in the @code{info} program.
46290@end ifset
46291@c man end
46292
46293@c man begin OPTIONS gdb
46294Any arguments other than options specify an executable
46295file and core file (or process ID); that is, the first argument
46296encountered with no
46297associated option flag is equivalent to a @option{-se} option, and the second,
46298if any, is equivalent to a @option{-c} option if it's the name of a file.
46299Many options have
46300both long and short forms; both are shown here. The long forms are also
46301recognized if you truncate them, so long as enough of the option is
46302present to be unambiguous. (If you prefer, you can flag option
46303arguments with @option{+} rather than @option{-}, though we illustrate the
46304more usual convention.)
46305
46306All the options and command line arguments you give are processed
46307in sequential order. The order makes a difference when the @option{-x}
46308option is used.
46309
46310@table @env
46311@item -help
46312@itemx -h
46313List all options, with brief explanations.
46314
46315@item -symbols=@var{file}
46316@itemx -s @var{file}
46317Read symbol table from file @var{file}.
46318
46319@item -write
46320Enable writing into executable and core files.
46321
46322@item -exec=@var{file}
46323@itemx -e @var{file}
46324Use file @var{file} as the executable file to execute when
46325appropriate, and for examining pure data in conjunction with a core
46326dump.
46327
46328@item -se=@var{file}
46329Read symbol table from file @var{file} and use it as the executable
46330file.
46331
46332@item -core=@var{file}
46333@itemx -c @var{file}
46334Use file @var{file} as a core dump to examine.
46335
46336@item -command=@var{file}
46337@itemx -x @var{file}
46338Execute @value{GDBN} commands from file @var{file}.
46339
46340@item -ex @var{command}
46341Execute given @value{GDBN} @var{command}.
46342
46343@item -directory=@var{directory}
46344@itemx -d @var{directory}
46345Add @var{directory} to the path to search for source files.
46346
46347@item -nh
46348Do not execute commands from @file{~/.gdbinit}.
46349
46350@item -nx
46351@itemx -n
46352Do not execute commands from any @file{.gdbinit} initialization files.
46353
46354@item -quiet
46355@itemx -q
46356``Quiet''. Do not print the introductory and copyright messages. These
46357messages are also suppressed in batch mode.
46358
46359@item -batch
46360Run in batch mode. Exit with status @code{0} after processing all the command
46361files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46362Exit with nonzero status if an error occurs in executing the @value{GDBN}
46363commands in the command files.
46364
46365Batch mode may be useful for running @value{GDBN} as a filter, for example to
46366download and run a program on another computer; in order to make this
46367more useful, the message
46368
46369@smallexample
46370Program exited normally.
46371@end smallexample
46372
46373@noindent
46374(which is ordinarily issued whenever a program running under @value{GDBN} control
46375terminates) is not issued when running in batch mode.
46376
46377@item -cd=@var{directory}
46378Run @value{GDBN} using @var{directory} as its working directory,
46379instead of the current directory.
46380
46381@item -fullname
46382@itemx -f
46383Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46384@value{GDBN} to output the full file name and line number in a standard,
46385recognizable fashion each time a stack frame is displayed (which
46386includes each time the program stops). This recognizable format looks
46387like two @samp{\032} characters, followed by the file name, line number
46388and character position separated by colons, and a newline. The
46389Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46390characters as a signal to display the source code for the frame.
46391
46392@item -b @var{bps}
46393Set the line speed (baud rate or bits per second) of any serial
46394interface used by @value{GDBN} for remote debugging.
46395
46396@item -tty=@var{device}
46397Run using @var{device} for your program's standard input and output.
46398@end table
46399@c man end
46400
46401@c man begin SEEALSO gdb
46402@ifset man
46403The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46404If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46405documentation are properly installed at your site, the command
46406
46407@smallexample
46408info gdb
46409@end smallexample
46410
46411@noindent
46412should give you access to the complete manual.
46413
46414@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46415Richard M. Stallman and Roland H. Pesch, July 1991.
46416@end ifset
46417@c man end
46418
46419@node gdbserver man
46420@heading gdbserver man
46421
46422@c man title gdbserver Remote Server for the GNU Debugger
46423@format
46424@c man begin SYNOPSIS gdbserver
5b8b6385 46425gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46426
5b8b6385
JK
46427gdbserver --attach @var{comm} @var{pid}
46428
46429gdbserver --multi @var{comm}
43662968
JK
46430@c man end
46431@end format
46432
46433@c man begin DESCRIPTION gdbserver
46434@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46435than the one which is running the program being debugged.
46436
46437@ifclear man
46438@subheading Usage (server (target) side)
46439@end ifclear
46440@ifset man
46441Usage (server (target) side):
46442@end ifset
46443
46444First, you need to have a copy of the program you want to debug put onto
46445the target system. The program can be stripped to save space if needed, as
46446@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46447the @value{GDBN} running on the host system.
46448
46449To use the server, you log on to the target system, and run the @command{gdbserver}
46450program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46451your program, and (c) its arguments. The general syntax is:
46452
46453@smallexample
46454target> gdbserver @var{comm} @var{program} [@var{args} ...]
46455@end smallexample
46456
46457For example, using a serial port, you might say:
46458
46459@smallexample
46460@ifset man
46461@c @file would wrap it as F</dev/com1>.
46462target> gdbserver /dev/com1 emacs foo.txt
46463@end ifset
46464@ifclear man
46465target> gdbserver @file{/dev/com1} emacs foo.txt
46466@end ifclear
46467@end smallexample
46468
46469This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46470to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46471waits patiently for the host @value{GDBN} to communicate with it.
46472
46473To use a TCP connection, you could say:
46474
46475@smallexample
46476target> gdbserver host:2345 emacs foo.txt
46477@end smallexample
46478
46479This says pretty much the same thing as the last example, except that we are
46480going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46481that we are expecting to see a TCP connection from @code{host} to local TCP port
464822345. (Currently, the @code{host} part is ignored.) You can choose any number you
46483want for the port number as long as it does not conflict with any existing TCP
46484ports on the target system. This same port number must be used in the host
46485@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46486you chose a port number that conflicts with another service, @command{gdbserver} will
46487print an error message and exit.
46488
5b8b6385 46489@command{gdbserver} can also attach to running programs.
43662968
JK
46490This is accomplished via the @option{--attach} argument. The syntax is:
46491
46492@smallexample
5b8b6385 46493target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46494@end smallexample
46495
46496@var{pid} is the process ID of a currently running process. It isn't
46497necessary to point @command{gdbserver} at a binary for the running process.
46498
5b8b6385
JK
46499To start @code{gdbserver} without supplying an initial command to run
46500or process ID to attach, use the @option{--multi} command line option.
46501In such case you should connect using @kbd{target extended-remote} to start
46502the program you want to debug.
46503
46504@smallexample
46505target> gdbserver --multi @var{comm}
46506@end smallexample
46507
43662968
JK
46508@ifclear man
46509@subheading Usage (host side)
46510@end ifclear
46511@ifset man
46512Usage (host side):
46513@end ifset
46514
46515You need an unstripped copy of the target program on your host system, since
1a088a2e 46516@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46517would, with the target program as the first argument. (You may need to use the
46518@option{--baud} option if the serial line is running at anything except 9600 baud.)
46519That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46520new command you need to know about is @code{target remote}
46521(or @code{target extended-remote}). Its argument is either
43662968
JK
46522a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46523descriptor. For example:
46524
46525@smallexample
46526@ifset man
46527@c @file would wrap it as F</dev/ttyb>.
46528(gdb) target remote /dev/ttyb
46529@end ifset
46530@ifclear man
46531(gdb) target remote @file{/dev/ttyb}
46532@end ifclear
46533@end smallexample
46534
46535@noindent
46536communicates with the server via serial line @file{/dev/ttyb}, and:
46537
46538@smallexample
46539(gdb) target remote the-target:2345
46540@end smallexample
46541
46542@noindent
46543communicates via a TCP connection to port 2345 on host `the-target', where
46544you previously started up @command{gdbserver} with the same port number. Note that for
46545TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46546command, otherwise you may get an error that looks something like
46547`Connection refused'.
5b8b6385
JK
46548
46549@command{gdbserver} can also debug multiple inferiors at once,
46550described in
46551@ifset man
65c574f6
PA
46552the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46553-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46554@end ifset
46555@ifclear man
65c574f6 46556@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46557@end ifclear
46558In such case use the @code{extended-remote} @value{GDBN} command variant:
46559
46560@smallexample
46561(gdb) target extended-remote the-target:2345
46562@end smallexample
46563
46564The @command{gdbserver} option @option{--multi} may or may not be used in such
46565case.
43662968
JK
46566@c man end
46567
46568@c man begin OPTIONS gdbserver
5b8b6385
JK
46569There are three different modes for invoking @command{gdbserver}:
46570
46571@itemize @bullet
46572
46573@item
46574Debug a specific program specified by its program name:
46575
46576@smallexample
46577gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46578@end smallexample
46579
46580The @var{comm} parameter specifies how should the server communicate
46581with @value{GDBN}; it is either a device name (to use a serial line),
46582a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46583stdin/stdout of @code{gdbserver}. Specify the name of the program to
46584debug in @var{prog}. Any remaining arguments will be passed to the
46585program verbatim. When the program exits, @value{GDBN} will close the
46586connection, and @code{gdbserver} will exit.
46587
46588@item
46589Debug a specific program by specifying the process ID of a running
46590program:
46591
46592@smallexample
46593gdbserver --attach @var{comm} @var{pid}
46594@end smallexample
46595
46596The @var{comm} parameter is as described above. Supply the process ID
46597of a running program in @var{pid}; @value{GDBN} will do everything
46598else. Like with the previous mode, when the process @var{pid} exits,
46599@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46600
46601@item
46602Multi-process mode -- debug more than one program/process:
46603
46604@smallexample
46605gdbserver --multi @var{comm}
46606@end smallexample
46607
46608In this mode, @value{GDBN} can instruct @command{gdbserver} which
46609command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46610close the connection when a process being debugged exits, so you can
46611debug several processes in the same session.
46612@end itemize
46613
46614In each of the modes you may specify these options:
46615
46616@table @env
46617
46618@item --help
46619List all options, with brief explanations.
46620
46621@item --version
46622This option causes @command{gdbserver} to print its version number and exit.
46623
46624@item --attach
46625@command{gdbserver} will attach to a running program. The syntax is:
46626
46627@smallexample
46628target> gdbserver --attach @var{comm} @var{pid}
46629@end smallexample
46630
46631@var{pid} is the process ID of a currently running process. It isn't
46632necessary to point @command{gdbserver} at a binary for the running process.
46633
46634@item --multi
46635To start @code{gdbserver} without supplying an initial command to run
46636or process ID to attach, use this command line option.
46637Then you can connect using @kbd{target extended-remote} and start
46638the program you want to debug. The syntax is:
46639
46640@smallexample
46641target> gdbserver --multi @var{comm}
46642@end smallexample
46643
46644@item --debug
46645Instruct @code{gdbserver} to display extra status information about the debugging
46646process.
46647This option is intended for @code{gdbserver} development and for bug reports to
46648the developers.
46649
46650@item --remote-debug
46651Instruct @code{gdbserver} to display remote protocol debug output.
46652This option is intended for @code{gdbserver} development and for bug reports to
46653the developers.
46654
aeb2e706
AH
46655@item --debug-file=@var{filename}
46656Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46657This option is intended for @code{gdbserver} development and for bug reports to
46658the developers.
46659
87ce2a04
DE
46660@item --debug-format=option1@r{[},option2,...@r{]}
46661Instruct @code{gdbserver} to include extra information in each line
46662of debugging output.
46663@xref{Other Command-Line Arguments for gdbserver}.
46664
5b8b6385
JK
46665@item --wrapper
46666Specify a wrapper to launch programs
46667for debugging. The option should be followed by the name of the
46668wrapper, then any command-line arguments to pass to the wrapper, then
46669@kbd{--} indicating the end of the wrapper arguments.
46670
46671@item --once
46672By default, @command{gdbserver} keeps the listening TCP port open, so that
46673additional connections are possible. However, if you start @code{gdbserver}
46674with the @option{--once} option, it will stop listening for any further
46675connection attempts after connecting to the first @value{GDBN} session.
46676
46677@c --disable-packet is not documented for users.
46678
46679@c --disable-randomization and --no-disable-randomization are superseded by
46680@c QDisableRandomization.
46681
46682@end table
43662968
JK
46683@c man end
46684
46685@c man begin SEEALSO gdbserver
46686@ifset man
46687The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46688If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46689documentation are properly installed at your site, the command
46690
46691@smallexample
46692info gdb
46693@end smallexample
46694
46695should give you access to the complete manual.
46696
46697@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46698Richard M. Stallman and Roland H. Pesch, July 1991.
46699@end ifset
46700@c man end
46701
b292c783
JK
46702@node gcore man
46703@heading gcore
46704
46705@c man title gcore Generate a core file of a running program
46706
46707@format
46708@c man begin SYNOPSIS gcore
129eb0f1 46709gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46710@c man end
46711@end format
46712
46713@c man begin DESCRIPTION gcore
129eb0f1
SDJ
46714Generate core dumps of one or more running programs with process IDs
46715@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46716is equivalent to one produced by the kernel when the process crashes
46717(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46718limit). However, unlike after a crash, after @command{gcore} finishes
46719its job the program remains running without any change.
b292c783
JK
46720@c man end
46721
46722@c man begin OPTIONS gcore
46723@table @env
c179febe
SL
46724@item -a
46725Dump all memory mappings. The actual effect of this option depends on
46726the Operating System. On @sc{gnu}/Linux, it will disable
46727@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46728enable @code{dump-excluded-mappings} (@pxref{set
46729dump-excluded-mappings}).
46730
129eb0f1
SDJ
46731@item -o @var{prefix}
46732The optional argument @var{prefix} specifies the prefix to be used
46733when composing the file names of the core dumps. The file name is
46734composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46735process ID of the running program being analyzed by @command{gcore}.
46736If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
46737@end table
46738@c man end
46739
46740@c man begin SEEALSO gcore
46741@ifset man
46742The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46743If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46744documentation are properly installed at your site, the command
46745
46746@smallexample
46747info gdb
46748@end smallexample
46749
46750@noindent
46751should give you access to the complete manual.
46752
46753@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46754Richard M. Stallman and Roland H. Pesch, July 1991.
46755@end ifset
46756@c man end
46757
43662968
JK
46758@node gdbinit man
46759@heading gdbinit
46760
46761@c man title gdbinit GDB initialization scripts
46762
46763@format
46764@c man begin SYNOPSIS gdbinit
46765@ifset SYSTEM_GDBINIT
46766@value{SYSTEM_GDBINIT}
46767@end ifset
46768
ed2a2229
CB
46769@ifset SYSTEM_GDBINIT_DIR
46770@value{SYSTEM_GDBINIT_DIR}/*
46771@end ifset
46772
43662968
JK
46773~/.gdbinit
46774
46775./.gdbinit
46776@c man end
46777@end format
46778
46779@c man begin DESCRIPTION gdbinit
46780These files contain @value{GDBN} commands to automatically execute during
46781@value{GDBN} startup. The lines of contents are canned sequences of commands,
46782described in
46783@ifset man
46784the @value{GDBN} manual in node @code{Sequences}
46785-- shell command @code{info -f gdb -n Sequences}.
46786@end ifset
46787@ifclear man
46788@ref{Sequences}.
46789@end ifclear
46790
46791Please read more in
46792@ifset man
46793the @value{GDBN} manual in node @code{Startup}
46794-- shell command @code{info -f gdb -n Startup}.
46795@end ifset
46796@ifclear man
46797@ref{Startup}.
46798@end ifclear
46799
46800@table @env
46801@ifset SYSTEM_GDBINIT
46802@item @value{SYSTEM_GDBINIT}
46803@end ifset
46804@ifclear SYSTEM_GDBINIT
46805@item (not enabled with @code{--with-system-gdbinit} during compilation)
46806@end ifclear
46807System-wide initialization file. It is executed unless user specified
46808@value{GDBN} option @code{-nx} or @code{-n}.
46809See more in
46810@ifset man
46811the @value{GDBN} manual in node @code{System-wide configuration}
46812-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46813@end ifset
ed2a2229
CB
46814@ifset SYSTEM_GDBINIT_DIR
46815@item @value{SYSTEM_GDBINIT_DIR}
46816@end ifset
46817@ifclear SYSTEM_GDBINIT_DIR
46818@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46819@end ifclear
46820System-wide initialization directory. All files in this directory are
46821executed on startup unless user specified @value{GDBN} option @code{-nx} or
46822@code{-n}, as long as they have a recognized file extension.
46823See more in
46824@ifset man
46825the @value{GDBN} manual in node @code{System-wide configuration}
46826-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46827@end ifset
43662968
JK
46828@ifclear man
46829@ref{System-wide configuration}.
46830@end ifclear
46831
46832@item ~/.gdbinit
46833User initialization file. It is executed unless user specified
46834@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46835
46836@item ./.gdbinit
46837Initialization file for current directory. It may need to be enabled with
46838@value{GDBN} security command @code{set auto-load local-gdbinit}.
46839See more in
46840@ifset man
46841the @value{GDBN} manual in node @code{Init File in the Current Directory}
46842-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46843@end ifset
46844@ifclear man
46845@ref{Init File in the Current Directory}.
46846@end ifclear
46847@end table
46848@c man end
46849
46850@c man begin SEEALSO gdbinit
46851@ifset man
46852gdb(1), @code{info -f gdb -n Startup}
46853
46854The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46855If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46856documentation are properly installed at your site, the command
ba643918
SDJ
46857
46858@smallexample
46859info gdb
46860@end smallexample
46861
46862should give you access to the complete manual.
46863
46864@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46865Richard M. Stallman and Roland H. Pesch, July 1991.
46866@end ifset
46867@c man end
46868
46869@node gdb-add-index man
ba643918 46870@heading gdb-add-index
d726cb5d 46871@pindex gdb-add-index
dbfa4523 46872@anchor{gdb-add-index}
ba643918
SDJ
46873
46874@c man title gdb-add-index Add index files to speed up GDB
46875
46876@c man begin SYNOPSIS gdb-add-index
46877gdb-add-index @var{filename}
46878@c man end
46879
46880@c man begin DESCRIPTION gdb-add-index
46881When @value{GDBN} finds a symbol file, it scans the symbols in the
46882file in order to construct an internal symbol table. This lets most
46883@value{GDBN} operations work quickly--at the cost of a delay early on.
46884For large programs, this delay can be quite lengthy, so @value{GDBN}
46885provides a way to build an index, which speeds up startup.
46886
46887To determine whether a file contains such an index, use the command
46888@kbd{readelf -S filename}: the index is stored in a section named
46889@code{.gdb_index}. The index file can only be produced on systems
46890which use ELF binaries and DWARF debug information (i.e., sections
46891named @code{.debug_*}).
46892
46893@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46894in the @env{PATH} environment variable. If you want to use different
46895versions of these programs, you can specify them through the
46896@env{GDB} and @env{OBJDUMP} environment variables.
46897
46898See more in
46899@ifset man
46900the @value{GDBN} manual in node @code{Index Files}
46901-- shell command @kbd{info -f gdb -n "Index Files"}.
46902@end ifset
46903@ifclear man
46904@ref{Index Files}.
46905@end ifclear
46906@c man end
46907
46908@c man begin SEEALSO gdb-add-index
46909@ifset man
46910The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46911If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46912documentation are properly installed at your site, the command
43662968
JK
46913
46914@smallexample
46915info gdb
46916@end smallexample
46917
46918should give you access to the complete manual.
46919
46920@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46921Richard M. Stallman and Roland H. Pesch, July 1991.
46922@end ifset
46923@c man end
46924
aab4e0ec 46925@include gpl.texi
eb12ee30 46926
e4c0cfae
SS
46927@node GNU Free Documentation License
46928@appendix GNU Free Documentation License
6826cf00
EZ
46929@include fdl.texi
46930
00595b5e
EZ
46931@node Concept Index
46932@unnumbered Concept Index
c906108c
SS
46933
46934@printindex cp
46935
00595b5e
EZ
46936@node Command and Variable Index
46937@unnumbered Command, Variable, and Function Index
46938
46939@printindex fn
46940
c906108c 46941@tex
984359d2 46942% I think something like @@colophon should be in texinfo. In the
c906108c
SS
46943% meantime:
46944\long\def\colophon{\hbox to0pt{}\vfill
46945\centerline{The body of this manual is set in}
46946\centerline{\fontname\tenrm,}
46947\centerline{with headings in {\bf\fontname\tenbf}}
46948\centerline{and examples in {\tt\fontname\tentt}.}
46949\centerline{{\it\fontname\tenit\/},}
46950\centerline{{\bf\fontname\tenbf}, and}
46951\centerline{{\sl\fontname\tensl\/}}
46952\centerline{are used for emphasis.}\vfill}
46953\page\colophon
984359d2 46954% Blame: doc@@cygnus.com, 1991.
c906108c
SS
46955@end tex
46956
c906108c 46957@bye
This page took 7.940541 seconds and 4 git commands to generate.