x86-64: Add Intel LAM property support
[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
64aaad63 940* Initialization Files:: Initialization Files
c906108c
SS
941@end menu
942
6d2ebf8b 943@node File Options
79a6e687 944@subsection Choosing Files
c906108c 945
2df3850c 946When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
947specifying an executable file and core file (or process ID). This is
948the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 949@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
950first argument that does not have an associated option flag as
951equivalent to the @samp{-se} option followed by that argument; and the
952second argument that does not have an associated option flag, if any, as
953equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
954If the second argument begins with a decimal digit, @value{GDBN} will
955first attempt to attach to it as a process, and if that fails, attempt
956to open it as a corefile. If you have a corefile whose name begins with
b383017d 957a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 958prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
959
960If @value{GDBN} has not been configured to included core file support,
961such as for most embedded targets, then it will complain about a second
962argument and ignore it.
c906108c
SS
963
964Many options have both long and short forms; both are shown in the
965following list. @value{GDBN} also recognizes the long forms if you truncate
966them, so long as enough of the option is present to be unambiguous.
967(If you prefer, you can flag option arguments with @samp{--} rather
968than @samp{-}, though we illustrate the more usual convention.)
969
d700128c
EZ
970@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
971@c way, both those who look for -foo and --foo in the index, will find
972@c it.
973
c906108c
SS
974@table @code
975@item -symbols @var{file}
976@itemx -s @var{file}
d700128c
EZ
977@cindex @code{--symbols}
978@cindex @code{-s}
c906108c
SS
979Read symbol table from file @var{file}.
980
981@item -exec @var{file}
982@itemx -e @var{file}
d700128c
EZ
983@cindex @code{--exec}
984@cindex @code{-e}
7a292a7a
SS
985Use file @var{file} as the executable file to execute when appropriate,
986and for examining pure data in conjunction with a core dump.
c906108c
SS
987
988@item -se @var{file}
d700128c 989@cindex @code{--se}
c906108c
SS
990Read symbol table from file @var{file} and use it as the executable
991file.
992
c906108c
SS
993@item -core @var{file}
994@itemx -c @var{file}
d700128c
EZ
995@cindex @code{--core}
996@cindex @code{-c}
b383017d 997Use file @var{file} as a core dump to examine.
c906108c 998
19837790
MS
999@item -pid @var{number}
1000@itemx -p @var{number}
1001@cindex @code{--pid}
1002@cindex @code{-p}
1003Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
1004
1005@item -command @var{file}
1006@itemx -x @var{file}
d700128c
EZ
1007@cindex @code{--command}
1008@cindex @code{-x}
95433b34
JB
1009Execute commands from file @var{file}. The contents of this file is
1010evaluated exactly as the @code{source} command would.
8150ff9c 1011@xref{Command Files,, Command files}.
c906108c 1012
8a5a3c82
AS
1013@item -eval-command @var{command}
1014@itemx -ex @var{command}
1015@cindex @code{--eval-command}
1016@cindex @code{-ex}
1017Execute a single @value{GDBN} command.
1018
1019This option may be used multiple times to call multiple commands. It may
1020also be interleaved with @samp{-command} as required.
1021
1022@smallexample
1023@value{GDBP} -ex 'target sim' -ex 'load' \
1024 -x setbreakpoints -ex 'run' a.out
1025@end smallexample
1026
8320cc4f
JK
1027@item -init-command @var{file}
1028@itemx -ix @var{file}
1029@cindex @code{--init-command}
1030@cindex @code{-ix}
2d7b58e8
JK
1031Execute commands from file @var{file} before loading the inferior (but
1032after loading gdbinit files).
8320cc4f
JK
1033@xref{Startup}.
1034
1035@item -init-eval-command @var{command}
1036@itemx -iex @var{command}
1037@cindex @code{--init-eval-command}
1038@cindex @code{-iex}
2d7b58e8
JK
1039Execute a single @value{GDBN} command before loading the inferior (but
1040after loading gdbinit files).
8320cc4f
JK
1041@xref{Startup}.
1042
c906108c
SS
1043@item -directory @var{directory}
1044@itemx -d @var{directory}
d700128c
EZ
1045@cindex @code{--directory}
1046@cindex @code{-d}
4b505b12 1047Add @var{directory} to the path to search for source and script files.
c906108c 1048
c906108c
SS
1049@item -r
1050@itemx -readnow
d700128c
EZ
1051@cindex @code{--readnow}
1052@cindex @code{-r}
c906108c
SS
1053Read each symbol file's entire symbol table immediately, rather than
1054the default, which is to read it incrementally as it is needed.
1055This makes startup slower, but makes future operations faster.
53a5351d 1056
97cbe998
SDJ
1057@item --readnever
1058@anchor{--readnever}
1059@cindex @code{--readnever}, command-line option
1060Do not read each symbol file's symbolic debug information. This makes
1061startup faster but at the expense of not being able to perform
1062symbolic debugging. DWARF unwind information is also not read,
1063meaning backtraces may become incomplete or inaccurate. One use of
1064this is when a user simply wants to do the following sequence: attach,
1065dump core, detach. Loading the debugging information in this case is
1066an unnecessary cause of delay.
c906108c
SS
1067@end table
1068
6d2ebf8b 1069@node Mode Options
79a6e687 1070@subsection Choosing Modes
c906108c
SS
1071
1072You can run @value{GDBN} in various alternative modes---for example, in
1073batch mode or quiet mode.
1074
1075@table @code
bf88dd68 1076@anchor{-nx}
c906108c
SS
1077@item -nx
1078@itemx -n
d700128c
EZ
1079@cindex @code{--nx}
1080@cindex @code{-n}
64aaad63
AB
1081Do not execute commands found in any initialization files
1082(@pxref{Initialization Files}).
07540c15
DE
1083
1084@anchor{-nh}
1085@item -nh
1086@cindex @code{--nh}
64aaad63
AB
1087Do not execute commands found in any home directory initialization
1088file (@pxref{Initialization Files,,Home directory initialization
1089file}). The system wide and current directory initialization files
1090are still loaded.
c906108c
SS
1091
1092@item -quiet
d700128c 1093@itemx -silent
c906108c 1094@itemx -q
d700128c
EZ
1095@cindex @code{--quiet}
1096@cindex @code{--silent}
1097@cindex @code{-q}
c906108c
SS
1098``Quiet''. Do not print the introductory and copyright messages. These
1099messages are also suppressed in batch mode.
1100
1101@item -batch
d700128c 1102@cindex @code{--batch}
c906108c
SS
1103Run in batch mode. Exit with status @code{0} after processing all the
1104command files specified with @samp{-x} (and all commands from
1105initialization files, if not inhibited with @samp{-n}). Exit with
1106nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1107in the command files. Batch mode also disables pagination, sets unlimited
1108terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1109off} were in effect (@pxref{Messages/Warnings}).
c906108c 1110
2df3850c
JM
1111Batch mode may be useful for running @value{GDBN} as a filter, for
1112example to download and run a program on another computer; in order to
1113make this more useful, the message
c906108c 1114
474c8240 1115@smallexample
c906108c 1116Program exited normally.
474c8240 1117@end smallexample
c906108c
SS
1118
1119@noindent
2df3850c
JM
1120(which is ordinarily issued whenever a program running under
1121@value{GDBN} control terminates) is not issued when running in batch
1122mode.
1123
1a088d06
AS
1124@item -batch-silent
1125@cindex @code{--batch-silent}
1126Run in batch mode exactly like @samp{-batch}, but totally silently. All
1127@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1128unaffected). This is much quieter than @samp{-silent} and would be useless
1129for an interactive session.
1130
1131This is particularly useful when using targets that give @samp{Loading section}
1132messages, for example.
1133
1134Note that targets that give their output via @value{GDBN}, as opposed to
1135writing directly to @code{stdout}, will also be made silent.
1136
4b0ad762
AS
1137@item -return-child-result
1138@cindex @code{--return-child-result}
1139The return code from @value{GDBN} will be the return code from the child
1140process (the process being debugged), with the following exceptions:
1141
1142@itemize @bullet
1143@item
1144@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1145internal error. In this case the exit code is the same as it would have been
1146without @samp{-return-child-result}.
1147@item
1148The user quits with an explicit value. E.g., @samp{quit 1}.
1149@item
1150The child process never runs, or is not allowed to terminate, in which case
1151the exit code will be -1.
1152@end itemize
1153
1154This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1155when @value{GDBN} is being used as a remote program loader or simulator
1156interface.
1157
2df3850c
JM
1158@item -nowindows
1159@itemx -nw
d700128c
EZ
1160@cindex @code{--nowindows}
1161@cindex @code{-nw}
2df3850c 1162``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1163(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1164interface. If no GUI is available, this option has no effect.
1165
1166@item -windows
1167@itemx -w
d700128c
EZ
1168@cindex @code{--windows}
1169@cindex @code{-w}
2df3850c
JM
1170If @value{GDBN} includes a GUI, then this option requires it to be
1171used if possible.
c906108c
SS
1172
1173@item -cd @var{directory}
d700128c 1174@cindex @code{--cd}
c906108c
SS
1175Run @value{GDBN} using @var{directory} as its working directory,
1176instead of the current directory.
1177
aae1c79a 1178@item -data-directory @var{directory}
8d551b02 1179@itemx -D @var{directory}
aae1c79a 1180@cindex @code{--data-directory}
8d551b02 1181@cindex @code{-D}
aae1c79a
DE
1182Run @value{GDBN} using @var{directory} as its data directory.
1183The data directory is where @value{GDBN} searches for its
1184auxiliary files. @xref{Data Files}.
1185
c906108c
SS
1186@item -fullname
1187@itemx -f
d700128c
EZ
1188@cindex @code{--fullname}
1189@cindex @code{-f}
7a292a7a
SS
1190@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1191subprocess. It tells @value{GDBN} to output the full file name and line
1192number in a standard, recognizable fashion each time a stack frame is
1193displayed (which includes each time your program stops). This
1194recognizable format looks like two @samp{\032} characters, followed by
1195the file name, line number and character position separated by colons,
1196and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1197@samp{\032} characters as a signal to display the source code for the
1198frame.
c906108c 1199
d700128c
EZ
1200@item -annotate @var{level}
1201@cindex @code{--annotate}
1202This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1203effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1204(@pxref{Annotations}). The annotation @var{level} controls how much
1205information @value{GDBN} prints together with its prompt, values of
1206expressions, source lines, and other types of output. Level 0 is the
1207normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1208@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1209that control @value{GDBN}, and level 2 has been deprecated.
1210
265eeb58 1211The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1212(@pxref{GDB/MI}).
d700128c 1213
aa26fa3a
TT
1214@item --args
1215@cindex @code{--args}
1216Change interpretation of command line so that arguments following the
1217executable file are passed as command line arguments to the inferior.
1218This option stops option processing.
1219
2df3850c
JM
1220@item -baud @var{bps}
1221@itemx -b @var{bps}
d700128c
EZ
1222@cindex @code{--baud}
1223@cindex @code{-b}
c906108c
SS
1224Set the line speed (baud rate or bits per second) of any serial
1225interface used by @value{GDBN} for remote debugging.
c906108c 1226
f47b1503
AS
1227@item -l @var{timeout}
1228@cindex @code{-l}
1229Set the timeout (in seconds) of any communication used by @value{GDBN}
1230for remote debugging.
1231
c906108c 1232@item -tty @var{device}
d700128c
EZ
1233@itemx -t @var{device}
1234@cindex @code{--tty}
1235@cindex @code{-t}
c906108c
SS
1236Run using @var{device} for your program's standard input and output.
1237@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1238
53a5351d 1239@c resolve the situation of these eventually
c4555f82
SC
1240@item -tui
1241@cindex @code{--tui}
d0d5df6f
AC
1242Activate the @dfn{Text User Interface} when starting. The Text User
1243Interface manages several text windows on the terminal, showing
1244source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1245(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1246option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1247Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1248
d700128c
EZ
1249@item -interpreter @var{interp}
1250@cindex @code{--interpreter}
1251Use the interpreter @var{interp} for interface with the controlling
1252program or device. This option is meant to be set by programs which
94bbb2c0 1253communicate with @value{GDBN} using it as a back end.
21c294e6 1254@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1255
b4be1b06
SM
1256@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1257@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1258The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1259version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1260included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1261interfaces are no longer supported.
d700128c
EZ
1262
1263@item -write
1264@cindex @code{--write}
1265Open the executable and core files for both reading and writing. This
1266is equivalent to the @samp{set write on} command inside @value{GDBN}
1267(@pxref{Patching}).
1268
1269@item -statistics
1270@cindex @code{--statistics}
1271This option causes @value{GDBN} to print statistics about time and
1272memory usage after it completes each command and returns to the prompt.
1273
1274@item -version
1275@cindex @code{--version}
1276This option causes @value{GDBN} to print its version number and
1277no-warranty blurb, and exit.
1278
6eaaf48b
EZ
1279@item -configuration
1280@cindex @code{--configuration}
1281This option causes @value{GDBN} to print details about its build-time
1282configuration parameters, and then exit. These details can be
1283important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1284
c906108c
SS
1285@end table
1286
6fc08d32 1287@node Startup
79a6e687 1288@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1289@cindex @value{GDBN} startup
1290
1291Here's the description of what @value{GDBN} does during session startup:
1292
1293@enumerate
1294@item
1295Sets up the command interpreter as specified by the command line
1296(@pxref{Mode Options, interpreter}).
1297
1298@item
1299@cindex init file
64aaad63
AB
1300Reads the system wide initialization file and the files from the
1301system wide initialization directory, @pxref{System Wide Init Files}.
098b41a6
JG
1302
1303@item
64aaad63
AB
1304Reads the initialization file (if any) in your home directory and
1305executes all the commands in that file, @pxref{Home Directory Init
1306File}.
6fc08d32 1307
2d7b58e8
JK
1308@anchor{Option -init-eval-command}
1309@item
1310Executes commands and command files specified by the @samp{-iex} and
1311@samp{-ix} options in their specified order. Usually you should use the
1312@samp{-ex} and @samp{-x} options instead, but this way you can apply
1313settings before @value{GDBN} init files get executed and before inferior
1314gets loaded.
1315
6fc08d32
EZ
1316@item
1317Processes command line options and operands.
1318
1319@item
64aaad63
AB
1320Reads and executes the commands from the initialization file (if any)
1321in the current working directory as long as @samp{set auto-load
1322local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1323Directory}). This is only done if the current directory is different
1324from your home directory. Thus, you can have more than one init file,
1325one generic in your home directory, and another, specific to the
1326program you are debugging, in the directory where you invoke
1327@value{GDBN}. @xref{Init File in the Current Directory during
1328Startup}.
6fc08d32 1329
a86caf66
DE
1330@item
1331If the command line specified a program to debug, or a process to
1332attach to, or a core file, @value{GDBN} loads any auto-loaded
1333scripts provided for the program or for its loaded shared libraries.
1334@xref{Auto-loading}.
1335
1336If you wish to disable the auto-loading during startup,
1337you must do something like the following:
1338
1339@smallexample
bf88dd68 1340$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1341@end smallexample
1342
8320cc4f
JK
1343Option @samp{-ex} does not work because the auto-loading is then turned
1344off too late.
a86caf66 1345
6fc08d32 1346@item
6fe37d23
JK
1347Executes commands and command files specified by the @samp{-ex} and
1348@samp{-x} options in their specified order. @xref{Command Files}, for
1349more details about @value{GDBN} command files.
6fc08d32
EZ
1350
1351@item
1352Reads the command history recorded in the @dfn{history file}.
d620b259 1353@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1354files where @value{GDBN} records it.
1355@end enumerate
1356
64aaad63
AB
1357@node Initialization Files
1358@subsection Initialization Files
1359@cindex init file name
6fc08d32 1360
64aaad63
AB
1361During startup (@pxref{Startup}) @value{GDBN} will execute commands
1362from several initialization files. These initialization files use the
1363same syntax as @dfn{command files} (@pxref{Command Files}) and are
1364processed by @value{GDBN} in the same way.
098b41a6 1365
64aaad63
AB
1366To display the list of initialization files loaded by @value{GDBN} at
1367startup, in the order they will be loaded, you can use @kbd{gdb
1368--help}.
1369
1370As the system wide and home directory initialization files are
1371processed before most command line options, changes to settings
1372(e.g. @samp{set complaints}) can affect subsequent processing of
1373command line options and operands.
1374
1375The following sections describe where @value{GDBN} looks for the
1376initialization and the order that the files are searched for.
1377
1378@anchor{System Wide Init Files}
1379@subsubsection System wide initialization files
1380
1381There are two locations that are searched for system wide
1382initialization files. Both of these locations are always checked:
1383
1384@table @code
1385
1386@item @file{system.gdbinit}
1387This is a single system-wide initialization file. Its location is
1388specified with the @code{--with-system-gdbinit} configure option
1389(@pxref{System-wide configuration}). It is loaded first when
1390@value{GDBN} starts, before command line options have been processed.
1391
1392@item @file{system.gdbinit.d}
1393This is the system-wide initialization directory. Its location is
1394specified with the @code{--with-system-gdbinit-dir} configure option
1395(@pxref{System-wide configuration}). Files in this directory are
1396loaded in alphabetical order immediately after @file{system.gdbinit}
1397(if enabled) when @value{GDBN} starts, before command line options
1398have been processed. Files need to have a recognized scripting
1399language extension (@file{.py}/@file{.scm}) or be named with a
1400@file{.gdb} extension to be interpreted as regular @value{GDBN}
1401commands. @value{GDBN} will not recurse into any subdirectories of
1402this directory.
1403
1404@end table
1405
1406It is possible to prevent the system wide initialization files from
1407being loaded using the @samp{-nx} command line option, @pxref{Mode
1408Options,,Choosing Modes}.
1409
1410@anchor{Home Directory Init File}
1411@subsubsection Home directory initialization file
1412@cindex @file{gdbinit}
6fc08d32 1413@cindex @file{.gdbinit}
119b882a 1414@cindex @file{gdb.ini}
119b882a 1415
64aaad63
AB
1416After loading the system wide initialization files @value{GDBN} will
1417look for an initialization file in the users home
1418directory@footnote{On DOS/Windows systems, the home directory is the
1419one pointed to by the @code{HOME} environment variable.}. There are a
1420number of locations that @value{GDBN} will search in the home
1421directory, these locations are searched in order and @value{GDBN} will
1422load the first file that it finds, and subsequent locations will not
1423be checked.
1424
1425On non-Apple hosts the locations searched are:
1426@table @file
1427@item $XDG_CONFIG_HOME/gdb/gdbinit
1428@item $HOME/.config/gdb/gdbinit
1429@item $HOME/.gdbinit
1430@end table
1431
1432While on Apple hosts the locations searched are:
1433@table @file
1434@item $HOME/Library/Preferences/gdb/gdbinit
1435@item $HOME/.gdbinit
1436@end table
1437
1438It is possible to prevent the home directory initialization file from
1439being loaded using the @samp{-nx} or @samp{-nh} command line options,
1440@pxref{Mode Options,,Choosing Modes}.
1441
1442The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1443@file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1444names imposed by DOS filesystems. The Windows port of @value{GDBN}
1445uses the standard name, but if it finds a @file{gdb.ini} file in your
1446home directory, it warns you about that and suggests to rename the
1447file to the standard name.
1448
1449@anchor{Init File in the Current Directory during Startup}
1450@subsubsection Local directory initialization file
1451
1452@value{GDBN} will check the current directory for a file called
1453@file{.gdbinit}. It is loaded last, after command line options
1454other than @samp{-x} and @samp{-ex} have been processed. The command
1455line options @samp{-x} and @samp{-ex} are processed last, after
1456@file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1457Files}.
1458
1459If the file in the current directory was already loaded as the home
1460directory initialization file then it will not be loaded a second
1461time.
1462
1463It is possible to prevent the local directory initialization file from
1464being loaded using the @samp{-nx} command line option, @pxref{Mode
1465Options,,Choosing Modes}.
6fc08d32 1466
6d2ebf8b 1467@node Quitting GDB
c906108c
SS
1468@section Quitting @value{GDBN}
1469@cindex exiting @value{GDBN}
1470@cindex leaving @value{GDBN}
1471
1472@table @code
1473@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1474@kindex q @r{(@code{quit})}
96a2c332
SS
1475@item quit @r{[}@var{expression}@r{]}
1476@itemx q
1477To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1478@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1479do not supply @var{expression}, @value{GDBN} will terminate normally;
1480otherwise it will terminate using the result of @var{expression} as the
1481error code.
c906108c
SS
1482@end table
1483
1484@cindex interrupt
c8aa23ab 1485An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1486terminates the action of any @value{GDBN} command that is in progress and
1487returns to @value{GDBN} command level. It is safe to type the interrupt
1488character at any time because @value{GDBN} does not allow it to take effect
1489until a time when it is safe.
1490
c906108c
SS
1491If you have been using @value{GDBN} to control an attached process or
1492device, you can release it with the @code{detach} command
79a6e687 1493(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1494
6d2ebf8b 1495@node Shell Commands
79a6e687 1496@section Shell Commands
c906108c
SS
1497
1498If you need to execute occasional shell commands during your
1499debugging session, there is no need to leave or suspend @value{GDBN}; you can
1500just use the @code{shell} command.
1501
1502@table @code
1503@kindex shell
ed59ded5 1504@kindex !
c906108c 1505@cindex shell escape
ed59ded5
DE
1506@item shell @var{command-string}
1507@itemx !@var{command-string}
1508Invoke a standard shell to execute @var{command-string}.
1509Note that no space is needed between @code{!} and @var{command-string}.
edf92af0
EZ
1510On GNU and Unix systems, the environment variable @code{SHELL}, if it
1511exists, determines which shell to run. Otherwise @value{GDBN} uses
1512the default shell (@file{/bin/sh} on GNU and Unix systems,
1513@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1514@end table
1515
1516The utility @code{make} is often needed in development environments.
1517You do not have to use the @code{shell} command for this purpose in
1518@value{GDBN}:
1519
1520@table @code
1521@kindex make
1522@cindex calling make
1523@item make @var{make-args}
1524Execute the @code{make} program with the specified
1525arguments. This is equivalent to @samp{shell make @var{make-args}}.
1526@end table
1527
e2c52041
PW
1528@table @code
1529@kindex pipe
1530@kindex |
1531@cindex send the output of a gdb command to a shell command
1532@anchor{pipe}
1533@item pipe [@var{command}] | @var{shell_command}
1534@itemx | [@var{command}] | @var{shell_command}
1535@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1536@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1537Executes @var{command} and sends its output to @var{shell_command}.
1538Note that no space is needed around @code{|}.
1539If no @var{command} is provided, the last command executed is repeated.
1540
1541In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1542can be used to specify an alternate delimiter string @var{delim} that separates
1543the @var{command} from the @var{shell_command}.
1544
1545Example:
1546@smallexample
1547@group
1548(gdb) p var
1549$1 = @{
1550 black = 144,
1551 red = 233,
1552 green = 377,
1553 blue = 610,
1554 white = 987
1555@}
1556@end group
1557@group
1558(gdb) pipe p var|wc
1559 7 19 80
1560(gdb) |p var|wc -l
15617
1562@end group
1563@group
1564(gdb) p /x var
1565$4 = @{
1566 black = 0x90,
1567 red = 0xe9,
1568 green = 0x179,
1569 blue = 0x262,
1570 white = 0x3db
1571@}
1572(gdb) ||grep red
1573 red => 0xe9,
1574@end group
1575@group
1576(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1577this contains a PIPE char
1578(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1579this contains a PIPE char!
1580(gdb)
1581@end group
1582@end smallexample
1583@end table
1584
1585The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1586can be used to examine the exit status of the last shell command launched
1587by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1588@xref{Convenience Vars,, Convenience Variables}.
1589
79a6e687
BW
1590@node Logging Output
1591@section Logging Output
0fac0b41 1592@cindex logging @value{GDBN} output
9c16f35a 1593@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1594
1595You may want to save the output of @value{GDBN} commands to a file.
1596There are several commands to control @value{GDBN}'s logging.
1597
1598@table @code
1599@kindex set logging
1600@item set logging on
1601Enable logging.
1602@item set logging off
1603Disable logging.
9c16f35a 1604@cindex logging file name
0fac0b41
DJ
1605@item set logging file @var{file}
1606Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1607@item set logging overwrite [on|off]
1608By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1609you want @code{set logging on} to overwrite the logfile instead.
1610@item set logging redirect [on|off]
1611By default, @value{GDBN} output will go to both the terminal and the logfile.
1612Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1613@item set logging debugredirect [on|off]
1614By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1615Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1616@kindex show logging
1617@item show logging
1618Show the current values of the logging settings.
1619@end table
1620
e2c52041
PW
1621You can also redirect the output of a @value{GDBN} command to a
1622shell command. @xref{pipe}.
6d2ebf8b 1623@node Commands
c906108c
SS
1624@chapter @value{GDBN} Commands
1625
1626You can abbreviate a @value{GDBN} command to the first few letters of the command
1627name, if that abbreviation is unambiguous; and you can repeat certain
1628@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1629key to get @value{GDBN} to fill out the rest of a word in a command (or to
1630show you the alternatives available, if there is more than one possibility).
1631
1632@menu
1633* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1634* Command Settings:: How to change default behavior of commands
c906108c 1635* Completion:: Command completion
3345721a 1636* Command Options:: Command options
5b860c93 1637* Command aliases default args:: Automatically prepend default arguments to user-defined aliases
c906108c
SS
1638* Help:: How to ask @value{GDBN} for help
1639@end menu
1640
6d2ebf8b 1641@node Command Syntax
79a6e687 1642@section Command Syntax
c906108c
SS
1643
1644A @value{GDBN} command is a single line of input. There is no limit on
1645how long it can be. It starts with a command name, which is followed by
1646arguments whose meaning depends on the command name. For example, the
1647command @code{step} accepts an argument which is the number of times to
1648step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1649with no arguments. Some commands do not allow any arguments.
c906108c
SS
1650
1651@cindex abbreviation
1652@value{GDBN} command names may always be truncated if that abbreviation is
1653unambiguous. Other possible command abbreviations are listed in the
1654documentation for individual commands. In some cases, even ambiguous
1655abbreviations are allowed; for example, @code{s} is specially defined as
1656equivalent to @code{step} even though there are other commands whose
1657names start with @code{s}. You can test abbreviations by using them as
1658arguments to the @code{help} command.
1659
1660@cindex repeating commands
41afff9a 1661@kindex RET @r{(repeat last command)}
c906108c 1662A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1663repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1664will not repeat this way; these are commands whose unintentional
1665repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1666repeat. User-defined commands can disable this feature; see
1667@ref{Define, dont-repeat}.
c906108c
SS
1668
1669The @code{list} and @code{x} commands, when you repeat them with
1670@key{RET}, construct new arguments rather than repeating
1671exactly as typed. This permits easy scanning of source or memory.
1672
1673@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1674output, in a way similar to the common utility @code{more}
79a6e687 1675(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1676@key{RET} too many in this situation, @value{GDBN} disables command
1677repetition after any command that generates this sort of display.
1678
41afff9a 1679@kindex # @r{(a comment)}
c906108c
SS
1680@cindex comment
1681Any text from a @kbd{#} to the end of the line is a comment; it does
1682nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1683Files,,Command Files}).
c906108c 1684
88118b3a 1685@cindex repeating command sequences
c8aa23ab
EZ
1686@kindex Ctrl-o @r{(operate-and-get-next)}
1687The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1688commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1689then fetches the next line relative to the current line from the history
1690for editing.
1691
fdbc9870
PA
1692
1693@node Command Settings
1694@section Command Settings
1695@cindex default behavior of commands, changing
1696@cindex default settings, changing
1697
1698Many commands change their behavior according to command-specific
1699variables or settings. These settings can be changed with the
1700@code{set} subcommands. For example, the @code{print} command
1701(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1702settings changeable with the commands @code{set print elements
1703NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1704
1705You can change these settings to your preference in the gdbinit files
1706loaded at @value{GDBN} startup. @xref{Startup}.
1707
1708The settings can also be changed interactively during the debugging
1709session. For example, to change the limit of array elements to print,
1710you can do the following:
1711@smallexample
1712(@value{GDBN}) set print elements 10
1713(@value{GDBN}) print some_array
1714$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1715@end smallexample
1716
1717The above @code{set print elements 10} command changes the number of
1718elements to print from the default of 200 to 10. If you only intend
1719this limit of 10 to be used for printing @code{some_array}, then you
1720must restore the limit back to 200, with @code{set print elements
1721200}.
1722
1723Some commands allow overriding settings with command options. For
1724example, the @code{print} command supports a number of options that
1725allow overriding relevant global print settings as set by @code{set
1726print} subcommands. @xref{print options}. The example above could be
1727rewritten as:
1728@smallexample
1729(@value{GDBN}) print -elements 10 -- some_array
1730$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1731@end smallexample
1732
1733Alternatively, you can use the @code{with} command to change a setting
1734temporarily, for the duration of a command invocation.
1735
1736@table @code
1737@kindex with command
1738@kindex w @r{(@code{with})}
1739@cindex settings
1740@cindex temporarily change settings
1741@item with @var{setting} [@var{value}] [-- @var{command}]
1742@itemx w @var{setting} [@var{value}] [-- @var{command}]
1743Temporarily set @var{setting} to @var{value} for the duration of
1744@var{command}.
1745
1746@var{setting} is any setting you can change with the @code{set}
1747subcommands. @var{value} is the value to assign to @code{setting}
1748while running @code{command}.
1749
1750If no @var{command} is provided, the last command executed is
1751repeated.
1752
1753If a @var{command} is provided, it must be preceded by a double dash
1754(@code{--}) separator. This is required because some settings accept
1755free-form arguments, such as expressions or filenames.
1756
1757For example, the command
1758@smallexample
1759(@value{GDBN}) with print array on -- print some_array
1760@end smallexample
1761@noindent
1762is equivalent to the following 3 commands:
1763@smallexample
1764(@value{GDBN}) set print array on
1765(@value{GDBN}) print some_array
1766(@value{GDBN}) set print array off
1767@end smallexample
1768
1769The @code{with} command is particularly useful when you want to
1770override a setting while running user-defined commands, or commands
1771defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1772
1773@smallexample
1774(@value{GDBN}) with print pretty on -- my_complex_command
1775@end smallexample
1776
1777To change several settings for the same command, you can nest
1778@code{with} commands. For example, @code{with language ada -- with
1779print elements 10} temporarily changes the language to Ada and sets a
1780limit of 10 elements to print for arrays and strings.
1781
1782@end table
1783
6d2ebf8b 1784@node Completion
79a6e687 1785@section Command Completion
c906108c
SS
1786
1787@cindex completion
1788@cindex word completion
1789@value{GDBN} can fill in the rest of a word in a command for you, if there is
1790only one possibility; it can also show you what the valid possibilities
1791are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1792commands, @value{GDBN} subcommands, command options, and the names of symbols
1793in your program.
c906108c
SS
1794
1795Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1796of a word. If there is only one possibility, @value{GDBN} fills in the
1797word, and waits for you to finish the command (or press @key{RET} to
1798enter it). For example, if you type
1799
1800@c FIXME "@key" does not distinguish its argument sufficiently to permit
1801@c complete accuracy in these examples; space introduced for clarity.
1802@c If texinfo enhancements make it unnecessary, it would be nice to
1803@c replace " @key" by "@key" in the following...
474c8240 1804@smallexample
c906108c 1805(@value{GDBP}) info bre @key{TAB}
474c8240 1806@end smallexample
c906108c
SS
1807
1808@noindent
1809@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1810the only @code{info} subcommand beginning with @samp{bre}:
1811
474c8240 1812@smallexample
c906108c 1813(@value{GDBP}) info breakpoints
474c8240 1814@end smallexample
c906108c
SS
1815
1816@noindent
1817You can either press @key{RET} at this point, to run the @code{info
1818breakpoints} command, or backspace and enter something else, if
1819@samp{breakpoints} does not look like the command you expected. (If you
1820were sure you wanted @code{info breakpoints} in the first place, you
1821might as well just type @key{RET} immediately after @samp{info bre},
1822to exploit command abbreviations rather than command completion).
1823
1824If there is more than one possibility for the next word when you press
1825@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1826characters and try again, or just press @key{TAB} a second time;
1827@value{GDBN} displays all the possible completions for that word. For
1828example, you might want to set a breakpoint on a subroutine whose name
1829begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1830just sounds the bell. Typing @key{TAB} again displays all the
1831function names in your program that begin with those characters, for
1832example:
1833
474c8240 1834@smallexample
c906108c
SS
1835(@value{GDBP}) b make_ @key{TAB}
1836@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1837make_a_section_from_file make_environ
1838make_abs_section make_function_type
1839make_blockvector make_pointer_type
1840make_cleanup make_reference_type
c906108c
SS
1841make_command make_symbol_completion_list
1842(@value{GDBP}) b make_
474c8240 1843@end smallexample
c906108c
SS
1844
1845@noindent
1846After displaying the available possibilities, @value{GDBN} copies your
1847partial input (@samp{b make_} in the example) so you can finish the
1848command.
1849
1850If you just want to see the list of alternatives in the first place, you
b37052ae 1851can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1852means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1853key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1854one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1855
ef0b411a
GB
1856If the number of possible completions is large, @value{GDBN} will
1857print as much of the list as it has collected, as well as a message
1858indicating that the list may be truncated.
1859
1860@smallexample
1861(@value{GDBP}) b m@key{TAB}@key{TAB}
1862main
1863<... the rest of the possible completions ...>
1864*** List may be truncated, max-completions reached. ***
1865(@value{GDBP}) b m
1866@end smallexample
1867
1868@noindent
1869This behavior can be controlled with the following commands:
1870
1871@table @code
1872@kindex set max-completions
1873@item set max-completions @var{limit}
1874@itemx set max-completions unlimited
1875Set the maximum number of completion candidates. @value{GDBN} will
1876stop looking for more completions once it collects this many candidates.
1877This is useful when completing on things like function names as collecting
1878all the possible candidates can be time consuming.
1879The default value is 200. A value of zero disables tab-completion.
1880Note that setting either no limit or a very large limit can make
1881completion slow.
1882@kindex show max-completions
1883@item show max-completions
1884Show the maximum number of candidates that @value{GDBN} will collect and show
1885during completion.
1886@end table
1887
c906108c
SS
1888@cindex quotes in commands
1889@cindex completion of quoted strings
1890Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1891parentheses or other characters that @value{GDBN} normally excludes from
1892its notion of a word. To permit word completion to work in this
1893situation, you may enclose words in @code{'} (single quote marks) in
1894@value{GDBN} commands.
c906108c 1895
d044bac8
PA
1896A likely situation where you might need this is in typing an
1897expression that involves a C@t{++} symbol name with template
1898parameters. This is because when completing expressions, GDB treats
1899the @samp{<} character as word delimiter, assuming that it's the
1900less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1901Operators}).
1902
1903For example, when you want to call a C@t{++} template function
1904interactively using the @code{print} or @code{call} commands, you may
1905need to distinguish whether you mean the version of @code{name} that
1906was specialized for @code{int}, @code{name<int>()}, or the version
1907that was specialized for @code{float}, @code{name<float>()}. To use
1908the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1909@code{'} at the beginning of the function name. This alerts
1910@value{GDBN} that it may need to consider more information than usual
1911when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1912
474c8240 1913@smallexample
d044bac8
PA
1914(@value{GDBP}) p 'func< @kbd{M-?}
1915func<int>() func<float>()
1916(@value{GDBP}) p 'func<
474c8240 1917@end smallexample
c906108c 1918
d044bac8
PA
1919When setting breakpoints however (@pxref{Specify Location}), you don't
1920usually need to type a quote before the function name, because
1921@value{GDBN} understands that you want to set a breakpoint on a
1922function:
c906108c 1923
474c8240 1924@smallexample
d044bac8
PA
1925(@value{GDBP}) b func< @kbd{M-?}
1926func<int>() func<float>()
1927(@value{GDBP}) b func<
474c8240 1928@end smallexample
c906108c 1929
d044bac8
PA
1930This is true even in the case of typing the name of C@t{++} overloaded
1931functions (multiple definitions of the same function, distinguished by
1932argument type). For example, when you want to set a breakpoint you
1933don't need to distinguish whether you mean the version of @code{name}
1934that takes an @code{int} parameter, @code{name(int)}, or the version
1935that takes a @code{float} parameter, @code{name(float)}.
1936
1937@smallexample
1938(@value{GDBP}) b bubble( @kbd{M-?}
1939bubble(int) bubble(double)
1940(@value{GDBP}) b bubble(dou @kbd{M-?}
1941bubble(double)
1942@end smallexample
1943
1944See @ref{quoting names} for a description of other scenarios that
1945require quoting.
c906108c 1946
79a6e687
BW
1947For more information about overloaded functions, see @ref{C Plus Plus
1948Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1949overload-resolution off} to disable overload resolution;
79a6e687 1950see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1951
65d12d83
TT
1952@cindex completion of structure field names
1953@cindex structure field name completion
1954@cindex completion of union field names
1955@cindex union field name completion
1956When completing in an expression which looks up a field in a
1957structure, @value{GDBN} also tries@footnote{The completer can be
1958confused by certain kinds of invalid expressions. Also, it only
1959examines the static type of the expression, not the dynamic type.} to
1960limit completions to the field names available in the type of the
1961left-hand-side:
1962
1963@smallexample
1964(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1965magic to_fputs to_rewind
1966to_data to_isatty to_write
1967to_delete to_put to_write_async_safe
1968to_flush to_read
65d12d83
TT
1969@end smallexample
1970
1971@noindent
1972This is because the @code{gdb_stdout} is a variable of the type
1973@code{struct ui_file} that is defined in @value{GDBN} sources as
1974follows:
1975
1976@smallexample
1977struct ui_file
1978@{
1979 int *magic;
1980 ui_file_flush_ftype *to_flush;
1981 ui_file_write_ftype *to_write;
01124a23 1982 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1983 ui_file_fputs_ftype *to_fputs;
1984 ui_file_read_ftype *to_read;
1985 ui_file_delete_ftype *to_delete;
1986 ui_file_isatty_ftype *to_isatty;
1987 ui_file_rewind_ftype *to_rewind;
1988 ui_file_put_ftype *to_put;
1989 void *to_data;
1990@}
1991@end smallexample
1992
3345721a
PA
1993@node Command Options
1994@section Command options
1995
1996@cindex command options
1997Some commands accept options starting with a leading dash. For
1998example, @code{print -pretty}. Similarly to command names, you can
1999abbreviate a @value{GDBN} option to the first few letters of the
2000option name, if that abbreviation is unambiguous, and you can also use
2001the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2002in an option (or to show you the alternatives available, if there is
2003more than one possibility).
2004
2005@cindex command options, raw input
2006Some commands take raw input as argument. For example, the print
2007command processes arbitrary expressions in any of the languages
2008supported by @value{GDBN}. With such commands, because raw input may
2009start with a leading dash that would be confused with an option or any
d8edc8b7
PW
2010of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2011-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
2012option, then you must use a double-dash (@code{--}) delimiter to
2013indicate the end of options.
2014
2015@cindex command options, boolean
2016
2017Some options are described as accepting an argument which can be
2018either @code{on} or @code{off}. These are known as @dfn{boolean
2019options}. Similarly to boolean settings commands---@code{on} and
2020@code{off} are the typical values, but any of @code{1}, @code{yes} and
2021@code{enable} can also be used as ``true'' value, and any of @code{0},
2022@code{no} and @code{disable} can also be used as ``false'' value. You
2023can also omit a ``true'' value, as it is implied by default.
2024
2025For example, these are equivalent:
2026
2027@smallexample
2028(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2029(@value{GDBP}) p -o -p 0 -e u -- *myptr
2030@end smallexample
2031
2032You can discover the set of options some command accepts by completing
2033on @code{-} after the command name. For example:
2034
2035@smallexample
2036(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
2037-address -max-depth -raw-values -union
2038-array -null-stop -repeats -vtbl
2039-array-indexes -object -static-members
2040-elements -pretty -symbol
3345721a
PA
2041@end smallexample
2042
2043Completion will in some cases guide you with a suggestion of what kind
2044of argument an option expects. For example:
2045
2046@smallexample
2047(@value{GDBP}) print -elements @key{TAB}@key{TAB}
2048NUMBER unlimited
2049@end smallexample
2050
2051Here, the option expects a number (e.g., @code{100}), not literal
2052@code{NUMBER}. Such metasyntactical arguments are always presented in
2053uppercase.
2054
2055(For more on using the @code{print} command, see @ref{Data, ,Examining
2056Data}.)
c906108c 2057
5b860c93
PW
2058@node Command aliases default args
2059@section Automatically prepend default arguments to user-defined aliases
2060
2061You can tell @value{GDBN} to always prepend some default arguments to
2062the list of arguments provided explicitly by the user when using a
2063user-defined alias.
2064
2065If you repeatedly use the same arguments or options for a command, you
2066can define an alias for this command and tell @value{GDBN} to
2067automatically prepend these arguments or options to the list of
2068arguments you type explicitly when using the alias@footnote{@value{GDBN}
2069could easily accept default arguments for pre-defined commands and aliases,
2070but it was deemed this would be confusing, and so is not allowed.}.
2071
2072For example, if you often use the command @code{thread apply all}
2073specifying to work on the threads in ascending order and to continue in case it
2074encounters an error, you can tell @value{GDBN} to automatically preprend
2075the @code{-ascending} and @code{-c} options by using:
2076
2077@smallexample
2078(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2079@end smallexample
2080
2081Once you have defined this alias with its default args, any time you type
2082the @code{thread apply asc-all} followed by @code{some arguments},
2083@value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2084
2085To have even less to type, you can also define a one word alias:
2086@smallexample
2087(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2088@end smallexample
2089
2090As usual, unambiguous abbreviations can be used for @var{alias}
2091and @var{default-args}.
2092
2093The different aliases of a command do not share their default args.
2094For example, you define a new alias @code{bt_ALL} showing all possible
2095information and another alias @code{bt_SMALL} showing very limited information
2096using:
2097@smallexample
2098(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2099 -past-main -past-entry -full
2100(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2101 -past-main off -past-entry off
2102@end smallexample
2103
2104(For more on using the @code{alias} command, see @ref{Aliases}.)
2105
2106Default args are not limited to the arguments and options of @var{command},
2107but can specify nested commands if @var{command} accepts such a nested command
2108as argument.
2109For example, the below defines @code{faalocalsoftype} that lists the
2110frames having locals of a certain type, together with the matching
2111local vars:
2112@smallexample
2113(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2114(@value{GDBP}) faalocalsoftype int
2115#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2116i = 0
2117ret = 21845
2118@end smallexample
2119
2120This is also very useful to define an alias for a set of nested @code{with}
2121commands to have a particular combination of temporary settings. For example,
2122the below defines the alias @code{pp10} that pretty prints an expression
2123argument, with a maximum of 10 elements if the expression is a string or
2124an array:
2125@smallexample
2126(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2127@end smallexample
2128This defines the alias @code{pp10} as being a sequence of 3 commands.
2129The first part @code{with print pretty --} temporarily activates the setting
2130@code{set print pretty}, then launches the command that follows the separator
2131@code{--}.
2132The command following the first part is also a @code{with} command that
2133temporarily changes the setting @code{set print elements} to 10, then
2134launches the command that follows the second separator @code{--}.
2135The third part @code{print} is the command the @code{pp10} alias will launch,
2136using the temporary values of the settings and the arguments explicitly given
2137by the user.
2138For more information about the @code{with} command usage,
2139see @ref{Command Settings}.
2140
6d2ebf8b 2141@node Help
79a6e687 2142@section Getting Help
c906108c
SS
2143@cindex online documentation
2144@kindex help
2145
5d161b24 2146You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2147using the command @code{help}.
2148
2149@table @code
41afff9a 2150@kindex h @r{(@code{help})}
c906108c
SS
2151@item help
2152@itemx h
2153You can use @code{help} (abbreviated @code{h}) with no arguments to
2154display a short list of named classes of commands:
2155
2156@smallexample
2157(@value{GDBP}) help
2158List of classes of commands:
2159
5b860c93 2160aliases -- User-defined aliases of other commands
c906108c 2161breakpoints -- Making program stop at certain points
2df3850c 2162data -- Examining data
c906108c 2163files -- Specifying and examining files
2df3850c
JM
2164internals -- Maintenance commands
2165obscure -- Obscure features
2166running -- Running the program
2167stack -- Examining the stack
c906108c
SS
2168status -- Status inquiries
2169support -- Support facilities
12c27660 2170tracepoints -- Tracing of program execution without
96a2c332 2171 stopping the program
c906108c 2172user-defined -- User-defined commands
c906108c 2173
5d161b24 2174Type "help" followed by a class name for a list of
c906108c 2175commands in that class.
5d161b24 2176Type "help" followed by command name for full
c906108c
SS
2177documentation.
2178Command name abbreviations are allowed if unambiguous.
2179(@value{GDBP})
2180@end smallexample
96a2c332 2181@c the above line break eliminates huge line overfull...
c906108c
SS
2182
2183@item help @var{class}
2184Using one of the general help classes as an argument, you can get a
5b4a1a8d
PW
2185list of the individual commands in that class. If a command has
2186aliases, the aliases are given after the command name, separated by
5b860c93
PW
2187commas. If an alias has default arguments, the full definition of
2188the alias is given after the first line.
2189For example, here is the help display for the class @code{status}:
c906108c
SS
2190
2191@smallexample
2192(@value{GDBP}) help status
2193Status inquiries.
2194
2195List of commands:
2196
2197@c Line break in "show" line falsifies real output, but needed
2198@c to fit in smallbook page size.
5b4a1a8d 2199info, inf, i -- Generic command for showing things
12c27660 2200 about the program being debugged
5b860c93
PW
2201info address, iamain -- Describe where symbol SYM is stored.
2202 alias iamain = info address main
2203info all-registers -- List of all registers and their contents,
2204 for selected stack frame.
5b4a1a8d
PW
2205...
2206show, info set -- Generic command for showing things
12c27660 2207 about the debugger
c906108c 2208
5d161b24 2209Type "help" followed by command name for full
c906108c
SS
2210documentation.
2211Command name abbreviations are allowed if unambiguous.
2212(@value{GDBP})
2213@end smallexample
2214
2215@item help @var{command}
2216With a command name as @code{help} argument, @value{GDBN} displays a
5b4a1a8d
PW
2217short paragraph on how to use that command. If that command has
2218one or more aliases, @value{GDBN} will display a first line with
2219the command name and all its aliases separated by commas.
5b860c93
PW
2220This first line will be followed by the full definition of all aliases
2221having default arguments.
c906108c 2222
6837a0a2 2223@kindex apropos
e664d728 2224@item apropos [-v] @var{regexp}
09d4efe1 2225The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2226commands, and their documentation, for the regular expression specified in
e664d728
PW
2227@var{args}. It prints out all matches found. The optional flag @samp{-v},
2228which stands for @samp{verbose}, indicates to output the full documentation
2229of the matching commands and highlight the parts of the documentation
2230matching @var{regexp}. For example:
6837a0a2
DB
2231
2232@smallexample
16899756 2233apropos alias
6837a0a2
DB
2234@end smallexample
2235
b37052ae
EZ
2236@noindent
2237results in:
6837a0a2
DB
2238
2239@smallexample
e664d728 2240@group
16899756 2241alias -- Define a new command that is an alias of an existing command
5b860c93 2242aliases -- User-defined aliases of other commands
e664d728
PW
2243@end group
2244@end smallexample
2245
2246@noindent
2247while
2248
2249@smallexample
2250apropos -v cut.*thread apply
2251@end smallexample
2252
2253@noindent
2254results in the below output, where @samp{cut for 'thread apply}
2255is highlighted if styling is enabled.
2256
2257@smallexample
2258@group
2259taas -- Apply a command to all threads (ignoring errors
2260and empty output).
2261Usage: taas COMMAND
2262shortcut for 'thread apply all -s COMMAND'
2263
2264tfaas -- Apply a command to all frames of all threads
2265(ignoring errors and empty output).
2266Usage: tfaas COMMAND
2267shortcut for 'thread apply all -s frame apply all -s COMMAND'
2268@end group
6837a0a2
DB
2269@end smallexample
2270
c906108c
SS
2271@kindex complete
2272@item complete @var{args}
2273The @code{complete @var{args}} command lists all the possible completions
2274for the beginning of a command. Use @var{args} to specify the beginning of the
2275command you want completed. For example:
2276
2277@smallexample
2278complete i
2279@end smallexample
2280
2281@noindent results in:
2282
2283@smallexample
2284@group
2df3850c
JM
2285if
2286ignore
c906108c
SS
2287info
2288inspect
c906108c
SS
2289@end group
2290@end smallexample
2291
2292@noindent This is intended for use by @sc{gnu} Emacs.
2293@end table
2294
2295In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2296and @code{show} to inquire about the state of your program, or the state
2297of @value{GDBN} itself. Each command supports many topics of inquiry; this
2298manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2299under @code{info} and under @code{show} in the Command, Variable, and
2300Function Index point to all the sub-commands. @xref{Command and Variable
2301Index}.
c906108c
SS
2302
2303@c @group
2304@table @code
2305@kindex info
41afff9a 2306@kindex i @r{(@code{info})}
c906108c
SS
2307@item info
2308This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2309program. For example, you can show the arguments passed to a function
c906108c
SS
2310with @code{info args}, list the registers currently in use with @code{info
2311registers}, or list the breakpoints you have set with @code{info breakpoints}.
2312You can get a complete list of the @code{info} sub-commands with
2313@w{@code{help info}}.
2314
2315@kindex set
2316@item set
5d161b24 2317You can assign the result of an expression to an environment variable with
c906108c
SS
2318@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2319@code{set prompt $}.
2320
2321@kindex show
2322@item show
5d161b24 2323In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2324@value{GDBN} itself.
2325You can change most of the things you can @code{show}, by using the
2326related command @code{set}; for example, you can control what number
2327system is used for displays with @code{set radix}, or simply inquire
2328which is currently in use with @code{show radix}.
2329
2330@kindex info set
2331To display all the settable parameters and their current
2332values, you can use @code{show} with no arguments; you may also use
2333@code{info set}. Both commands produce the same display.
2334@c FIXME: "info set" violates the rule that "info" is for state of
2335@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2336@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2337@end table
2338@c @end group
2339
6eaaf48b 2340Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2341exceptional in lacking corresponding @code{set} commands:
2342
2343@table @code
2344@kindex show version
9c16f35a 2345@cindex @value{GDBN} version number
c906108c
SS
2346@item show version
2347Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2348information in @value{GDBN} bug-reports. If multiple versions of
2349@value{GDBN} are in use at your site, you may need to determine which
2350version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2351commands are introduced, and old ones may wither away. Also, many
2352system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2353variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2354The version number is the same as the one announced when you start
2355@value{GDBN}.
c906108c
SS
2356
2357@kindex show copying
09d4efe1 2358@kindex info copying
9c16f35a 2359@cindex display @value{GDBN} copyright
c906108c 2360@item show copying
09d4efe1 2361@itemx info copying
c906108c
SS
2362Display information about permission for copying @value{GDBN}.
2363
2364@kindex show warranty
09d4efe1 2365@kindex info warranty
c906108c 2366@item show warranty
09d4efe1 2367@itemx info warranty
2df3850c 2368Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2369if your version of @value{GDBN} comes with one.
2df3850c 2370
6eaaf48b
EZ
2371@kindex show configuration
2372@item show configuration
2373Display detailed information about the way @value{GDBN} was configured
2374when it was built. This displays the optional arguments passed to the
2375@file{configure} script and also configuration parameters detected
2376automatically by @command{configure}. When reporting a @value{GDBN}
2377bug (@pxref{GDB Bugs}), it is important to include this information in
2378your report.
2379
c906108c
SS
2380@end table
2381
6d2ebf8b 2382@node Running
c906108c
SS
2383@chapter Running Programs Under @value{GDBN}
2384
2385When you run a program under @value{GDBN}, you must first generate
2386debugging information when you compile it.
7a292a7a
SS
2387
2388You may start @value{GDBN} with its arguments, if any, in an environment
2389of your choice. If you are doing native debugging, you may redirect
2390your program's input and output, debug an already running process, or
2391kill a child process.
c906108c
SS
2392
2393@menu
2394* Compilation:: Compiling for debugging
2395* Starting:: Starting your program
c906108c
SS
2396* Arguments:: Your program's arguments
2397* Environment:: Your program's environment
c906108c
SS
2398
2399* Working Directory:: Your program's working directory
2400* Input/Output:: Your program's input and output
2401* Attach:: Debugging an already-running process
2402* Kill Process:: Killing the child process
65c574f6
PA
2403* Inferiors Connections and Programs:: Debugging multiple inferiors
2404 connections and programs
c906108c 2405* Threads:: Debugging programs with multiple threads
6c95b8df 2406* Forks:: Debugging forks
5c95884b 2407* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2408@end menu
2409
6d2ebf8b 2410@node Compilation
79a6e687 2411@section Compiling for Debugging
c906108c
SS
2412
2413In order to debug a program effectively, you need to generate
2414debugging information when you compile it. This debugging information
2415is stored in the object file; it describes the data type of each
2416variable or function and the correspondence between source line numbers
2417and addresses in the executable code.
2418
2419To request debugging information, specify the @samp{-g} option when you run
2420the compiler.
2421
514c4d71 2422Programs that are to be shipped to your customers are compiled with
edb3359d 2423optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2424compilers are unable to handle the @samp{-g} and @samp{-O} options
2425together. Using those compilers, you cannot generate optimized
c906108c
SS
2426executables containing debugging information.
2427
514c4d71 2428@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2429without @samp{-O}, making it possible to debug optimized code. We
2430recommend that you @emph{always} use @samp{-g} whenever you compile a
2431program. You may think your program is correct, but there is no sense
edb3359d 2432in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2433
2434Older versions of the @sc{gnu} C compiler permitted a variant option
2435@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2436format; if your @sc{gnu} C compiler has this option, do not use it.
2437
514c4d71
EZ
2438@value{GDBN} knows about preprocessor macros and can show you their
2439expansion (@pxref{Macros}). Most compilers do not include information
2440about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2441the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2442the @sc{gnu} C compiler, provides macro information if you are using
2443the DWARF debugging format, and specify the option @option{-g3}.
2444
2445@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2446gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2447information on @value{NGCC} options affecting debug information.
2448
2449You will have the best debugging experience if you use the latest
2450version of the DWARF debugging format that your compiler supports.
2451DWARF is currently the most expressive and best supported debugging
2452format in @value{GDBN}.
514c4d71 2453
c906108c 2454@need 2000
6d2ebf8b 2455@node Starting
79a6e687 2456@section Starting your Program
c906108c
SS
2457@cindex starting
2458@cindex running
2459
2460@table @code
2461@kindex run
41afff9a 2462@kindex r @r{(@code{run})}
c906108c
SS
2463@item run
2464@itemx r
7a292a7a 2465Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2466You must first specify the program name with an argument to
2467@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2468@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2469command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2470
2471@end table
2472
c906108c
SS
2473If you are running your program in an execution environment that
2474supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2475that process run your program. In some environments without processes,
2476@code{run} jumps to the start of your program. Other targets,
2477like @samp{remote}, are always running. If you get an error
2478message like this one:
2479
2480@smallexample
2481The "remote" target does not support "run".
2482Try "help target" or "continue".
2483@end smallexample
2484
2485@noindent
2486then use @code{continue} to run your program. You may need @code{load}
2487first (@pxref{load}).
c906108c
SS
2488
2489The execution of a program is affected by certain information it
2490receives from its superior. @value{GDBN} provides ways to specify this
2491information, which you must do @emph{before} starting your program. (You
2492can change it after starting your program, but such changes only affect
2493your program the next time you start it.) This information may be
2494divided into four categories:
2495
2496@table @asis
2497@item The @emph{arguments.}
2498Specify the arguments to give your program as the arguments of the
2499@code{run} command. If a shell is available on your target, the shell
2500is used to pass the arguments, so that you may use normal conventions
2501(such as wildcard expansion or variable substitution) in describing
2502the arguments.
2503In Unix systems, you can control which shell is used with the
98882a26
PA
2504@code{SHELL} environment variable. If you do not define @code{SHELL},
2505@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2506use of any shell with the @code{set startup-with-shell} command (see
2507below for details).
c906108c
SS
2508
2509@item The @emph{environment.}
2510Your program normally inherits its environment from @value{GDBN}, but you can
2511use the @value{GDBN} commands @code{set environment} and @code{unset
2512environment} to change parts of the environment that affect
79a6e687 2513your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2514
2515@item The @emph{working directory.}
d092c5a2
SDJ
2516You can set your program's working directory with the command
2517@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2518command, your program will inherit @value{GDBN}'s working directory if
2519native debugging, or the remote server's working directory if remote
2520debugging. @xref{Working Directory, ,Your Program's Working
2521Directory}.
c906108c
SS
2522
2523@item The @emph{standard input and output.}
2524Your program normally uses the same device for standard input and
2525standard output as @value{GDBN} is using. You can redirect input and output
2526in the @code{run} command line, or you can use the @code{tty} command to
2527set a different device for your program.
79a6e687 2528@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2529
2530@cindex pipes
2531@emph{Warning:} While input and output redirection work, you cannot use
2532pipes to pass the output of the program you are debugging to another
2533program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2534wrong program.
2535@end table
c906108c
SS
2536
2537When you issue the @code{run} command, your program begins to execute
79a6e687 2538immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2539of how to arrange for your program to stop. Once your program has
2540stopped, you may call functions in your program, using the @code{print}
2541or @code{call} commands. @xref{Data, ,Examining Data}.
2542
2543If the modification time of your symbol file has changed since the last
2544time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2545table, and reads it again. When it does this, @value{GDBN} tries to retain
2546your current breakpoints.
2547
4e8b0763
JB
2548@table @code
2549@kindex start
2550@item start
2551@cindex run to main procedure
2552The name of the main procedure can vary from language to language.
2553With C or C@t{++}, the main procedure name is always @code{main}, but
2554other languages such as Ada do not require a specific name for their
2555main procedure. The debugger provides a convenient way to start the
2556execution of the program and to stop at the beginning of the main
2557procedure, depending on the language used.
2558
2559The @samp{start} command does the equivalent of setting a temporary
2560breakpoint at the beginning of the main procedure and then invoking
2561the @samp{run} command.
2562
f018e82f
EZ
2563@cindex elaboration phase
2564Some programs contain an @dfn{elaboration} phase where some startup code is
2565executed before the main procedure is called. This depends on the
2566languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2567constructors for static and global objects are executed before
2568@code{main} is called. It is therefore possible that the debugger stops
2569before reaching the main procedure. However, the temporary breakpoint
2570will remain to halt execution.
2571
2572Specify the arguments to give to your program as arguments to the
2573@samp{start} command. These arguments will be given verbatim to the
2574underlying @samp{run} command. Note that the same arguments will be
2575reused if no argument is provided during subsequent calls to
2576@samp{start} or @samp{run}.
2577
2578It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2579these cases, using the @code{start} command would stop the execution
2580of your program too late, as the program would have already completed
2581the elaboration phase. Under these circumstances, either insert
2582breakpoints in your elaboration code before running your program or
2583use the @code{starti} command.
2584
2585@kindex starti
2586@item starti
2587@cindex run to first instruction
2588The @samp{starti} command does the equivalent of setting a temporary
2589breakpoint at the first instruction of a program's execution and then
2590invoking the @samp{run} command. For programs containing an
2591elaboration phase, the @code{starti} command will stop execution at
2592the start of the elaboration phase.
ccd213ac 2593
41ef2965 2594@anchor{set exec-wrapper}
ccd213ac
DJ
2595@kindex set exec-wrapper
2596@item set exec-wrapper @var{wrapper}
2597@itemx show exec-wrapper
2598@itemx unset exec-wrapper
2599When @samp{exec-wrapper} is set, the specified wrapper is used to
2600launch programs for debugging. @value{GDBN} starts your program
2601with a shell command of the form @kbd{exec @var{wrapper}
2602@var{program}}. Quoting is added to @var{program} and its
2603arguments, but not to @var{wrapper}, so you should add quotes if
2604appropriate for your shell. The wrapper runs until it executes
2605your program, and then @value{GDBN} takes control.
2606
2607You can use any program that eventually calls @code{execve} with
2608its arguments as a wrapper. Several standard Unix utilities do
2609this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2610with @code{exec "$@@"} will also work.
2611
2612For example, you can use @code{env} to pass an environment variable to
2613the debugged program, without setting the variable in your shell's
2614environment:
2615
2616@smallexample
2617(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2618(@value{GDBP}) run
2619@end smallexample
2620
2621This command is available when debugging locally on most targets, excluding
2622@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2623
98882a26 2624@kindex set startup-with-shell
aefd8b33 2625@anchor{set startup-with-shell}
98882a26
PA
2626@item set startup-with-shell
2627@itemx set startup-with-shell on
2628@itemx set startup-with-shell off
ca145713 2629@itemx show startup-with-shell
98882a26
PA
2630On Unix systems, by default, if a shell is available on your target,
2631@value{GDBN}) uses it to start your program. Arguments of the
2632@code{run} command are passed to the shell, which does variable
2633substitution, expands wildcard characters and performs redirection of
2634I/O. In some circumstances, it may be useful to disable such use of a
2635shell, for example, when debugging the shell itself or diagnosing
2636startup failures such as:
2637
2638@smallexample
2639(@value{GDBP}) run
2640Starting program: ./a.out
2641During startup program terminated with signal SIGSEGV, Segmentation fault.
2642@end smallexample
2643
2644@noindent
2645which indicates the shell or the wrapper specified with
2646@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2647caused by something odd in your shell's non-interactive mode
2648initialization file---such as @file{.cshrc} for C-shell,
2649$@file{.zshenv} for the Z shell, or the file specified in the
2650@samp{BASH_ENV} environment variable for BASH.
98882a26 2651
6a3cb8e8
PA
2652@anchor{set auto-connect-native-target}
2653@kindex set auto-connect-native-target
2654@item set auto-connect-native-target
2655@itemx set auto-connect-native-target on
2656@itemx set auto-connect-native-target off
2657@itemx show auto-connect-native-target
2658
65c574f6
PA
2659By default, if the current inferior is not connected to any target yet
2660(e.g., with @code{target remote}), the @code{run} command starts your
2661program as a native process under @value{GDBN}, on your local machine.
2662If you're sure you don't want to debug programs on your local machine,
2663you can tell @value{GDBN} to not connect to the native target
2664automatically with the @code{set auto-connect-native-target off}
2665command.
6a3cb8e8 2666
65c574f6 2667If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2668connected to a target already, the @code{run} command automaticaly
2669connects to the native target, if one is available.
2670
65c574f6
PA
2671If @code{off}, and if the current inferior is not connected to a
2672target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2673
2674@smallexample
2675(@value{GDBP}) run
2676Don't know how to run. Try "help target".
2677@end smallexample
2678
65c574f6
PA
2679If the current inferior is already connected to a target, @value{GDBN}
2680always uses it with the @code{run} command.
6a3cb8e8
PA
2681
2682In any case, you can explicitly connect to the native target with the
2683@code{target native} command. For example,
2684
2685@smallexample
2686(@value{GDBP}) set auto-connect-native-target off
2687(@value{GDBP}) run
2688Don't know how to run. Try "help target".
2689(@value{GDBP}) target native
2690(@value{GDBP}) run
2691Starting program: ./a.out
2692[Inferior 1 (process 10421) exited normally]
2693@end smallexample
2694
2695In case you connected explicitly to the @code{native} target,
2696@value{GDBN} remains connected even if all inferiors exit, ready for
2697the next @code{run} command. Use the @code{disconnect} command to
2698disconnect.
2699
2700Examples of other commands that likewise respect the
2701@code{auto-connect-native-target} setting: @code{attach}, @code{info
2702proc}, @code{info os}.
2703
10568435
JK
2704@kindex set disable-randomization
2705@item set disable-randomization
2706@itemx set disable-randomization on
2707This option (enabled by default in @value{GDBN}) will turn off the native
2708randomization of the virtual address space of the started program. This option
2709is useful for multiple debugging sessions to make the execution better
2710reproducible and memory addresses reusable across debugging sessions.
2711
03583c20
UW
2712This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2713On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2714
2715@smallexample
2716(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2717@end smallexample
2718
2719@item set disable-randomization off
2720Leave the behavior of the started executable unchanged. Some bugs rear their
2721ugly heads only when the program is loaded at certain addresses. If your bug
2722disappears when you run the program under @value{GDBN}, that might be because
2723@value{GDBN} by default disables the address randomization on platforms, such
2724as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2725disable-randomization off} to try to reproduce such elusive bugs.
2726
03583c20
UW
2727On targets where it is available, virtual address space randomization
2728protects the programs against certain kinds of security attacks. In these
10568435
JK
2729cases the attacker needs to know the exact location of a concrete executable
2730code. Randomizing its location makes it impossible to inject jumps misusing
2731a code at its expected addresses.
2732
2733Prelinking shared libraries provides a startup performance advantage but it
2734makes addresses in these libraries predictable for privileged processes by
2735having just unprivileged access at the target system. Reading the shared
2736library binary gives enough information for assembling the malicious code
2737misusing it. Still even a prelinked shared library can get loaded at a new
2738random address just requiring the regular relocation process during the
2739startup. Shared libraries not already prelinked are always loaded at
2740a randomly chosen address.
2741
2742Position independent executables (PIE) contain position independent code
2743similar to the shared libraries and therefore such executables get loaded at
2744a randomly chosen address upon startup. PIE executables always load even
2745already prelinked shared libraries at a random address. You can build such
2746executable using @command{gcc -fPIE -pie}.
2747
2748Heap (malloc storage), stack and custom mmap areas are always placed randomly
2749(as long as the randomization is enabled).
2750
2751@item show disable-randomization
2752Show the current setting of the explicit disable of the native randomization of
2753the virtual address space of the started program.
2754
4e8b0763
JB
2755@end table
2756
6d2ebf8b 2757@node Arguments
79a6e687 2758@section Your Program's Arguments
c906108c
SS
2759
2760@cindex arguments (to your program)
2761The arguments to your program can be specified by the arguments of the
5d161b24 2762@code{run} command.
c906108c
SS
2763They are passed to a shell, which expands wildcard characters and
2764performs redirection of I/O, and thence to your program. Your
2765@code{SHELL} environment variable (if it exists) specifies what shell
2766@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2767the default shell (@file{/bin/sh} on Unix).
2768
2769On non-Unix systems, the program is usually invoked directly by
2770@value{GDBN}, which emulates I/O redirection via the appropriate system
2771calls, and the wildcard characters are expanded by the startup code of
2772the program, not by the shell.
c906108c
SS
2773
2774@code{run} with no arguments uses the same arguments used by the previous
2775@code{run}, or those set by the @code{set args} command.
2776
c906108c 2777@table @code
41afff9a 2778@kindex set args
c906108c
SS
2779@item set args
2780Specify the arguments to be used the next time your program is run. If
2781@code{set args} has no arguments, @code{run} executes your program
2782with no arguments. Once you have run your program with arguments,
2783using @code{set args} before the next @code{run} is the only way to run
2784it again without arguments.
2785
2786@kindex show args
2787@item show args
2788Show the arguments to give your program when it is started.
2789@end table
2790
6d2ebf8b 2791@node Environment
79a6e687 2792@section Your Program's Environment
c906108c
SS
2793
2794@cindex environment (of your program)
2795The @dfn{environment} consists of a set of environment variables and
2796their values. Environment variables conventionally record such things as
2797your user name, your home directory, your terminal type, and your search
2798path for programs to run. Usually you set up environment variables with
2799the shell and they are inherited by all the other programs you run. When
2800debugging, it can be useful to try running your program with a modified
2801environment without having to start @value{GDBN} over again.
2802
2803@table @code
2804@kindex path
2805@item path @var{directory}
2806Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2807(the search path for executables) that will be passed to your program.
2808The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2809You may specify several directory names, separated by whitespace or by a
2810system-dependent separator character (@samp{:} on Unix, @samp{;} on
2811MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2812is moved to the front, so it is searched sooner.
c906108c
SS
2813
2814You can use the string @samp{$cwd} to refer to whatever is the current
2815working directory at the time @value{GDBN} searches the path. If you
2816use @samp{.} instead, it refers to the directory where you executed the
2817@code{path} command. @value{GDBN} replaces @samp{.} in the
2818@var{directory} argument (with the current path) before adding
2819@var{directory} to the search path.
2820@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2821@c document that, since repeating it would be a no-op.
2822
2823@kindex show paths
2824@item show paths
2825Display the list of search paths for executables (the @code{PATH}
2826environment variable).
2827
2828@kindex show environment
2829@item show environment @r{[}@var{varname}@r{]}
2830Print the value of environment variable @var{varname} to be given to
2831your program when it starts. If you do not supply @var{varname},
2832print the names and values of all environment variables to be given to
2833your program. You can abbreviate @code{environment} as @code{env}.
2834
2835@kindex set environment
0a2dde4a 2836@anchor{set environment}
53a5351d 2837@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2838Set environment variable @var{varname} to @var{value}. The value
41ef2965 2839changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2840it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2841values of environment variables are just strings, and any
2842interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2843parameter is optional; if it is eliminated, the variable is set to a
2844null value.
2845@c "any string" here does not include leading, trailing
2846@c blanks. Gnu asks: does anyone care?
2847
2848For example, this command:
2849
474c8240 2850@smallexample
c906108c 2851set env USER = foo
474c8240 2852@end smallexample
c906108c
SS
2853
2854@noindent
d4f3574e 2855tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2856@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2857are not actually required.)
2858
41ef2965
PA
2859Note that on Unix systems, @value{GDBN} runs your program via a shell,
2860which also inherits the environment set with @code{set environment}.
2861If necessary, you can avoid that by using the @samp{env} program as a
2862wrapper instead of using @code{set environment}. @xref{set
2863exec-wrapper}, for an example doing just that.
2864
0a2dde4a
SDJ
2865Environment variables that are set by the user are also transmitted to
2866@command{gdbserver} to be used when starting the remote inferior.
2867@pxref{QEnvironmentHexEncoded}.
2868
c906108c 2869@kindex unset environment
0a2dde4a 2870@anchor{unset environment}
c906108c
SS
2871@item unset environment @var{varname}
2872Remove variable @var{varname} from the environment to be passed to your
2873program. This is different from @samp{set env @var{varname} =};
2874@code{unset environment} removes the variable from the environment,
2875rather than assigning it an empty value.
0a2dde4a
SDJ
2876
2877Environment variables that are unset by the user are also unset on
2878@command{gdbserver} when starting the remote inferior.
2879@pxref{QEnvironmentUnset}.
c906108c
SS
2880@end table
2881
d4f3574e 2882@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2883the shell indicated by your @code{SHELL} environment variable if it
2884exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2885names a shell that runs an initialization file when started
2886non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2887for the Z shell, or the file specified in the @samp{BASH_ENV}
2888environment variable for BASH---any variables you set in that file
2889affect your program. You may wish to move setting of environment
2890variables to files that are only run when you sign on, such as
2891@file{.login} or @file{.profile}.
c906108c 2892
6d2ebf8b 2893@node Working Directory
79a6e687 2894@section Your Program's Working Directory
c906108c
SS
2895
2896@cindex working directory (of your program)
d092c5a2
SDJ
2897Each time you start your program with @code{run}, the inferior will be
2898initialized with the current working directory specified by the
2899@kbd{set cwd} command. If no directory has been specified by this
2900command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2901directory as its working directory if native debugging, or it will
2902inherit the remote server's current working directory if remote
2903debugging.
c906108c
SS
2904
2905@table @code
d092c5a2
SDJ
2906@kindex set cwd
2907@cindex change inferior's working directory
2908@anchor{set cwd command}
2909@item set cwd @r{[}@var{directory}@r{]}
2910Set the inferior's working directory to @var{directory}, which will be
2911@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2912argument has been specified, the command clears the setting and resets
2913it to an empty state. This setting has no effect on @value{GDBN}'s
2914working directory, and it only takes effect the next time you start
2915the inferior. The @file{~} in @var{directory} is a short for the
2916@dfn{home directory}, usually pointed to by the @env{HOME} environment
2917variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2918uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2919fallback.
2920
2921You can also change @value{GDBN}'s current working directory by using
2922the @code{cd} command.
dbfa4523 2923@xref{cd command}.
d092c5a2
SDJ
2924
2925@kindex show cwd
2926@cindex show inferior's working directory
2927@item show cwd
2928Show the inferior's working directory. If no directory has been
2929specified by @kbd{set cwd}, then the default inferior's working
2930directory is the same as @value{GDBN}'s working directory.
2931
c906108c 2932@kindex cd
d092c5a2
SDJ
2933@cindex change @value{GDBN}'s working directory
2934@anchor{cd command}
f3c8a52a
JK
2935@item cd @r{[}@var{directory}@r{]}
2936Set the @value{GDBN} working directory to @var{directory}. If not
2937given, @var{directory} uses @file{'~'}.
c906108c 2938
d092c5a2
SDJ
2939The @value{GDBN} working directory serves as a default for the
2940commands that specify files for @value{GDBN} to operate on.
2941@xref{Files, ,Commands to Specify Files}.
dbfa4523 2942@xref{set cwd command}.
d092c5a2 2943
c906108c
SS
2944@kindex pwd
2945@item pwd
2946Print the @value{GDBN} working directory.
2947@end table
2948
60bf7e09
EZ
2949It is generally impossible to find the current working directory of
2950the process being debugged (since a program can change its directory
2d97a5d9 2951during its run). If you work on a system where @value{GDBN} supports
754452f0 2952the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2953use the @code{info proc} command to find out the
60bf7e09
EZ
2954current working directory of the debuggee.
2955
6d2ebf8b 2956@node Input/Output
79a6e687 2957@section Your Program's Input and Output
c906108c
SS
2958
2959@cindex redirection
2960@cindex i/o
2961@cindex terminal
2962By default, the program you run under @value{GDBN} does input and output to
5d161b24 2963the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2964to its own terminal modes to interact with you, but it records the terminal
2965modes your program was using and switches back to them when you continue
2966running your program.
2967
2968@table @code
2969@kindex info terminal
2970@item info terminal
2971Displays information recorded by @value{GDBN} about the terminal modes your
2972program is using.
2973@end table
2974
2975You can redirect your program's input and/or output using shell
2976redirection with the @code{run} command. For example,
2977
474c8240 2978@smallexample
c906108c 2979run > outfile
474c8240 2980@end smallexample
c906108c
SS
2981
2982@noindent
2983starts your program, diverting its output to the file @file{outfile}.
2984
2985@kindex tty
2986@cindex controlling terminal
2987Another way to specify where your program should do input and output is
2988with the @code{tty} command. This command accepts a file name as
2989argument, and causes this file to be the default for future @code{run}
2990commands. It also resets the controlling terminal for the child
2991process, for future @code{run} commands. For example,
2992
474c8240 2993@smallexample
c906108c 2994tty /dev/ttyb
474c8240 2995@end smallexample
c906108c
SS
2996
2997@noindent
2998directs that processes started with subsequent @code{run} commands
2999default to do input and output on the terminal @file{/dev/ttyb} and have
3000that as their controlling terminal.
3001
3002An explicit redirection in @code{run} overrides the @code{tty} command's
3003effect on the input/output device, but not its effect on the controlling
3004terminal.
3005
3006When you use the @code{tty} command or redirect input in the @code{run}
3007command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
3008for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3009for @code{set inferior-tty}.
3010
3011@cindex inferior tty
3012@cindex set inferior controlling terminal
3013You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3014display the name of the terminal that will be used for future runs of your
3015program.
3016
3017@table @code
0a1ddfa6 3018@item set inferior-tty [ @var{tty} ]
3cb3b8df 3019@kindex set inferior-tty
0a1ddfa6
SM
3020Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3021restores the default behavior, which is to use the same terminal as
3022@value{GDBN}.
3cb3b8df
BR
3023
3024@item show inferior-tty
3025@kindex show inferior-tty
3026Show the current tty for the program being debugged.
3027@end table
c906108c 3028
6d2ebf8b 3029@node Attach
79a6e687 3030@section Debugging an Already-running Process
c906108c
SS
3031@kindex attach
3032@cindex attach
3033
3034@table @code
3035@item attach @var{process-id}
3036This command attaches to a running process---one that was started
3037outside @value{GDBN}. (@code{info files} shows your active
3038targets.) The command takes as argument a process ID. The usual way to
09d4efe1 3039find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
3040or with the @samp{jobs -l} shell command.
3041
3042@code{attach} does not repeat if you press @key{RET} a second time after
3043executing the command.
3044@end table
3045
3046To use @code{attach}, your program must be running in an environment
3047which supports processes; for example, @code{attach} does not work for
3048programs on bare-board targets that lack an operating system. You must
3049also have permission to send the process a signal.
3050
3051When you use @code{attach}, the debugger finds the program running in
3052the process first by looking in the current working directory, then (if
3053the program is not found) by using the source file search path
79a6e687 3054(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
3055the @code{file} command to load the program. @xref{Files, ,Commands to
3056Specify Files}.
3057
e47e48f6 3058@anchor{set exec-file-mismatch}
98c59b52
PA
3059If the debugger can determine that the executable file running in the
3060process it is attaching to does not match the current exec-file loaded
3061by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3062handle the mismatch. @value{GDBN} tries to compare the files by
3063comparing their build IDs (@pxref{build ID}), if available.
e47e48f6
PW
3064
3065@table @code
3066@kindex exec-file-mismatch
3067@cindex set exec-file-mismatch
3068@item set exec-file-mismatch @samp{ask|warn|off}
3069
98c59b52
PA
3070Whether to detect mismatch between the current executable file loaded
3071by @value{GDBN} and the executable file used to start the process. If
3072@samp{ask}, the default, display a warning and ask the user whether to
3073load the process executable file; if @samp{warn}, just display a
3074warning; if @samp{off}, don't attempt to detect a mismatch.
0a278aa7
PW
3075If the user confirms loading the process executable file, then its symbols
3076will be loaded as well.
e47e48f6
PW
3077
3078@cindex show exec-file-mismatch
3079@item show exec-file-mismatch
3080Show the current value of @code{exec-file-mismatch}.
3081
3082@end table
3083
c906108c
SS
3084The first thing @value{GDBN} does after arranging to debug the specified
3085process is to stop it. You can examine and modify an attached process
53a5351d
JM
3086with all the @value{GDBN} commands that are ordinarily available when
3087you start processes with @code{run}. You can insert breakpoints; you
3088can step and continue; you can modify storage. If you would rather the
3089process continue running, you may use the @code{continue} command after
c906108c
SS
3090attaching @value{GDBN} to the process.
3091
3092@table @code
3093@kindex detach
3094@item detach
3095When you have finished debugging the attached process, you can use the
3096@code{detach} command to release it from @value{GDBN} control. Detaching
3097the process continues its execution. After the @code{detach} command,
3098that process and @value{GDBN} become completely independent once more, and you
3099are ready to @code{attach} another process or start one with @code{run}.
3100@code{detach} does not repeat if you press @key{RET} again after
3101executing the command.
3102@end table
3103
159fcc13
JK
3104If you exit @value{GDBN} while you have an attached process, you detach
3105that process. If you use the @code{run} command, you kill that process.
3106By default, @value{GDBN} asks for confirmation if you try to do either of these
3107things; you can control whether or not you need to confirm by using the
3108@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 3109Messages}).
c906108c 3110
6d2ebf8b 3111@node Kill Process
79a6e687 3112@section Killing the Child Process
c906108c
SS
3113
3114@table @code
3115@kindex kill
3116@item kill
3117Kill the child process in which your program is running under @value{GDBN}.
3118@end table
3119
3120This command is useful if you wish to debug a core dump instead of a
3121running process. @value{GDBN} ignores any core dump file while your program
3122is running.
3123
3124On some operating systems, a program cannot be executed outside @value{GDBN}
3125while you have breakpoints set on it inside @value{GDBN}. You can use the
3126@code{kill} command in this situation to permit running your program
3127outside the debugger.
3128
3129The @code{kill} command is also useful if you wish to recompile and
3130relink your program, since on many systems it is impossible to modify an
3131executable file while it is running in a process. In this case, when you
3132next type @code{run}, @value{GDBN} notices that the file has changed, and
3133reads the symbol table again (while trying to preserve your current
3134breakpoint settings).
3135
65c574f6
PA
3136@node Inferiors Connections and Programs
3137@section Debugging Multiple Inferiors Connections and Programs
b77209e0 3138
6c95b8df
PA
3139@value{GDBN} lets you run and debug multiple programs in a single
3140session. In addition, @value{GDBN} on some systems may let you run
3141several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
3142before starting another). On some systems @value{GDBN} may even let
3143you debug several programs simultaneously on different remote systems.
3144In the most general case, you can have multiple threads of execution
3145in each of multiple processes, launched from multiple executables,
3146running on different machines.
b77209e0
PA
3147
3148@cindex inferior
3149@value{GDBN} represents the state of each program execution with an
3150object called an @dfn{inferior}. An inferior typically corresponds to
3151a process, but is more general and applies also to targets that do not
3152have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
3153may be retained after a process exits. Inferiors have unique
3154identifiers that are different from process ids. Usually each
3155inferior will also have its own distinct address space, although some
3156embedded targets may have several inferiors running in different parts
3157of a single address space. Each inferior may in turn have multiple
3158threads running in it.
b77209e0 3159
6c95b8df
PA
3160To find out what inferiors exist at any moment, use @w{@code{info
3161inferiors}}:
b77209e0
PA
3162
3163@table @code
a3c25011 3164@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
3165@item info inferiors
3166Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
3167By default all inferiors are printed, but the argument @var{id}@dots{}
3168-- a space separated list of inferior numbers -- can be used to limit
3169the display to just the requested inferiors.
3a1ff0b6
PA
3170
3171@value{GDBN} displays for each inferior (in this order):
3172
3173@enumerate
3174@item
3175the inferior number assigned by @value{GDBN}
3176
3177@item
3178the target system's inferior identifier
6c95b8df 3179
65c574f6
PA
3180@item
3181the target connection the inferior is bound to, including the unique
3182connection number assigned by @value{GDBN}, and the protocol used by
3183the connection.
3184
6c95b8df
PA
3185@item
3186the name of the executable the inferior is running.
3187
3a1ff0b6
PA
3188@end enumerate
3189
3190@noindent
3191An asterisk @samp{*} preceding the @value{GDBN} inferior number
3192indicates the current inferior.
3193
3194For example,
2277426b 3195@end table
3a1ff0b6
PA
3196@c end table here to get a little more width for example
3197
3198@smallexample
3199(@value{GDBP}) info inferiors
65c574f6
PA
3200 Num Description Connection Executable
3201* 1 process 3401 1 (native) goodbye
3202 2 process 2307 2 (extended-remote host:10000) hello
3203@end smallexample
3204
3205To find out what open target connections exist at any moment, use
3206@w{@code{info connections}}:
3207
3208@table @code
3209@kindex info connections [ @var{id}@dots{} ]
3210@item info connections
3211Print a list of all open target connections currently being managed by
3212@value{GDBN}. By default all connections are printed, but the
3213argument @var{id}@dots{} -- a space separated list of connections
3214numbers -- can be used to limit the display to just the requested
3215connections.
3216
3217@value{GDBN} displays for each connection (in this order):
3218
3219@enumerate
3220@item
3221the connection number assigned by @value{GDBN}.
3222
3223@item
3224the protocol used by the connection.
3225
3226@item
3227a textual description of the protocol used by the connection.
3228
3229@end enumerate
3230
3231@noindent
3232An asterisk @samp{*} preceding the connection number indicates the
3233connection of the current inferior.
3234
3235For example,
3236@end table
3237@c end table here to get a little more width for example
3238
3239@smallexample
3240(@value{GDBP}) info connections
3241 Num What Description
3242* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3243 2 native Native process
3244 3 core Local core dump file
3a1ff0b6 3245@end smallexample
2277426b
PA
3246
3247To switch focus between inferiors, use the @code{inferior} command:
3248
3249@table @code
3a1ff0b6
PA
3250@kindex inferior @var{infno}
3251@item inferior @var{infno}
3252Make inferior number @var{infno} the current inferior. The argument
3253@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3254in the first field of the @samp{info inferiors} display.
2277426b
PA
3255@end table
3256
e3940304
PA
3257@vindex $_inferior@r{, convenience variable}
3258The debugger convenience variable @samp{$_inferior} contains the
3259number of the current inferior. You may find this useful in writing
3260breakpoint conditional expressions, command scripts, and so forth.
3261@xref{Convenience Vars,, Convenience Variables}, for general
3262information on convenience variables.
6c95b8df
PA
3263
3264You can get multiple executables into a debugging session via the
3265@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3266systems @value{GDBN} can add inferiors to the debug session
3267automatically by following calls to @code{fork} and @code{exec}. To
3268remove inferiors from the debugging session use the
af624141 3269@w{@code{remove-inferiors}} command.
6c95b8df
PA
3270
3271@table @code
3272@kindex add-inferior
65c574f6 3273@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3274Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3275executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3276the inferiors begins empty, with no program. You can still assign or
3277change the program assigned to the inferior at any time by using the
3278@code{file} command with the executable name as its argument.
3279
65c574f6
PA
3280By default, the new inferior begins connected to the same target
3281connection as the current inferior. For example, if the current
3282inferior was connected to @code{gdbserver} with @code{target remote},
3283then the new inferior will be connected to the same @code{gdbserver}
3284instance. The @samp{-no-connection} option starts the new inferior
3285with no connection yet. You can then for example use the @code{target
3286remote} command to connect to some other @code{gdbserver} instance,
3287use @code{run} to spawn a local program, etc.
3288
6c95b8df
PA
3289@kindex clone-inferior
3290@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3291Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3292@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3293number of the current inferior. This is a convenient command when you
3294want to run another instance of the inferior you are debugging.
3295
3296@smallexample
3297(@value{GDBP}) info inferiors
65c574f6
PA
3298 Num Description Connection Executable
3299* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3300(@value{GDBP}) clone-inferior
3301Added inferior 2.
33021 inferiors added.
3303(@value{GDBP}) info inferiors
65c574f6
PA
3304 Num Description Connection Executable
3305* 1 process 29964 1 (native) helloworld
3306 2 <null> 1 (native) helloworld
6c95b8df
PA
3307@end smallexample
3308
3309You can now simply switch focus to inferior 2 and run it.
3310
af624141
MS
3311@kindex remove-inferiors
3312@item remove-inferiors @var{infno}@dots{}
3313Removes the inferior or inferiors @var{infno}@dots{}. It is not
3314possible to remove an inferior that is running with this command. For
3315those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3316
3317@end table
3318
3319To quit debugging one of the running inferiors that is not the current
3320inferior, you can either detach from it by using the @w{@code{detach
3321inferior}} command (allowing it to run independently), or kill it
af624141 3322using the @w{@code{kill inferiors}} command:
2277426b
PA
3323
3324@table @code
af624141
MS
3325@kindex detach inferiors @var{infno}@dots{}
3326@item detach inferior @var{infno}@dots{}
3327Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3328inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3329still stays on the list of inferiors shown by @code{info inferiors},
3330but its Description will show @samp{<null>}.
3331
3332@kindex kill inferiors @var{infno}@dots{}
3333@item kill inferiors @var{infno}@dots{}
3334Kill the inferior or inferiors identified by @value{GDBN} inferior
3335number(s) @var{infno}@dots{}. Note that the inferior's entry still
3336stays on the list of inferiors shown by @code{info inferiors}, but its
3337Description will show @samp{<null>}.
2277426b
PA
3338@end table
3339
6c95b8df 3340After the successful completion of a command such as @code{detach},
af624141 3341@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3342a normal process exit, the inferior is still valid and listed with
3343@code{info inferiors}, ready to be restarted.
3344
3345
2277426b
PA
3346To be notified when inferiors are started or exit under @value{GDBN}'s
3347control use @w{@code{set print inferior-events}}:
b77209e0 3348
2277426b 3349@table @code
b77209e0
PA
3350@kindex set print inferior-events
3351@cindex print messages on inferior start and exit
3352@item set print inferior-events
3353@itemx set print inferior-events on
3354@itemx set print inferior-events off
3355The @code{set print inferior-events} command allows you to enable or
3356disable printing of messages when @value{GDBN} notices that new
3357inferiors have started or that inferiors have exited or have been
3358detached. By default, these messages will not be printed.
3359
3360@kindex show print inferior-events
3361@item show print inferior-events
3362Show whether messages will be printed when @value{GDBN} detects that
3363inferiors have started, exited or have been detached.
3364@end table
3365
6c95b8df
PA
3366Many commands will work the same with multiple programs as with a
3367single program: e.g., @code{print myglobal} will simply display the
3368value of @code{myglobal} in the current inferior.
3369
3370
6b92c0d3 3371Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3372get more info about the relationship of inferiors, programs, address
3373spaces in a debug session. You can do that with the @w{@code{maint
3374info program-spaces}} command.
3375
3376@table @code
3377@kindex maint info program-spaces
3378@item maint info program-spaces
3379Print a list of all program spaces currently being managed by
3380@value{GDBN}.
3381
3382@value{GDBN} displays for each program space (in this order):
3383
3384@enumerate
3385@item
3386the program space number assigned by @value{GDBN}
3387
3388@item
3389the name of the executable loaded into the program space, with e.g.,
3390the @code{file} command.
3391
3392@end enumerate
3393
3394@noindent
3395An asterisk @samp{*} preceding the @value{GDBN} program space number
3396indicates the current program space.
3397
3398In addition, below each program space line, @value{GDBN} prints extra
3399information that isn't suitable to display in tabular form. For
3400example, the list of inferiors bound to the program space.
3401
3402@smallexample
3403(@value{GDBP}) maint info program-spaces
3404 Id Executable
b05b1202 3405* 1 hello
6c95b8df
PA
3406 2 goodbye
3407 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3408@end smallexample
3409
3410Here we can see that no inferior is running the program @code{hello},
3411while @code{process 21561} is running the program @code{goodbye}. On
3412some targets, it is possible that multiple inferiors are bound to the
3413same program space. The most common example is that of debugging both
3414the parent and child processes of a @code{vfork} call. For example,
3415
3416@smallexample
3417(@value{GDBP}) maint info program-spaces
3418 Id Executable
3419* 1 vfork-test
3420 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3421@end smallexample
3422
3423Here, both inferior 2 and inferior 1 are running in the same program
3424space as a result of inferior 1 having executed a @code{vfork} call.
3425@end table
3426
6d2ebf8b 3427@node Threads
79a6e687 3428@section Debugging Programs with Multiple Threads
c906108c
SS
3429
3430@cindex threads of execution
3431@cindex multiple threads
3432@cindex switching threads
b1236ac3 3433In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3434may have more than one @dfn{thread} of execution. The precise semantics
3435of threads differ from one operating system to another, but in general
3436the threads of a single program are akin to multiple processes---except
3437that they share one address space (that is, they can all examine and
3438modify the same variables). On the other hand, each thread has its own
3439registers and execution stack, and perhaps private memory.
3440
3441@value{GDBN} provides these facilities for debugging multi-thread
3442programs:
3443
3444@itemize @bullet
3445@item automatic notification of new threads
5d5658a1 3446@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3447@item @samp{info threads}, a command to inquire about existing threads
0a232300 3448@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3449a command to apply a command to a list of threads
3450@item thread-specific breakpoints
93815fbf
VP
3451@item @samp{set print thread-events}, which controls printing of
3452messages on thread start and exit.
17a37d48
PP
3453@item @samp{set libthread-db-search-path @var{path}}, which lets
3454the user specify which @code{libthread_db} to use if the default choice
3455isn't compatible with the program.
c906108c
SS
3456@end itemize
3457
c906108c
SS
3458@cindex focus of debugging
3459@cindex current thread
3460The @value{GDBN} thread debugging facility allows you to observe all
3461threads while your program runs---but whenever @value{GDBN} takes
3462control, one thread in particular is always the focus of debugging.
3463This thread is called the @dfn{current thread}. Debugging commands show
3464program information from the perspective of the current thread.
3465
41afff9a 3466@cindex @code{New} @var{systag} message
c906108c
SS
3467@cindex thread identifier (system)
3468@c FIXME-implementors!! It would be more helpful if the [New...] message
3469@c included GDB's numeric thread handle, so you could just go to that
3470@c thread without first checking `info threads'.
3471Whenever @value{GDBN} detects a new thread in your program, it displays
3472the target system's identification for the thread with a message in the
697aa1b7 3473form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3474whose form varies depending on the particular system. For example, on
8807d78b 3475@sc{gnu}/Linux, you might see
c906108c 3476
474c8240 3477@smallexample
08e796bc 3478[New Thread 0x41e02940 (LWP 25582)]
474c8240 3479@end smallexample
c906108c
SS
3480
3481@noindent
b1236ac3 3482when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3483the @var{systag} is simply something like @samp{process 368}, with no
3484further qualifier.
3485
3486@c FIXME!! (1) Does the [New...] message appear even for the very first
3487@c thread of a program, or does it only appear for the
6ca652b0 3488@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3489@c program?
3490@c (2) *Is* there necessarily a first thread always? Or do some
3491@c multithread systems permit starting a program with multiple
5d161b24 3492@c threads ab initio?
c906108c 3493
5d5658a1
PA
3494@anchor{thread numbers}
3495@cindex thread number, per inferior
c906108c 3496@cindex thread identifier (GDB)
5d5658a1
PA
3497For debugging purposes, @value{GDBN} associates its own thread number
3498---always a single integer---with each thread of an inferior. This
3499number is unique between all threads of an inferior, but not unique
3500between threads of different inferiors.
3501
3502@cindex qualified thread ID
3503You can refer to a given thread in an inferior using the qualified
3504@var{inferior-num}.@var{thread-num} syntax, also known as
3505@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3506number and @var{thread-num} being the thread number of the given
3507inferior. For example, thread @code{2.3} refers to thread number 3 of
3508inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3509then @value{GDBN} infers you're referring to a thread of the current
3510inferior.
3511
3512Until you create a second inferior, @value{GDBN} does not show the
3513@var{inferior-num} part of thread IDs, even though you can always use
3514the full @var{inferior-num}.@var{thread-num} form to refer to threads
3515of inferior 1, the initial inferior.
3516
3517@anchor{thread ID lists}
3518@cindex thread ID lists
3519Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3520argument. A list element can be:
3521
3522@enumerate
3523@item
3524A thread ID as shown in the first field of the @samp{info threads}
3525display, with or without an inferior qualifier. E.g., @samp{2.1} or
3526@samp{1}.
3527
3528@item
3529A range of thread numbers, again with or without an inferior
3530qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3531@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3532
3533@item
3534All threads of an inferior, specified with a star wildcard, with or
3535without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3536@samp{1.*}) or @code{*}. The former refers to all threads of the
3537given inferior, and the latter form without an inferior qualifier
3538refers to all threads of the current inferior.
3539
3540@end enumerate
3541
3542For example, if the current inferior is 1, and inferior 7 has one
3543thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3544includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
35457 to 9 of inferior 6 and all threads of inferior 7. That is, in
3546expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
35477.1}.
3548
5d5658a1
PA
3549
3550@anchor{global thread numbers}
3551@cindex global thread number
3552@cindex global thread identifier (GDB)
3553In addition to a @emph{per-inferior} number, each thread is also
3554assigned a unique @emph{global} number, also known as @dfn{global
3555thread ID}, a single integer. Unlike the thread number component of
3556the thread ID, no two threads have the same global ID, even when
3557you're debugging multiple inferiors.
c906108c 3558
f4f4330e
PA
3559From @value{GDBN}'s perspective, a process always has at least one
3560thread. In other words, @value{GDBN} assigns a thread number to the
3561program's ``main thread'' even if the program is not multi-threaded.
3562
5d5658a1 3563@vindex $_thread@r{, convenience variable}
663f6d42
PA
3564@vindex $_gthread@r{, convenience variable}
3565The debugger convenience variables @samp{$_thread} and
3566@samp{$_gthread} contain, respectively, the per-inferior thread number
3567and the global thread number of the current thread. You may find this
5d5658a1
PA
3568useful in writing breakpoint conditional expressions, command scripts,
3569and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3570general information on convenience variables.
3571
f303dbd6
PA
3572If @value{GDBN} detects the program is multi-threaded, it augments the
3573usual message about stopping at a breakpoint with the ID and name of
3574the thread that hit the breakpoint.
3575
3576@smallexample
3577Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3578@end smallexample
3579
3580Likewise when the program receives a signal:
3581
3582@smallexample
3583Thread 1 "main" received signal SIGINT, Interrupt.
3584@end smallexample
3585
c906108c
SS
3586@table @code
3587@kindex info threads
5d5658a1
PA
3588@item info threads @r{[}@var{thread-id-list}@r{]}
3589
3590Display information about one or more threads. With no arguments
3591displays information about all threads. You can specify the list of
3592threads that you want to display using the thread ID list syntax
3593(@pxref{thread ID lists}).
3594
60f98dde 3595@value{GDBN} displays for each thread (in this order):
c906108c
SS
3596
3597@enumerate
09d4efe1 3598@item
5d5658a1 3599the per-inferior thread number assigned by @value{GDBN}
c906108c 3600
c84f6bbf
PA
3601@item
3602the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3603option was specified
3604
09d4efe1
EZ
3605@item
3606the target system's thread identifier (@var{systag})
c906108c 3607
4694da01
TT
3608@item
3609the thread's name, if one is known. A thread can either be named by
3610the user (see @code{thread name}, below), or, in some cases, by the
3611program itself.
3612
09d4efe1
EZ
3613@item
3614the current stack frame summary for that thread
c906108c
SS
3615@end enumerate
3616
3617@noindent
3618An asterisk @samp{*} to the left of the @value{GDBN} thread number
3619indicates the current thread.
3620
5d161b24 3621For example,
c906108c
SS
3622@end table
3623@c end table here to get a little more width for example
3624
3625@smallexample
3626(@value{GDBP}) info threads
e56d7f1e 3627 Id Target Id Frame
c0ecb95f 3628* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3629 2 process 35 thread 23 0x34e5 in sigpause ()
3630 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3631 at threadtest.c:68
3632@end smallexample
53a5351d 3633
5d5658a1
PA
3634If you're debugging multiple inferiors, @value{GDBN} displays thread
3635IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3636Otherwise, only @var{thread-num} is shown.
3637
3638If you specify the @samp{-gid} option, @value{GDBN} displays a column
3639indicating each thread's global thread ID:
5d5658a1
PA
3640
3641@smallexample
3642(@value{GDBP}) info threads
c84f6bbf
PA
3643 Id GId Target Id Frame
3644 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3645 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3646 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3647* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3648@end smallexample
3649
c45da7e6
EZ
3650On Solaris, you can display more information about user threads with a
3651Solaris-specific command:
3652
3653@table @code
3654@item maint info sol-threads
3655@kindex maint info sol-threads
3656@cindex thread info (Solaris)
3657Display info on Solaris user threads.
3658@end table
3659
c906108c 3660@table @code
5d5658a1
PA
3661@kindex thread @var{thread-id}
3662@item thread @var{thread-id}
3663Make thread ID @var{thread-id} the current thread. The command
3664argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3665the first field of the @samp{info threads} display, with or without an
3666inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3667
3668@value{GDBN} responds by displaying the system identifier of the
3669thread you selected, and its current stack frame summary:
c906108c
SS
3670
3671@smallexample
c906108c 3672(@value{GDBP}) thread 2
13fd8b81
TT
3673[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3674#0 some_function (ignore=0x0) at example.c:8
36758 printf ("hello\n");
c906108c
SS
3676@end smallexample
3677
3678@noindent
3679As with the @samp{[New @dots{}]} message, the form of the text after
3680@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3681threads.
c906108c 3682
3345721a 3683@anchor{thread apply all}
9c16f35a 3684@kindex thread apply
638ac427 3685@cindex apply command to several threads
0a232300 3686@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3687The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3688@var{command} to one or more threads. Specify the threads that you
3689want affected using the thread ID list syntax (@pxref{thread ID
3690lists}), or specify @code{all} to apply to all threads. To apply a
3691command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3692@var{command}}. To apply a command to all threads in ascending order,
3693type @kbd{thread apply all -ascending @var{command}}.
3694
0a232300
PW
3695The @var{flag} arguments control what output to produce and how to handle
3696errors raised when applying @var{command} to a thread. @var{flag}
3697must start with a @code{-} directly followed by one letter in
3698@code{qcs}. If several flags are provided, they must be given
3699individually, such as @code{-c -q}.
3700
3701By default, @value{GDBN} displays some thread information before the
3702output produced by @var{command}, and an error raised during the
3703execution of a @var{command} will abort @code{thread apply}. The
3704following flags can be used to fine-tune this behavior:
3705
3706@table @code
3707@item -c
3708The flag @code{-c}, which stands for @samp{continue}, causes any
3709errors in @var{command} to be displayed, and the execution of
3710@code{thread apply} then continues.
3711@item -s
3712The flag @code{-s}, which stands for @samp{silent}, causes any errors
3713or empty output produced by a @var{command} to be silently ignored.
3714That is, the execution continues, but the thread information and errors
3715are not printed.
3716@item -q
3717The flag @code{-q} (@samp{quiet}) disables printing the thread
3718information.
3719@end table
3720
3721Flags @code{-c} and @code{-s} cannot be used together.
3722
3723@kindex taas
3724@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3725@item taas [@var{option}]@dots{} @var{command}
3726Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3727Applies @var{command} on all threads, ignoring errors and empty output.
3728
3345721a
PA
3729The @code{taas} command accepts the same options as the @code{thread
3730apply all} command. @xref{thread apply all}.
3731
0a232300
PW
3732@kindex tfaas
3733@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3734@item tfaas [@var{option}]@dots{} @var{command}
3735Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3736Applies @var{command} on all frames of all threads, ignoring errors
3737and empty output. Note that the flag @code{-s} is specified twice:
3738The first @code{-s} ensures that @code{thread apply} only shows the thread
3739information of the threads for which @code{frame apply} produces
3740some output. The second @code{-s} is needed to ensure that @code{frame
3741apply} shows the frame information of a frame only if the
3742@var{command} successfully produced some output.
3743
3744It can for example be used to print a local variable or a function
3745argument without knowing the thread or frame where this variable or argument
3746is, using:
3747@smallexample
3748(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3749@end smallexample
3750
3345721a 3751The @code{tfaas} command accepts the same options as the @code{frame
ed788fee 3752apply} command. @xref{Frame Apply,,frame apply}.
93815fbf 3753
4694da01
TT
3754@kindex thread name
3755@cindex name a thread
3756@item thread name [@var{name}]
3757This command assigns a name to the current thread. If no argument is
3758given, any existing user-specified name is removed. The thread name
3759appears in the @samp{info threads} display.
3760
3761On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3762determine the name of the thread as given by the OS. On these
3763systems, a name specified with @samp{thread name} will override the
3764system-give name, and removing the user-specified name will cause
3765@value{GDBN} to once again display the system-specified name.
3766
60f98dde
MS
3767@kindex thread find
3768@cindex search for a thread
3769@item thread find [@var{regexp}]
3770Search for and display thread ids whose name or @var{systag}
3771matches the supplied regular expression.
3772
3773As well as being the complement to the @samp{thread name} command,
3774this command also allows you to identify a thread by its target
3775@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3776is the LWP id.
3777
3778@smallexample
3779(@value{GDBN}) thread find 26688
3780Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3781(@value{GDBN}) info thread 4
3782 Id Target Id Frame
3783 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3784@end smallexample
3785
93815fbf
VP
3786@kindex set print thread-events
3787@cindex print messages on thread start and exit
3788@item set print thread-events
3789@itemx set print thread-events on
3790@itemx set print thread-events off
3791The @code{set print thread-events} command allows you to enable or
3792disable printing of messages when @value{GDBN} notices that new threads have
3793started or that threads have exited. By default, these messages will
3794be printed if detection of these events is supported by the target.
3795Note that these messages cannot be disabled on all targets.
3796
3797@kindex show print thread-events
3798@item show print thread-events
3799Show whether messages will be printed when @value{GDBN} detects that threads
3800have started and exited.
c906108c
SS
3801@end table
3802
79a6e687 3803@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3804more information about how @value{GDBN} behaves when you stop and start
3805programs with multiple threads.
3806
79a6e687 3807@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3808watchpoints in programs with multiple threads.
c906108c 3809
bf88dd68 3810@anchor{set libthread-db-search-path}
17a37d48
PP
3811@table @code
3812@kindex set libthread-db-search-path
3813@cindex search path for @code{libthread_db}
3814@item set libthread-db-search-path @r{[}@var{path}@r{]}
3815If this variable is set, @var{path} is a colon-separated list of
3816directories @value{GDBN} will use to search for @code{libthread_db}.
3817If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3818its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3819Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3820macro.
17a37d48
PP
3821
3822On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3823@code{libthread_db} library to obtain information about threads in the
3824inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3825to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3826specific thread debugging library loading is enabled
3827by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3828
3829A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3830refers to the default system directories that are
bf88dd68
JK
3831normally searched for loading shared libraries. The @samp{$sdir} entry
3832is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3833(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3834
3835A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3836refers to the directory from which @code{libpthread}
3837was loaded in the inferior process.
17a37d48
PP
3838
3839For any @code{libthread_db} library @value{GDBN} finds in above directories,
3840@value{GDBN} attempts to initialize it with the current inferior process.
3841If this initialization fails (which could happen because of a version
3842mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3843will unload @code{libthread_db}, and continue with the next directory.
3844If none of @code{libthread_db} libraries initialize successfully,
3845@value{GDBN} will issue a warning and thread debugging will be disabled.
3846
3847Setting @code{libthread-db-search-path} is currently implemented
3848only on some platforms.
3849
3850@kindex show libthread-db-search-path
3851@item show libthread-db-search-path
3852Display current libthread_db search path.
02d868e8
PP
3853
3854@kindex set debug libthread-db
3855@kindex show debug libthread-db
3856@cindex debugging @code{libthread_db}
3857@item set debug libthread-db
3858@itemx show debug libthread-db
3859Turns on or off display of @code{libthread_db}-related events.
3860Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3861@end table
3862
6c95b8df
PA
3863@node Forks
3864@section Debugging Forks
c906108c
SS
3865
3866@cindex fork, debugging programs which call
3867@cindex multiple processes
3868@cindex processes, multiple
53a5351d
JM
3869On most systems, @value{GDBN} has no special support for debugging
3870programs which create additional processes using the @code{fork}
3871function. When a program forks, @value{GDBN} will continue to debug the
3872parent process and the child process will run unimpeded. If you have
3873set a breakpoint in any code which the child then executes, the child
3874will get a @code{SIGTRAP} signal which (unless it catches the signal)
3875will cause it to terminate.
c906108c
SS
3876
3877However, if you want to debug the child process there is a workaround
3878which isn't too painful. Put a call to @code{sleep} in the code which
3879the child process executes after the fork. It may be useful to sleep
3880only if a certain environment variable is set, or a certain file exists,
3881so that the delay need not occur when you don't want to run @value{GDBN}
3882on the child. While the child is sleeping, use the @code{ps} program to
3883get its process ID. Then tell @value{GDBN} (a new invocation of
3884@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3885the child process (@pxref{Attach}). From that point on you can debug
c906108c 3886the child process just like any other process which you attached to.
c906108c 3887
b1236ac3
PA
3888On some systems, @value{GDBN} provides support for debugging programs
3889that create additional processes using the @code{fork} or @code{vfork}
3890functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3891with kernel version 2.5.46 and later.
c906108c 3892
19d9d4ef
DB
3893The fork debugging commands are supported in native mode and when
3894connected to @code{gdbserver} in either @code{target remote} mode or
3895@code{target extended-remote} mode.
0d71eef5 3896
c906108c
SS
3897By default, when a program forks, @value{GDBN} will continue to debug
3898the parent process and the child process will run unimpeded.
3899
3900If you want to follow the child process instead of the parent process,
3901use the command @w{@code{set follow-fork-mode}}.
3902
3903@table @code
3904@kindex set follow-fork-mode
3905@item set follow-fork-mode @var{mode}
3906Set the debugger response to a program call of @code{fork} or
3907@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3908process. The @var{mode} argument can be:
c906108c
SS
3909
3910@table @code
3911@item parent
3912The original process is debugged after a fork. The child process runs
2df3850c 3913unimpeded. This is the default.
c906108c
SS
3914
3915@item child
3916The new process is debugged after a fork. The parent process runs
3917unimpeded.
3918
c906108c
SS
3919@end table
3920
9c16f35a 3921@kindex show follow-fork-mode
c906108c 3922@item show follow-fork-mode
2df3850c 3923Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3924@end table
3925
5c95884b
MS
3926@cindex debugging multiple processes
3927On Linux, if you want to debug both the parent and child processes, use the
3928command @w{@code{set detach-on-fork}}.
3929
3930@table @code
3931@kindex set detach-on-fork
3932@item set detach-on-fork @var{mode}
3933Tells gdb whether to detach one of the processes after a fork, or
3934retain debugger control over them both.
3935
3936@table @code
3937@item on
3938The child process (or parent process, depending on the value of
3939@code{follow-fork-mode}) will be detached and allowed to run
3940independently. This is the default.
3941
3942@item off
3943Both processes will be held under the control of @value{GDBN}.
3944One process (child or parent, depending on the value of
3945@code{follow-fork-mode}) is debugged as usual, while the other
3946is held suspended.
3947
3948@end table
3949
11310833
NR
3950@kindex show detach-on-fork
3951@item show detach-on-fork
3952Show whether detach-on-fork mode is on/off.
5c95884b
MS
3953@end table
3954
2277426b
PA
3955If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3956will retain control of all forked processes (including nested forks).
3957You can list the forked processes under the control of @value{GDBN} by
3958using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3959to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3960Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3961
3962To quit debugging one of the forked processes, you can either detach
af624141
MS
3963from it by using the @w{@code{detach inferiors}} command (allowing it
3964to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3965command. @xref{Inferiors Connections and Programs, ,Debugging
3966Multiple Inferiors Connections and Programs}.
5c95884b 3967
c906108c
SS
3968If you ask to debug a child process and a @code{vfork} is followed by an
3969@code{exec}, @value{GDBN} executes the new target up to the first
3970breakpoint in the new target. If you have a breakpoint set on
3971@code{main} in your original program, the breakpoint will also be set on
3972the child process's @code{main}.
3973
2277426b
PA
3974On some systems, when a child process is spawned by @code{vfork}, you
3975cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3976
3977If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3978call executes, the new target restarts. To restart the parent
3979process, use the @code{file} command with the parent executable name
3980as its argument. By default, after an @code{exec} call executes,
3981@value{GDBN} discards the symbols of the previous executable image.
3982You can change this behaviour with the @w{@code{set follow-exec-mode}}
3983command.
3984
3985@table @code
3986@kindex set follow-exec-mode
3987@item set follow-exec-mode @var{mode}
3988
3989Set debugger response to a program call of @code{exec}. An
3990@code{exec} call replaces the program image of a process.
3991
3992@code{follow-exec-mode} can be:
3993
3994@table @code
3995@item new
3996@value{GDBN} creates a new inferior and rebinds the process to this
3997new inferior. The program the process was running before the
3998@code{exec} call can be restarted afterwards by restarting the
3999original inferior.
4000
4001For example:
4002
4003@smallexample
4004(@value{GDBP}) info inferiors
4005(gdb) info inferior
4006 Id Description Executable
4007* 1 <null> prog1
4008(@value{GDBP}) run
4009process 12020 is executing new program: prog2
4010Program exited normally.
4011(@value{GDBP}) info inferiors
4012 Id Description Executable
c0ecb95f 4013 1 <null> prog1
b05b1202 4014* 2 <null> prog2
6c95b8df
PA
4015@end smallexample
4016
4017@item same
4018@value{GDBN} keeps the process bound to the same inferior. The new
4019executable image replaces the previous executable loaded in the
4020inferior. Restarting the inferior after the @code{exec} call, with
4021e.g., the @code{run} command, restarts the executable the process was
4022running after the @code{exec} call. This is the default mode.
4023
4024For example:
4025
4026@smallexample
4027(@value{GDBP}) info inferiors
4028 Id Description Executable
4029* 1 <null> prog1
4030(@value{GDBP}) run
4031process 12020 is executing new program: prog2
4032Program exited normally.
4033(@value{GDBP}) info inferiors
4034 Id Description Executable
4035* 1 <null> prog2
4036@end smallexample
4037
4038@end table
4039@end table
c906108c 4040
19d9d4ef
DB
4041@code{follow-exec-mode} is supported in native mode and
4042@code{target extended-remote} mode.
4043
c906108c
SS
4044You can use the @code{catch} command to make @value{GDBN} stop whenever
4045a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 4046Catchpoints, ,Setting Catchpoints}.
c906108c 4047
5c95884b 4048@node Checkpoint/Restart
79a6e687 4049@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
4050
4051@cindex checkpoint
4052@cindex restart
4053@cindex bookmark
4054@cindex snapshot of a process
4055@cindex rewind program state
4056
4057On certain operating systems@footnote{Currently, only
4058@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4059program's state, called a @dfn{checkpoint}, and come back to it
4060later.
4061
4062Returning to a checkpoint effectively undoes everything that has
4063happened in the program since the @code{checkpoint} was saved. This
4064includes changes in memory, registers, and even (within some limits)
4065system state. Effectively, it is like going back in time to the
4066moment when the checkpoint was saved.
4067
4068Thus, if you're stepping thru a program and you think you're
4069getting close to the point where things go wrong, you can save
4070a checkpoint. Then, if you accidentally go too far and miss
4071the critical statement, instead of having to restart your program
4072from the beginning, you can just go back to the checkpoint and
4073start again from there.
4074
4075This can be especially useful if it takes a lot of time or
4076steps to reach the point where you think the bug occurs.
4077
4078To use the @code{checkpoint}/@code{restart} method of debugging:
4079
4080@table @code
4081@kindex checkpoint
4082@item checkpoint
4083Save a snapshot of the debugged program's current execution state.
4084The @code{checkpoint} command takes no arguments, but each checkpoint
4085is assigned a small integer id, similar to a breakpoint id.
4086
4087@kindex info checkpoints
4088@item info checkpoints
4089List the checkpoints that have been saved in the current debugging
4090session. For each checkpoint, the following information will be
4091listed:
4092
4093@table @code
4094@item Checkpoint ID
4095@item Process ID
4096@item Code Address
4097@item Source line, or label
4098@end table
4099
4100@kindex restart @var{checkpoint-id}
4101@item restart @var{checkpoint-id}
4102Restore the program state that was saved as checkpoint number
4103@var{checkpoint-id}. All program variables, registers, stack frames
4104etc.@: will be returned to the values that they had when the checkpoint
4105was saved. In essence, gdb will ``wind back the clock'' to the point
4106in time when the checkpoint was saved.
4107
4108Note that breakpoints, @value{GDBN} variables, command history etc.
4109are not affected by restoring a checkpoint. In general, a checkpoint
4110only restores things that reside in the program being debugged, not in
4111the debugger.
4112
b8db102d
MS
4113@kindex delete checkpoint @var{checkpoint-id}
4114@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
4115Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4116
4117@end table
4118
4119Returning to a previously saved checkpoint will restore the user state
4120of the program being debugged, plus a significant subset of the system
4121(OS) state, including file pointers. It won't ``un-write'' data from
4122a file, but it will rewind the file pointer to the previous location,
4123so that the previously written data can be overwritten. For files
4124opened in read mode, the pointer will also be restored so that the
4125previously read data can be read again.
4126
4127Of course, characters that have been sent to a printer (or other
4128external device) cannot be ``snatched back'', and characters received
4129from eg.@: a serial device can be removed from internal program buffers,
4130but they cannot be ``pushed back'' into the serial pipeline, ready to
4131be received again. Similarly, the actual contents of files that have
4132been changed cannot be restored (at this time).
4133
4134However, within those constraints, you actually can ``rewind'' your
4135program to a previously saved point in time, and begin debugging it
4136again --- and you can change the course of events so as to debug a
4137different execution path this time.
4138
4139@cindex checkpoints and process id
4140Finally, there is one bit of internal program state that will be
4141different when you return to a checkpoint --- the program's process
4142id. Each checkpoint will have a unique process id (or @var{pid}),
4143and each will be different from the program's original @var{pid}.
4144If your program has saved a local copy of its process id, this could
4145potentially pose a problem.
4146
79a6e687 4147@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
4148
4149On some systems such as @sc{gnu}/Linux, address space randomization
4150is performed on new processes for security reasons. This makes it
4151difficult or impossible to set a breakpoint, or watchpoint, on an
4152absolute address if you have to restart the program, since the
4153absolute location of a symbol will change from one execution to the
4154next.
4155
4156A checkpoint, however, is an @emph{identical} copy of a process.
4157Therefore if you create a checkpoint at (eg.@:) the start of main,
4158and simply return to that checkpoint instead of restarting the
4159process, you can avoid the effects of address randomization and
4160your symbols will all stay in the same place.
4161
6d2ebf8b 4162@node Stopping
c906108c
SS
4163@chapter Stopping and Continuing
4164
4165The principal purposes of using a debugger are so that you can stop your
4166program before it terminates; or so that, if your program runs into
4167trouble, you can investigate and find out why.
4168
7a292a7a
SS
4169Inside @value{GDBN}, your program may stop for any of several reasons,
4170such as a signal, a breakpoint, or reaching a new line after a
4171@value{GDBN} command such as @code{step}. You may then examine and
4172change variables, set new breakpoints or remove old ones, and then
4173continue execution. Usually, the messages shown by @value{GDBN} provide
4174ample explanation of the status of your program---but you can also
4175explicitly request this information at any time.
c906108c
SS
4176
4177@table @code
4178@kindex info program
4179@item info program
4180Display information about the status of your program: whether it is
7a292a7a 4181running or not, what process it is, and why it stopped.
c906108c
SS
4182@end table
4183
4184@menu
4185* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4186* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4187* Skipping Over Functions and Files::
4188 Skipping over functions and files
c906108c 4189* Signals:: Signals
c906108c 4190* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4191@end menu
4192
6d2ebf8b 4193@node Breakpoints
79a6e687 4194@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4195
4196@cindex breakpoints
4197A @dfn{breakpoint} makes your program stop whenever a certain point in
4198the program is reached. For each breakpoint, you can add conditions to
4199control in finer detail whether your program stops. You can set
4200breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4201Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4202should stop by line number, function name or exact address in the
4203program.
4204
09d4efe1 4205On some systems, you can set breakpoints in shared libraries before
b1236ac3 4206the executable is run.
c906108c
SS
4207
4208@cindex watchpoints
fd60e0df 4209@cindex data breakpoints
c906108c
SS
4210@cindex memory tracing
4211@cindex breakpoint on memory address
4212@cindex breakpoint on variable modification
4213A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4214when the value of an expression changes. The expression may be a value
0ced0c34 4215of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4216combined by operators, such as @samp{a + b}. This is sometimes called
4217@dfn{data breakpoints}. You must use a different command to set
79a6e687 4218watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4219from that, you can manage a watchpoint like any other breakpoint: you
4220enable, disable, and delete both breakpoints and watchpoints using the
4221same commands.
c906108c
SS
4222
4223You can arrange to have values from your program displayed automatically
4224whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4225Automatic Display}.
c906108c
SS
4226
4227@cindex catchpoints
4228@cindex breakpoint on events
4229A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4230when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4231exception or the loading of a library. As with watchpoints, you use a
4232different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4233Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4234other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4235@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4236
4237@cindex breakpoint numbers
4238@cindex numbers for breakpoints
4239@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4240catchpoint when you create it; these numbers are successive integers
4241starting with one. In many of the commands for controlling various
4242features of breakpoints you use the breakpoint number to say which
4243breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4244@dfn{disabled}; if disabled, it has no effect on your program until you
4245enable it again.
4246
c5394b80 4247@cindex breakpoint ranges
18da0c51 4248@cindex breakpoint lists
c5394b80 4249@cindex ranges of breakpoints
18da0c51
MG
4250@cindex lists of breakpoints
4251Some @value{GDBN} commands accept a space-separated list of breakpoints
4252on which to operate. A list element can be either a single breakpoint number,
4253like @samp{5}, or a range of such numbers, like @samp{5-7}.
4254When a breakpoint list is given to a command, all breakpoints in that list
4255are operated on.
c5394b80 4256
c906108c
SS
4257@menu
4258* Set Breaks:: Setting breakpoints
4259* Set Watchpoints:: Setting watchpoints
4260* Set Catchpoints:: Setting catchpoints
4261* Delete Breaks:: Deleting breakpoints
4262* Disabling:: Disabling breakpoints
4263* Conditions:: Break conditions
4264* Break Commands:: Breakpoint command lists
e7e0cddf 4265* Dynamic Printf:: Dynamic printf
6149aea9 4266* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4267* Static Probe Points:: Listing static probe points
d4f3574e 4268* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4269* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4270@end menu
4271
6d2ebf8b 4272@node Set Breaks
79a6e687 4273@subsection Setting Breakpoints
c906108c 4274
5d161b24 4275@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4276@c consider in particular declaration with/without initialization.
4277@c
4278@c FIXME 2 is there stuff on this already? break at fun start, already init?
4279
4280@kindex break
41afff9a
EZ
4281@kindex b @r{(@code{break})}
4282@vindex $bpnum@r{, convenience variable}
c906108c
SS
4283@cindex latest breakpoint
4284Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4285@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4286number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4287Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4288convenience variables.
4289
c906108c 4290@table @code
2a25a5ba
EZ
4291@item break @var{location}
4292Set a breakpoint at the given @var{location}, which can specify a
4293function name, a line number, or an address of an instruction.
4294(@xref{Specify Location}, for a list of all the possible ways to
4295specify a @var{location}.) The breakpoint will stop your program just
4296before it executes any of the code in the specified @var{location}.
4297
c906108c 4298When using source languages that permit overloading of symbols, such as
2a25a5ba 4299C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4300@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4301that situation.
c906108c 4302
45ac276d 4303It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4304only if a specific thread (@pxref{Thread-Specific Breakpoints})
4305or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4306
c906108c
SS
4307@item break
4308When called without any arguments, @code{break} sets a breakpoint at
4309the next instruction to be executed in the selected stack frame
4310(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4311innermost, this makes your program stop as soon as control
4312returns to that frame. This is similar to the effect of a
4313@code{finish} command in the frame inside the selected frame---except
4314that @code{finish} does not leave an active breakpoint. If you use
4315@code{break} without an argument in the innermost frame, @value{GDBN} stops
4316the next time it reaches the current location; this may be useful
4317inside loops.
4318
4319@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4320least one instruction has been executed. If it did not do this, you
4321would be unable to proceed past a breakpoint without first disabling the
4322breakpoint. This rule applies whether or not the breakpoint already
4323existed when your program stopped.
4324
4325@item break @dots{} if @var{cond}
4326Set a breakpoint with condition @var{cond}; evaluate the expression
4327@var{cond} each time the breakpoint is reached, and stop only if the
4328value is nonzero---that is, if @var{cond} evaluates as true.
4329@samp{@dots{}} stands for one of the possible arguments described
4330above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4331,Break Conditions}, for more information on breakpoint conditions.
c906108c 4332
b5fa468f
TBA
4333The breakpoint may be mapped to multiple locations. If the breakpoint
4334condition @var{cond} is invalid at some but not all of the locations,
4335the locations for which the condition is invalid are disabled. For
4336example, @value{GDBN} reports below that two of the three locations
4337are disabled.
4338
4339@smallexample
4340(@value{GDBP}) break func if a == 10
4341warning: failed to validate condition at location 0x11ce, disabling:
4342 No symbol "a" in current context.
4343warning: failed to validate condition at location 0x11b6, disabling:
4344 No symbol "a" in current context.
4345Breakpoint 1 at 0x11b6: func. (3 locations)
4346@end smallexample
4347
4348Locations that are disabled because of the condition are denoted by an
4349uppercase @code{N} in the output of the @code{info breakpoints}
4350command:
4351
4352@smallexample
4353(@value{GDBP}) info breakpoints
4354Num Type Disp Enb Address What
43551 breakpoint keep y <MULTIPLE>
4356 stop only if a == 10
43571.1 N* 0x00000000000011b6 in ...
43581.2 y 0x00000000000011c2 in ...
43591.3 N* 0x00000000000011ce in ...
4360(*): Breakpoint condition is invalid at this location.
4361@end smallexample
4362
4363If the breakpoint condition @var{cond} is invalid in the context of
4364@emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4365define the breakpoint. For example, if variable @code{foo} is an
4366undefined variable:
4367
4368@smallexample
4369(@value{GDBP}) break func if foo
4370No symbol "foo" in current context.
4371@end smallexample
4372
733d554a
TBA
4373@item break @dots{} -force-condition if @var{cond}
4374There may be cases where the condition @var{cond} is invalid at all
4375the current locations, but the user knows that it will be valid at a
4376future location; for example, because of a library load. In such
4377cases, by using the @code{-force-condition} keyword before @samp{if},
4378@value{GDBN} can be forced to define the breakpoint with the given
4379condition expression instead of refusing it.
4380
4381@smallexample
4382(@value{GDBP}) break func -force-condition if foo
4383warning: failed to validate condition at location 1, disabling:
4384 No symbol "foo" in current context.
4385warning: failed to validate condition at location 2, disabling:
4386 No symbol "foo" in current context.
4387warning: failed to validate condition at location 3, disabling:
4388 No symbol "foo" in current context.
4389Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4390@end smallexample
4391
4392This causes all the present locations where the breakpoint would
4393otherwise be inserted, to be disabled, as seen in the example above.
4394However, if there exist locations at which the condition is valid, the
4395@code{-force-condition} keyword has no effect.
4396
c906108c
SS
4397@kindex tbreak
4398@item tbreak @var{args}
697aa1b7 4399Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4400same as for the @code{break} command, and the breakpoint is set in the same
4401way, but the breakpoint is automatically deleted after the first time your
79a6e687 4402program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4403
c906108c 4404@kindex hbreak
ba04e063 4405@cindex hardware breakpoints
c906108c 4406@item hbreak @var{args}
697aa1b7 4407Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4408@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4409breakpoint requires hardware support and some target hardware may not
4410have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4411debugging, so you can set a breakpoint at an instruction without
4412changing the instruction. This can be used with the new trap-generation
09d4efe1 4413provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4414will generate traps when a program accesses some data or instruction
4415address that is assigned to the debug registers. However the hardware
4416breakpoint registers can take a limited number of breakpoints. For
4417example, on the DSU, only two data breakpoints can be set at a time, and
4418@value{GDBN} will reject this command if more than two are used. Delete
4419or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4420(@pxref{Disabling, ,Disabling Breakpoints}).
4421@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4422For remote targets, you can restrict the number of hardware
4423breakpoints @value{GDBN} will use, see @ref{set remote
4424hardware-breakpoint-limit}.
501eef12 4425
c906108c
SS
4426@kindex thbreak
4427@item thbreak @var{args}
697aa1b7 4428Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4429are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4430the same way. However, like the @code{tbreak} command,
c906108c
SS
4431the breakpoint is automatically deleted after the
4432first time your program stops there. Also, like the @code{hbreak}
5d161b24 4433command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4434may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4435See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4436
4437@kindex rbreak
4438@cindex regular expression
8bd10a10 4439@cindex breakpoints at functions matching a regexp
c45da7e6 4440@cindex set breakpoints in many functions
c906108c 4441@item rbreak @var{regex}
c906108c 4442Set breakpoints on all functions matching the regular expression
11cf8741
JM
4443@var{regex}. This command sets an unconditional breakpoint on all
4444matches, printing a list of all breakpoints it set. Once these
4445breakpoints are set, they are treated just like the breakpoints set with
4446the @code{break} command. You can delete them, disable them, or make
4447them conditional the same way as any other breakpoint.
4448
20813a0b
PW
4449In programs using different languages, @value{GDBN} chooses the syntax
4450to print the list of all breakpoints it sets according to the
4451@samp{set language} value: using @samp{set language auto}
4452(see @ref{Automatically, ,Set Language Automatically}) means to use the
4453language of the breakpoint's function, other values mean to use
4454the manually specified language (see @ref{Manually, ,Set Language Manually}).
4455
11cf8741
JM
4456The syntax of the regular expression is the standard one used with tools
4457like @file{grep}. Note that this is different from the syntax used by
4458shells, so for instance @code{foo*} matches all functions that include
4459an @code{fo} followed by zero or more @code{o}s. There is an implicit
4460@code{.*} leading and trailing the regular expression you supply, so to
4461match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4462
f7dc1244 4463@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4464When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4465breakpoints on overloaded functions that are not members of any special
4466classes.
c906108c 4467
f7dc1244
EZ
4468@cindex set breakpoints on all functions
4469The @code{rbreak} command can be used to set breakpoints in
4470@strong{all} the functions in a program, like this:
4471
4472@smallexample
4473(@value{GDBP}) rbreak .
4474@end smallexample
4475
8bd10a10
CM
4476@item rbreak @var{file}:@var{regex}
4477If @code{rbreak} is called with a filename qualification, it limits
4478the search for functions matching the given regular expression to the
4479specified @var{file}. This can be used, for example, to set breakpoints on
4480every function in a given file:
4481
4482@smallexample
4483(@value{GDBP}) rbreak file.c:.
4484@end smallexample
4485
4486The colon separating the filename qualifier from the regex may
4487optionally be surrounded by spaces.
4488
c906108c
SS
4489@kindex info breakpoints
4490@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4491@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4492@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4493Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4494not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4495about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4496For each breakpoint, following columns are printed:
c906108c
SS
4497
4498@table @emph
4499@item Breakpoint Numbers
4500@item Type
4501Breakpoint, watchpoint, or catchpoint.
4502@item Disposition
4503Whether the breakpoint is marked to be disabled or deleted when hit.
4504@item Enabled or Disabled
4505Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4506that are not enabled.
c906108c 4507@item Address
fe6fbf8b 4508Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4509pending breakpoint whose address is not yet known, this field will
4510contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4511library that has the symbol or line referred by breakpoint is loaded.
4512See below for details. A breakpoint with several locations will
3b784c4f 4513have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4514@item What
4515Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4516line number. For a pending breakpoint, the original string passed to
4517the breakpoint command will be listed as it cannot be resolved until
4518the appropriate shared library is loaded in the future.
c906108c
SS
4519@end table
4520
4521@noindent
83364271
LM
4522If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4523``target''. If mode is ``host'', breakpoint condition evaluation is done by
4524@value{GDBN} on the host's side. If it is ``target'', then the condition
4525is evaluated by the target. The @code{info break} command shows
4526the condition on the line following the affected breakpoint, together with
4527its condition evaluation mode in between parentheses.
4528
4529Breakpoint commands, if any, are listed after that. A pending breakpoint is
4530allowed to have a condition specified for it. The condition is not parsed for
4531validity until a shared library is loaded that allows the pending
4532breakpoint to resolve to a valid location.
c906108c
SS
4533
4534@noindent
4535@code{info break} with a breakpoint
4536number @var{n} as argument lists only that breakpoint. The
4537convenience variable @code{$_} and the default examining-address for
4538the @code{x} command are set to the address of the last breakpoint
79a6e687 4539listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4540
4541@noindent
4542@code{info break} displays a count of the number of times the breakpoint
4543has been hit. This is especially useful in conjunction with the
4544@code{ignore} command. You can ignore a large number of breakpoint
4545hits, look at the breakpoint info to see how many times the breakpoint
4546was hit, and then run again, ignoring one less than that number. This
4547will get you quickly to the last hit of that breakpoint.
816338b5
SS
4548
4549@noindent
4550For a breakpoints with an enable count (xref) greater than 1,
4551@code{info break} also displays that count.
4552
c906108c
SS
4553@end table
4554
4555@value{GDBN} allows you to set any number of breakpoints at the same place in
4556your program. There is nothing silly or meaningless about this. When
4557the breakpoints are conditional, this is even useful
79a6e687 4558(@pxref{Conditions, ,Break Conditions}).
c906108c 4559
2e9132cc
EZ
4560@cindex multiple locations, breakpoints
4561@cindex breakpoints, multiple locations
fcda367b 4562It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4563in your program. Examples of this situation are:
4564
4565@itemize @bullet
f8eba3c6
TT
4566@item
4567Multiple functions in the program may have the same name.
4568
fe6fbf8b
VP
4569@item
4570For a C@t{++} constructor, the @value{NGCC} compiler generates several
4571instances of the function body, used in different cases.
4572
4573@item
4574For a C@t{++} template function, a given line in the function can
4575correspond to any number of instantiations.
4576
4577@item
4578For an inlined function, a given source line can correspond to
4579several places where that function is inlined.
fe6fbf8b
VP
4580@end itemize
4581
4582In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4583the relevant locations.
fe6fbf8b 4584
3b784c4f
EZ
4585A breakpoint with multiple locations is displayed in the breakpoint
4586table using several rows---one header row, followed by one row for
4587each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4588address column. The rows for individual locations contain the actual
4589addresses for locations, and show the functions to which those
4590locations belong. The number column for a location is of the form
fe6fbf8b
VP
4591@var{breakpoint-number}.@var{location-number}.
4592
4593For example:
3b784c4f 4594
fe6fbf8b
VP
4595@smallexample
4596Num Type Disp Enb Address What
45971 breakpoint keep y <MULTIPLE>
4598 stop only if i==1
4599 breakpoint already hit 1 time
46001.1 y 0x080486a2 in void foo<int>() at t.cc:8
46011.2 y 0x080486ca in void foo<double>() at t.cc:8
4602@end smallexample
4603
d0fe4701
XR
4604You cannot delete the individual locations from a breakpoint. However,
4605each location can be individually enabled or disabled by passing
fe6fbf8b 4606@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4607@code{enable} and @code{disable} commands. It's also possible to
4608@code{enable} and @code{disable} a range of @var{location-number}
4609locations using a @var{breakpoint-number} and two @var{location-number}s,
4610in increasing order, separated by a hyphen, like
4611@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4612in which case @value{GDBN} acts on all the locations in the range (inclusive).
4613Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4614all of the locations that belong to that breakpoint.
fe6fbf8b 4615
2650777c 4616@cindex pending breakpoints
fe6fbf8b 4617It's quite common to have a breakpoint inside a shared library.
3b784c4f 4618Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4619and possibly repeatedly, as the program is executed. To support
4620this use case, @value{GDBN} updates breakpoint locations whenever
4621any shared library is loaded or unloaded. Typically, you would
fcda367b 4622set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4623debugging session, when the library is not loaded, and when the
4624symbols from the library are not available. When you try to set
4625breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4626a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4627is not yet resolved.
4628
4629After the program is run, whenever a new shared library is loaded,
4630@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4631shared library contains the symbol or line referred to by some
4632pending breakpoint, that breakpoint is resolved and becomes an
4633ordinary breakpoint. When a library is unloaded, all breakpoints
4634that refer to its symbols or source lines become pending again.
4635
4636This logic works for breakpoints with multiple locations, too. For
4637example, if you have a breakpoint in a C@t{++} template function, and
4638a newly loaded shared library has an instantiation of that template,
4639a new location is added to the list of locations for the breakpoint.
4640
4641Except for having unresolved address, pending breakpoints do not
4642differ from regular breakpoints. You can set conditions or commands,
4643enable and disable them and perform other breakpoint operations.
4644
4645@value{GDBN} provides some additional commands for controlling what
4646happens when the @samp{break} command cannot resolve breakpoint
4647address specification to an address:
dd79a6cf
JJ
4648
4649@kindex set breakpoint pending
4650@kindex show breakpoint pending
4651@table @code
4652@item set breakpoint pending auto
4653This is the default behavior. When @value{GDBN} cannot find the breakpoint
4654location, it queries you whether a pending breakpoint should be created.
4655
4656@item set breakpoint pending on
4657This indicates that an unrecognized breakpoint location should automatically
4658result in a pending breakpoint being created.
4659
4660@item set breakpoint pending off
4661This indicates that pending breakpoints are not to be created. Any
4662unrecognized breakpoint location results in an error. This setting does
4663not affect any pending breakpoints previously created.
4664
4665@item show breakpoint pending
4666Show the current behavior setting for creating pending breakpoints.
4667@end table
2650777c 4668
fe6fbf8b
VP
4669The settings above only affect the @code{break} command and its
4670variants. Once breakpoint is set, it will be automatically updated
4671as shared libraries are loaded and unloaded.
2650777c 4672
765dc015
VP
4673@cindex automatic hardware breakpoints
4674For some targets, @value{GDBN} can automatically decide if hardware or
4675software breakpoints should be used, depending on whether the
4676breakpoint address is read-only or read-write. This applies to
4677breakpoints set with the @code{break} command as well as to internal
4678breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4679breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4680breakpoints.
4681
18da0c51 4682You can control this automatic behaviour with the following commands:
765dc015
VP
4683
4684@kindex set breakpoint auto-hw
4685@kindex show breakpoint auto-hw
4686@table @code
4687@item set breakpoint auto-hw on
4688This is the default behavior. When @value{GDBN} sets a breakpoint, it
4689will try to use the target memory map to decide if software or hardware
4690breakpoint must be used.
4691
4692@item set breakpoint auto-hw off
4693This indicates @value{GDBN} should not automatically select breakpoint
4694type. If the target provides a memory map, @value{GDBN} will warn when
4695trying to set software breakpoint at a read-only address.
4696@end table
4697
74960c60
VP
4698@value{GDBN} normally implements breakpoints by replacing the program code
4699at the breakpoint address with a special instruction, which, when
4700executed, given control to the debugger. By default, the program
4701code is so modified only when the program is resumed. As soon as
4702the program stops, @value{GDBN} restores the original instructions. This
4703behaviour guards against leaving breakpoints inserted in the
4704target should gdb abrubptly disconnect. However, with slow remote
4705targets, inserting and removing breakpoint can reduce the performance.
4706This behavior can be controlled with the following commands::
4707
4708@kindex set breakpoint always-inserted
4709@kindex show breakpoint always-inserted
4710@table @code
4711@item set breakpoint always-inserted off
33e5cbd6
PA
4712All breakpoints, including newly added by the user, are inserted in
4713the target only when the target is resumed. All breakpoints are
a25a5a45 4714removed from the target when it stops. This is the default mode.
74960c60
VP
4715
4716@item set breakpoint always-inserted on
4717Causes all breakpoints to be inserted in the target at all times. If
4718the user adds a new breakpoint, or changes an existing breakpoint, the
4719breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4720removed from the target only when breakpoint itself is deleted.
342cc091 4721@end table
765dc015 4722
83364271
LM
4723@value{GDBN} handles conditional breakpoints by evaluating these conditions
4724when a breakpoint breaks. If the condition is true, then the process being
4725debugged stops, otherwise the process is resumed.
4726
4727If the target supports evaluating conditions on its end, @value{GDBN} may
4728download the breakpoint, together with its conditions, to it.
4729
4730This feature can be controlled via the following commands:
4731
4732@kindex set breakpoint condition-evaluation
4733@kindex show breakpoint condition-evaluation
4734@table @code
4735@item set breakpoint condition-evaluation host
4736This option commands @value{GDBN} to evaluate the breakpoint
4737conditions on the host's side. Unconditional breakpoints are sent to
4738the target which in turn receives the triggers and reports them back to GDB
4739for condition evaluation. This is the standard evaluation mode.
4740
4741@item set breakpoint condition-evaluation target
4742This option commands @value{GDBN} to download breakpoint conditions
4743to the target at the moment of their insertion. The target
4744is responsible for evaluating the conditional expression and reporting
4745breakpoint stop events back to @value{GDBN} whenever the condition
4746is true. Due to limitations of target-side evaluation, some conditions
4747cannot be evaluated there, e.g., conditions that depend on local data
4748that is only known to the host. Examples include
4749conditional expressions involving convenience variables, complex types
4750that cannot be handled by the agent expression parser and expressions
4751that are too long to be sent over to the target, specially when the
4752target is a remote system. In these cases, the conditions will be
4753evaluated by @value{GDBN}.
4754
4755@item set breakpoint condition-evaluation auto
4756This is the default mode. If the target supports evaluating breakpoint
4757conditions on its end, @value{GDBN} will download breakpoint conditions to
4758the target (limitations mentioned previously apply). If the target does
4759not support breakpoint condition evaluation, then @value{GDBN} will fallback
4760to evaluating all these conditions on the host's side.
4761@end table
4762
4763
c906108c
SS
4764@cindex negative breakpoint numbers
4765@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4766@value{GDBN} itself sometimes sets breakpoints in your program for
4767special purposes, such as proper handling of @code{longjmp} (in C
4768programs). These internal breakpoints are assigned negative numbers,
4769starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4770You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4771@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4772
4773
6d2ebf8b 4774@node Set Watchpoints
79a6e687 4775@subsection Setting Watchpoints
c906108c
SS
4776
4777@cindex setting watchpoints
c906108c
SS
4778You can use a watchpoint to stop execution whenever the value of an
4779expression changes, without having to predict a particular place where
fd60e0df
EZ
4780this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4781The expression may be as simple as the value of a single variable, or
4782as complex as many variables combined by operators. Examples include:
4783
4784@itemize @bullet
4785@item
4786A reference to the value of a single variable.
4787
4788@item
4789An address cast to an appropriate data type. For example,
4790@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4791address (assuming an @code{int} occupies 4 bytes).
4792
4793@item
4794An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4795expression can use any operators valid in the program's native
4796language (@pxref{Languages}).
4797@end itemize
c906108c 4798
fa4727a6
DJ
4799You can set a watchpoint on an expression even if the expression can
4800not be evaluated yet. For instance, you can set a watchpoint on
4801@samp{*global_ptr} before @samp{global_ptr} is initialized.
4802@value{GDBN} will stop when your program sets @samp{global_ptr} and
4803the expression produces a valid value. If the expression becomes
4804valid in some other way than changing a variable (e.g.@: if the memory
4805pointed to by @samp{*global_ptr} becomes readable as the result of a
4806@code{malloc} call), @value{GDBN} may not stop until the next time
4807the expression changes.
4808
82f2d802
EZ
4809@cindex software watchpoints
4810@cindex hardware watchpoints
c906108c 4811Depending on your system, watchpoints may be implemented in software or
2df3850c 4812hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4813program and testing the variable's value each time, which is hundreds of
4814times slower than normal execution. (But this may still be worth it, to
4815catch errors where you have no clue what part of your program is the
4816culprit.)
4817
b1236ac3
PA
4818On some systems, such as most PowerPC or x86-based targets,
4819@value{GDBN} includes support for hardware watchpoints, which do not
4820slow down the running of your program.
c906108c
SS
4821
4822@table @code
4823@kindex watch
5d5658a1 4824@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4825Set a watchpoint for an expression. @value{GDBN} will break when the
4826expression @var{expr} is written into by the program and its value
4827changes. The simplest (and the most popular) use of this command is
4828to watch the value of a single variable:
4829
4830@smallexample
4831(@value{GDBP}) watch foo
4832@end smallexample
c906108c 4833
5d5658a1 4834If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4835argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4836@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4837change the value of @var{expr}, @value{GDBN} will not break. Note
4838that watchpoints restricted to a single thread in this way only work
4839with Hardware Watchpoints.
4840
06a64a0b
TT
4841Ordinarily a watchpoint respects the scope of variables in @var{expr}
4842(see below). The @code{-location} argument tells @value{GDBN} to
4843instead watch the memory referred to by @var{expr}. In this case,
4844@value{GDBN} will evaluate @var{expr}, take the address of the result,
4845and watch the memory at that address. The type of the result is used
4846to determine the size of the watched memory. If the expression's
4847result does not have an address, then @value{GDBN} will print an
4848error.
4849
9c06b0b4
TJB
4850The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4851of masked watchpoints, if the current architecture supports this
4852feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4853Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4854to an address to watch. The mask specifies that some bits of an address
4855(the bits which are reset in the mask) should be ignored when matching
4856the address accessed by the inferior against the watchpoint address.
4857Thus, a masked watchpoint watches many addresses simultaneously---those
4858addresses whose unmasked bits are identical to the unmasked bits in the
4859watchpoint address. The @code{mask} argument implies @code{-location}.
4860Examples:
4861
4862@smallexample
4863(@value{GDBP}) watch foo mask 0xffff00ff
4864(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4865@end smallexample
4866
c906108c 4867@kindex rwatch
5d5658a1 4868@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4869Set a watchpoint that will break when the value of @var{expr} is read
4870by the program.
c906108c
SS
4871
4872@kindex awatch
5d5658a1 4873@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4874Set a watchpoint that will break when @var{expr} is either read from
4875or written into by the program.
c906108c 4876
18da0c51
MG
4877@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4878@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4879This command prints a list of watchpoints, using the same format as
4880@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4881@end table
4882
65d79d4b
SDJ
4883If you watch for a change in a numerically entered address you need to
4884dereference it, as the address itself is just a constant number which will
4885never change. @value{GDBN} refuses to create a watchpoint that watches
4886a never-changing value:
4887
4888@smallexample
4889(@value{GDBP}) watch 0x600850
4890Cannot watch constant value 0x600850.
4891(@value{GDBP}) watch *(int *) 0x600850
4892Watchpoint 1: *(int *) 6293584
4893@end smallexample
4894
c906108c
SS
4895@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4896watchpoints execute very quickly, and the debugger reports a change in
4897value at the exact instruction where the change occurs. If @value{GDBN}
4898cannot set a hardware watchpoint, it sets a software watchpoint, which
4899executes more slowly and reports the change in value at the next
82f2d802
EZ
4900@emph{statement}, not the instruction, after the change occurs.
4901
82f2d802
EZ
4902@cindex use only software watchpoints
4903You can force @value{GDBN} to use only software watchpoints with the
4904@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4905zero, @value{GDBN} will never try to use hardware watchpoints, even if
4906the underlying system supports them. (Note that hardware-assisted
4907watchpoints that were set @emph{before} setting
4908@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4909mechanism of watching expression values.)
c906108c 4910
9c16f35a
EZ
4911@table @code
4912@item set can-use-hw-watchpoints
4913@kindex set can-use-hw-watchpoints
4914Set whether or not to use hardware watchpoints.
4915
4916@item show can-use-hw-watchpoints
4917@kindex show can-use-hw-watchpoints
4918Show the current mode of using hardware watchpoints.
4919@end table
4920
4921For remote targets, you can restrict the number of hardware
4922watchpoints @value{GDBN} will use, see @ref{set remote
4923hardware-breakpoint-limit}.
4924
c906108c
SS
4925When you issue the @code{watch} command, @value{GDBN} reports
4926
474c8240 4927@smallexample
c906108c 4928Hardware watchpoint @var{num}: @var{expr}
474c8240 4929@end smallexample
c906108c
SS
4930
4931@noindent
4932if it was able to set a hardware watchpoint.
4933
7be570e7
JM
4934Currently, the @code{awatch} and @code{rwatch} commands can only set
4935hardware watchpoints, because accesses to data that don't change the
4936value of the watched expression cannot be detected without examining
4937every instruction as it is being executed, and @value{GDBN} does not do
4938that currently. If @value{GDBN} finds that it is unable to set a
4939hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4940will print a message like this:
4941
4942@smallexample
4943Expression cannot be implemented with read/access watchpoint.
4944@end smallexample
4945
4946Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4947data type of the watched expression is wider than what a hardware
4948watchpoint on the target machine can handle. For example, some systems
4949can only watch regions that are up to 4 bytes wide; on such systems you
4950cannot set hardware watchpoints for an expression that yields a
4951double-precision floating-point number (which is typically 8 bytes
4952wide). As a work-around, it might be possible to break the large region
4953into a series of smaller ones and watch them with separate watchpoints.
4954
4955If you set too many hardware watchpoints, @value{GDBN} might be unable
4956to insert all of them when you resume the execution of your program.
4957Since the precise number of active watchpoints is unknown until such
4958time as the program is about to be resumed, @value{GDBN} might not be
4959able to warn you about this when you set the watchpoints, and the
4960warning will be printed only when the program is resumed:
4961
4962@smallexample
4963Hardware watchpoint @var{num}: Could not insert watchpoint
4964@end smallexample
4965
4966@noindent
4967If this happens, delete or disable some of the watchpoints.
4968
fd60e0df
EZ
4969Watching complex expressions that reference many variables can also
4970exhaust the resources available for hardware-assisted watchpoints.
4971That's because @value{GDBN} needs to watch every variable in the
4972expression with separately allocated resources.
4973
c906108c 4974If you call a function interactively using @code{print} or @code{call},
2df3850c 4975any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4976kind of breakpoint or the call completes.
4977
7be570e7
JM
4978@value{GDBN} automatically deletes watchpoints that watch local
4979(automatic) variables, or expressions that involve such variables, when
4980they go out of scope, that is, when the execution leaves the block in
4981which these variables were defined. In particular, when the program
4982being debugged terminates, @emph{all} local variables go out of scope,
4983and so only watchpoints that watch global variables remain set. If you
4984rerun the program, you will need to set all such watchpoints again. One
4985way of doing that would be to set a code breakpoint at the entry to the
4986@code{main} function and when it breaks, set all the watchpoints.
4987
c906108c
SS
4988@cindex watchpoints and threads
4989@cindex threads and watchpoints
d983da9c
DJ
4990In multi-threaded programs, watchpoints will detect changes to the
4991watched expression from every thread.
4992
4993@quotation
4994@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4995have only limited usefulness. If @value{GDBN} creates a software
4996watchpoint, it can only watch the value of an expression @emph{in a
4997single thread}. If you are confident that the expression can only
4998change due to the current thread's activity (and if you are also
4999confident that no other thread can become current), then you can use
5000software watchpoints as usual. However, @value{GDBN} may not notice
5001when a non-current thread's activity changes the expression. (Hardware
5002watchpoints, in contrast, watch an expression in all threads.)
c906108c 5003@end quotation
c906108c 5004
501eef12
AC
5005@xref{set remote hardware-watchpoint-limit}.
5006
6d2ebf8b 5007@node Set Catchpoints
79a6e687 5008@subsection Setting Catchpoints
d4f3574e 5009@cindex catchpoints, setting
c906108c
SS
5010@cindex exception handlers
5011@cindex event handling
5012
5013You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 5014kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
5015shared library. Use the @code{catch} command to set a catchpoint.
5016
5017@table @code
5018@kindex catch
5019@item catch @var{event}
697aa1b7 5020Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 5021
c906108c 5022@table @code
cc16e6c9
TT
5023@item throw @r{[}@var{regexp}@r{]}
5024@itemx rethrow @r{[}@var{regexp}@r{]}
5025@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5026@kindex catch throw
5027@kindex catch rethrow
5028@kindex catch catch
4644b6e3 5029@cindex stop on C@t{++} exceptions
591f19e8
TT
5030The throwing, re-throwing, or catching of a C@t{++} exception.
5031
cc16e6c9
TT
5032If @var{regexp} is given, then only exceptions whose type matches the
5033regular expression will be caught.
5034
72f1fe8a
TT
5035@vindex $_exception@r{, convenience variable}
5036The convenience variable @code{$_exception} is available at an
5037exception-related catchpoint, on some systems. This holds the
5038exception being thrown.
5039
591f19e8
TT
5040There are currently some limitations to C@t{++} exception handling in
5041@value{GDBN}:
c906108c 5042
591f19e8
TT
5043@itemize @bullet
5044@item
5045The support for these commands is system-dependent. Currently, only
5046systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5047supported.
5048
72f1fe8a 5049@item
cc16e6c9
TT
5050The regular expression feature and the @code{$_exception} convenience
5051variable rely on the presence of some SDT probes in @code{libstdc++}.
5052If these probes are not present, then these features cannot be used.
dee368d3
TT
5053These probes were first available in the GCC 4.8 release, but whether
5054or not they are available in your GCC also depends on how it was
5055built.
72f1fe8a
TT
5056
5057@item
5058The @code{$_exception} convenience variable is only valid at the
5059instruction at which an exception-related catchpoint is set.
5060
591f19e8
TT
5061@item
5062When an exception-related catchpoint is hit, @value{GDBN} stops at a
5063location in the system library which implements runtime exception
5064support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5065(@pxref{Selection}) to get to your code.
5066
5067@item
5068If you call a function interactively, @value{GDBN} normally returns
5069control to you when the function has finished executing. If the call
5070raises an exception, however, the call may bypass the mechanism that
5071returns control to you and cause your program either to abort or to
5072simply continue running until it hits a breakpoint, catches a signal
5073that @value{GDBN} is listening for, or exits. This is the case even if
5074you set a catchpoint for the exception; catchpoints on exceptions are
5075disabled within interactive calls. @xref{Calling}, for information on
5076controlling this with @code{set unwind-on-terminating-exception}.
5077
5078@item
5079You cannot raise an exception interactively.
5080
5081@item
5082You cannot install an exception handler interactively.
5083@end itemize
c906108c 5084
b8e07335 5085@item exception @r{[}@var{name}@r{]}
1a4f73eb 5086@kindex catch exception
8936fcda
JB
5087@cindex Ada exception catching
5088@cindex catch Ada exceptions
5089An Ada exception being raised. If an exception name is specified
5090at the end of the command (eg @code{catch exception Program_Error}),
5091the debugger will stop only when this specific exception is raised.
5092Otherwise, the debugger stops execution when any Ada exception is raised.
5093
87f67dba
JB
5094When inserting an exception catchpoint on a user-defined exception whose
5095name is identical to one of the exceptions defined by the language, the
5096fully qualified name must be used as the exception name. Otherwise,
5097@value{GDBN} will assume that it should stop on the pre-defined exception
5098rather than the user-defined one. For instance, assuming an exception
5099called @code{Constraint_Error} is defined in package @code{Pck}, then
5100the command to use to catch such exceptions is @kbd{catch exception
5101Pck.Constraint_Error}.
5102
37f6a7f4
TT
5103@vindex $_ada_exception@r{, convenience variable}
5104The convenience variable @code{$_ada_exception} holds the address of
5105the exception being thrown. This can be useful when setting a
5106condition for such a catchpoint.
5107
b8e07335
TT
5108@item exception unhandled
5109@kindex catch exception unhandled
37f6a7f4
TT
5110An exception that was raised but is not handled by the program. The
5111convenience variable @code{$_ada_exception} is set as for @code{catch
5112exception}.
b8e07335
TT
5113
5114@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
5115@kindex catch handlers
5116@cindex Ada exception handlers catching
5117@cindex catch Ada exceptions when handled
5118An Ada exception being handled. If an exception name is
5119specified at the end of the command
5120 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5121only when this specific exception is handled.
5122Otherwise, the debugger stops execution when any Ada exception is handled.
5123
5124When inserting a handlers catchpoint on a user-defined
5125exception whose name is identical to one of the exceptions
5126defined by the language, the fully qualified name must be used
5127as the exception name. Otherwise, @value{GDBN} will assume that it
5128should stop on the pre-defined exception rather than the
5129user-defined one. For instance, assuming an exception called
5130 @code{Constraint_Error} is defined in package @code{Pck}, then the
5131command to use to catch such exceptions handling is
5132@kbd{catch handlers Pck.Constraint_Error}.
5133
37f6a7f4
TT
5134The convenience variable @code{$_ada_exception} is set as for
5135@code{catch exception}.
5136
8936fcda 5137@item assert
1a4f73eb 5138@kindex catch assert
37f6a7f4
TT
5139A failed Ada assertion. Note that the convenience variable
5140@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 5141
c906108c 5142@item exec
1a4f73eb 5143@kindex catch exec
4644b6e3 5144@cindex break on fork/exec
b1236ac3 5145A call to @code{exec}.
c906108c 5146
e9076973 5147@anchor{catch syscall}
a96d9b2e 5148@item syscall
e3487908 5149@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 5150@kindex catch syscall
a96d9b2e
SDJ
5151@cindex break on a system call.
5152A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5153syscall is a mechanism for application programs to request a service
5154from the operating system (OS) or one of the OS system services.
5155@value{GDBN} can catch some or all of the syscalls issued by the
5156debuggee, and show the related information for each syscall. If no
5157argument is specified, calls to and returns from all system calls
5158will be caught.
5159
5160@var{name} can be any system call name that is valid for the
5161underlying OS. Just what syscalls are valid depends on the OS. On
5162GNU and Unix systems, you can find the full list of valid syscall
5163names on @file{/usr/include/asm/unistd.h}.
5164
5165@c For MS-Windows, the syscall names and the corresponding numbers
5166@c can be found, e.g., on this URL:
5167@c http://www.metasploit.com/users/opcode/syscalls.html
5168@c but we don't support Windows syscalls yet.
5169
5170Normally, @value{GDBN} knows in advance which syscalls are valid for
5171each OS, so you can use the @value{GDBN} command-line completion
5172facilities (@pxref{Completion,, command completion}) to list the
5173available choices.
5174
5175You may also specify the system call numerically. A syscall's
5176number is the value passed to the OS's syscall dispatcher to
5177identify the requested service. When you specify the syscall by its
5178name, @value{GDBN} uses its database of syscalls to convert the name
5179into the corresponding numeric code, but using the number directly
5180may be useful if @value{GDBN}'s database does not have the complete
5181list of syscalls on your system (e.g., because @value{GDBN} lags
5182behind the OS upgrades).
5183
e3487908
GKB
5184You may specify a group of related syscalls to be caught at once using
5185the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5186instance, on some platforms @value{GDBN} allows you to catch all
5187network related syscalls, by passing the argument @code{group:network}
5188to @code{catch syscall}. Note that not all syscall groups are
5189available in every system. You can use the command completion
5190facilities (@pxref{Completion,, command completion}) to list the
5191syscall groups available on your environment.
5192
a96d9b2e
SDJ
5193The example below illustrates how this command works if you don't provide
5194arguments to it:
5195
5196@smallexample
5197(@value{GDBP}) catch syscall
5198Catchpoint 1 (syscall)
5199(@value{GDBP}) r
5200Starting program: /tmp/catch-syscall
5201
5202Catchpoint 1 (call to syscall 'close'), \
5203 0xffffe424 in __kernel_vsyscall ()
5204(@value{GDBP}) c
5205Continuing.
5206
5207Catchpoint 1 (returned from syscall 'close'), \
5208 0xffffe424 in __kernel_vsyscall ()
5209(@value{GDBP})
5210@end smallexample
5211
5212Here is an example of catching a system call by name:
5213
5214@smallexample
5215(@value{GDBP}) catch syscall chroot
5216Catchpoint 1 (syscall 'chroot' [61])
5217(@value{GDBP}) r
5218Starting program: /tmp/catch-syscall
5219
5220Catchpoint 1 (call to syscall 'chroot'), \
5221 0xffffe424 in __kernel_vsyscall ()
5222(@value{GDBP}) c
5223Continuing.
5224
5225Catchpoint 1 (returned from syscall 'chroot'), \
5226 0xffffe424 in __kernel_vsyscall ()
5227(@value{GDBP})
5228@end smallexample
5229
5230An example of specifying a system call numerically. In the case
5231below, the syscall number has a corresponding entry in the XML
5232file, so @value{GDBN} finds its name and prints it:
5233
5234@smallexample
5235(@value{GDBP}) catch syscall 252
5236Catchpoint 1 (syscall(s) 'exit_group')
5237(@value{GDBP}) r
5238Starting program: /tmp/catch-syscall
5239
5240Catchpoint 1 (call to syscall 'exit_group'), \
5241 0xffffe424 in __kernel_vsyscall ()
5242(@value{GDBP}) c
5243Continuing.
5244
5245Program exited normally.
5246(@value{GDBP})
5247@end smallexample
5248
e3487908
GKB
5249Here is an example of catching a syscall group:
5250
5251@smallexample
5252(@value{GDBP}) catch syscall group:process
5253Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5254'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5255'exit_group' [252] 'waitid' [284] 'unshare' [310])
5256(@value{GDBP}) r
5257Starting program: /tmp/catch-syscall
5258
5259Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5260 from /lib64/ld-linux-x86-64.so.2
5261
5262(@value{GDBP}) c
5263Continuing.
5264@end smallexample
5265
a96d9b2e
SDJ
5266However, there can be situations when there is no corresponding name
5267in XML file for that syscall number. In this case, @value{GDBN} prints
5268a warning message saying that it was not able to find the syscall name,
5269but the catchpoint will be set anyway. See the example below:
5270
5271@smallexample
5272(@value{GDBP}) catch syscall 764
5273warning: The number '764' does not represent a known syscall.
5274Catchpoint 2 (syscall 764)
5275(@value{GDBP})
5276@end smallexample
5277
5278If you configure @value{GDBN} using the @samp{--without-expat} option,
5279it will not be able to display syscall names. Also, if your
5280architecture does not have an XML file describing its system calls,
5281you will not be able to see the syscall names. It is important to
5282notice that these two features are used for accessing the syscall
5283name database. In either case, you will see a warning like this:
5284
5285@smallexample
5286(@value{GDBP}) catch syscall
5287warning: Could not open "syscalls/i386-linux.xml"
5288warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5289GDB will not be able to display syscall names.
5290Catchpoint 1 (syscall)
5291(@value{GDBP})
5292@end smallexample
5293
5294Of course, the file name will change depending on your architecture and system.
5295
5296Still using the example above, you can also try to catch a syscall by its
5297number. In this case, you would see something like:
5298
5299@smallexample
5300(@value{GDBP}) catch syscall 252
5301Catchpoint 1 (syscall(s) 252)
5302@end smallexample
5303
5304Again, in this case @value{GDBN} would not be able to display syscall's names.
5305
c906108c 5306@item fork
1a4f73eb 5307@kindex catch fork
b1236ac3 5308A call to @code{fork}.
c906108c
SS
5309
5310@item vfork
1a4f73eb 5311@kindex catch vfork
b1236ac3 5312A call to @code{vfork}.
c906108c 5313
b8e07335
TT
5314@item load @r{[}@var{regexp}@r{]}
5315@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5316@kindex catch load
5317@kindex catch unload
edcc5120
TT
5318The loading or unloading of a shared library. If @var{regexp} is
5319given, then the catchpoint will stop only if the regular expression
5320matches one of the affected libraries.
5321
ab04a2af 5322@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5323@kindex catch signal
ab04a2af
TT
5324The delivery of a signal.
5325
5326With no arguments, this catchpoint will catch any signal that is not
5327used internally by @value{GDBN}, specifically, all signals except
5328@samp{SIGTRAP} and @samp{SIGINT}.
5329
5330With the argument @samp{all}, all signals, including those used by
5331@value{GDBN}, will be caught. This argument cannot be used with other
5332signal names.
5333
5334Otherwise, the arguments are a list of signal names as given to
5335@code{handle} (@pxref{Signals}). Only signals specified in this list
5336will be caught.
5337
5338One reason that @code{catch signal} can be more useful than
5339@code{handle} is that you can attach commands and conditions to the
5340catchpoint.
5341
5342When a signal is caught by a catchpoint, the signal's @code{stop} and
5343@code{print} settings, as specified by @code{handle}, are ignored.
5344However, whether the signal is still delivered to the inferior depends
5345on the @code{pass} setting; this can be changed in the catchpoint's
5346commands.
5347
c906108c
SS
5348@end table
5349
5350@item tcatch @var{event}
1a4f73eb 5351@kindex tcatch
c906108c
SS
5352Set a catchpoint that is enabled only for one stop. The catchpoint is
5353automatically deleted after the first time the event is caught.
5354
5355@end table
5356
5357Use the @code{info break} command to list the current catchpoints.
5358
c906108c 5359
6d2ebf8b 5360@node Delete Breaks
79a6e687 5361@subsection Deleting Breakpoints
c906108c
SS
5362
5363@cindex clearing breakpoints, watchpoints, catchpoints
5364@cindex deleting breakpoints, watchpoints, catchpoints
5365It is often necessary to eliminate a breakpoint, watchpoint, or
5366catchpoint once it has done its job and you no longer want your program
5367to stop there. This is called @dfn{deleting} the breakpoint. A
5368breakpoint that has been deleted no longer exists; it is forgotten.
5369
5370With the @code{clear} command you can delete breakpoints according to
5371where they are in your program. With the @code{delete} command you can
5372delete individual breakpoints, watchpoints, or catchpoints by specifying
5373their breakpoint numbers.
5374
5375It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5376automatically ignores breakpoints on the first instruction to be executed
5377when you continue execution without changing the execution address.
5378
5379@table @code
5380@kindex clear
5381@item clear
5382Delete any breakpoints at the next instruction to be executed in the
79a6e687 5383selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5384the innermost frame is selected, this is a good way to delete a
5385breakpoint where your program just stopped.
5386
2a25a5ba
EZ
5387@item clear @var{location}
5388Delete any breakpoints set at the specified @var{location}.
5389@xref{Specify Location}, for the various forms of @var{location}; the
5390most useful ones are listed below:
5391
5392@table @code
c906108c
SS
5393@item clear @var{function}
5394@itemx clear @var{filename}:@var{function}
09d4efe1 5395Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5396
5397@item clear @var{linenum}
5398@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5399Delete any breakpoints set at or within the code of the specified
5400@var{linenum} of the specified @var{filename}.
2a25a5ba 5401@end table
c906108c
SS
5402
5403@cindex delete breakpoints
5404@kindex delete
41afff9a 5405@kindex d @r{(@code{delete})}
18da0c51 5406@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5407Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5408list specified as argument. If no argument is specified, delete all
c906108c
SS
5409breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5410confirm off}). You can abbreviate this command as @code{d}.
5411@end table
5412
6d2ebf8b 5413@node Disabling
79a6e687 5414@subsection Disabling Breakpoints
c906108c 5415
4644b6e3 5416@cindex enable/disable a breakpoint
c906108c
SS
5417Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5418prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5419it had been deleted, but remembers the information on the breakpoint so
5420that you can @dfn{enable} it again later.
5421
5422You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5423the @code{enable} and @code{disable} commands, optionally specifying
5424one or more breakpoint numbers as arguments. Use @code{info break} to
5425print a list of all breakpoints, watchpoints, and catchpoints if you
5426do not know which numbers to use.
c906108c 5427
3b784c4f
EZ
5428Disabling and enabling a breakpoint that has multiple locations
5429affects all of its locations.
5430
816338b5
SS
5431A breakpoint, watchpoint, or catchpoint can have any of several
5432different states of enablement:
c906108c
SS
5433
5434@itemize @bullet
5435@item
5436Enabled. The breakpoint stops your program. A breakpoint set
5437with the @code{break} command starts out in this state.
5438@item
5439Disabled. The breakpoint has no effect on your program.
5440@item
5441Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5442disabled.
c906108c 5443@item
816338b5
SS
5444Enabled for a count. The breakpoint stops your program for the next
5445N times, then becomes disabled.
5446@item
c906108c 5447Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5448immediately after it does so it is deleted permanently. A breakpoint
5449set with the @code{tbreak} command starts out in this state.
c906108c
SS
5450@end itemize
5451
5452You can use the following commands to enable or disable breakpoints,
5453watchpoints, and catchpoints:
5454
5455@table @code
c906108c 5456@kindex disable
41afff9a 5457@kindex dis @r{(@code{disable})}
18da0c51 5458@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5459Disable the specified breakpoints---or all breakpoints, if none are
5460listed. A disabled breakpoint has no effect but is not forgotten. All
5461options such as ignore-counts, conditions and commands are remembered in
5462case the breakpoint is enabled again later. You may abbreviate
5463@code{disable} as @code{dis}.
5464
c906108c 5465@kindex enable
18da0c51 5466@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5467Enable the specified breakpoints (or all defined breakpoints). They
5468become effective once again in stopping your program.
5469
18da0c51 5470@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5471Enable the specified breakpoints temporarily. @value{GDBN} disables any
5472of these breakpoints immediately after stopping your program.
5473
18da0c51 5474@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5475Enable the specified breakpoints temporarily. @value{GDBN} records
5476@var{count} with each of the specified breakpoints, and decrements a
5477breakpoint's count when it is hit. When any count reaches 0,
5478@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5479count (@pxref{Conditions, ,Break Conditions}), that will be
5480decremented to 0 before @var{count} is affected.
5481
18da0c51 5482@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5483Enable the specified breakpoints to work once, then die. @value{GDBN}
5484deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5485Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5486@end table
5487
d4f3574e
SS
5488@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5489@c confusing: tbreak is also initially enabled.
c906108c 5490Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5491,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5492subsequently, they become disabled or enabled only when you use one of
5493the commands above. (The command @code{until} can set and delete a
5494breakpoint of its own, but it does not change the state of your other
5495breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5496Stepping}.)
c906108c 5497
6d2ebf8b 5498@node Conditions
79a6e687 5499@subsection Break Conditions
c906108c
SS
5500@cindex conditional breakpoints
5501@cindex breakpoint conditions
5502
5503@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5504@c in particular for a watchpoint?
c906108c
SS
5505The simplest sort of breakpoint breaks every time your program reaches a
5506specified place. You can also specify a @dfn{condition} for a
5507breakpoint. A condition is just a Boolean expression in your
5508programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5509a condition evaluates the expression each time your program reaches it,
5510and your program stops only if the condition is @emph{true}.
5511
5512This is the converse of using assertions for program validation; in that
5513situation, you want to stop when the assertion is violated---that is,
5514when the condition is false. In C, if you want to test an assertion expressed
5515by the condition @var{assert}, you should set the condition
5516@samp{! @var{assert}} on the appropriate breakpoint.
5517
5518Conditions are also accepted for watchpoints; you may not need them,
5519since a watchpoint is inspecting the value of an expression anyhow---but
5520it might be simpler, say, to just set a watchpoint on a variable name,
5521and specify a condition that tests whether the new value is an interesting
5522one.
5523
5524Break conditions can have side effects, and may even call functions in
5525your program. This can be useful, for example, to activate functions
5526that log program progress, or to use your own print functions to
99e008fe 5527format special data structures. The effects are completely predictable
c906108c
SS
5528unless there is another enabled breakpoint at the same address. (In
5529that case, @value{GDBN} might see the other breakpoint first and stop your
5530program without checking the condition of this one.) Note that
d4f3574e
SS
5531breakpoint commands are usually more convenient and flexible than break
5532conditions for the
c906108c 5533purpose of performing side effects when a breakpoint is reached
79a6e687 5534(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5535
83364271
LM
5536Breakpoint conditions can also be evaluated on the target's side if
5537the target supports it. Instead of evaluating the conditions locally,
5538@value{GDBN} encodes the expression into an agent expression
5539(@pxref{Agent Expressions}) suitable for execution on the target,
5540independently of @value{GDBN}. Global variables become raw memory
5541locations, locals become stack accesses, and so forth.
5542
5543In this case, @value{GDBN} will only be notified of a breakpoint trigger
5544when its condition evaluates to true. This mechanism may provide faster
5545response times depending on the performance characteristics of the target
5546since it does not need to keep @value{GDBN} informed about
5547every breakpoint trigger, even those with false conditions.
5548
c906108c
SS
5549Break conditions can be specified when a breakpoint is set, by using
5550@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5551Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5552with the @code{condition} command.
53a5351d 5553
c906108c
SS
5554You can also use the @code{if} keyword with the @code{watch} command.
5555The @code{catch} command does not recognize the @code{if} keyword;
5556@code{condition} is the only way to impose a further condition on a
5557catchpoint.
c906108c
SS
5558
5559@table @code
5560@kindex condition
5561@item condition @var{bnum} @var{expression}
5562Specify @var{expression} as the break condition for breakpoint,
5563watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5564breakpoint @var{bnum} stops your program only if the value of
5565@var{expression} is true (nonzero, in C). When you use
5566@code{condition}, @value{GDBN} checks @var{expression} immediately for
5567syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5568referents in the context of your breakpoint. If @var{expression} uses
5569symbols not referenced in the context of the breakpoint, @value{GDBN}
5570prints an error message:
5571
474c8240 5572@smallexample
d4f3574e 5573No symbol "foo" in current context.
474c8240 5574@end smallexample
d4f3574e
SS
5575
5576@noindent
c906108c
SS
5577@value{GDBN} does
5578not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5579command (or a command that sets a breakpoint with a condition, like
5580@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c 5581
733d554a
TBA
5582@item condition -force @var{bnum} @var{expression}
5583When the @code{-force} flag is used, define the condition even if
5584@var{expression} is invalid at all the current locations of breakpoint
5585@var{bnum}. This is similar to the @code{-force-condition} option
5586of the @code{break} command.
5587
c906108c
SS
5588@item condition @var{bnum}
5589Remove the condition from breakpoint number @var{bnum}. It becomes
5590an ordinary unconditional breakpoint.
5591@end table
5592
5593@cindex ignore count (of breakpoint)
5594A special case of a breakpoint condition is to stop only when the
5595breakpoint has been reached a certain number of times. This is so
5596useful that there is a special way to do it, using the @dfn{ignore
5597count} of the breakpoint. Every breakpoint has an ignore count, which
5598is an integer. Most of the time, the ignore count is zero, and
5599therefore has no effect. But if your program reaches a breakpoint whose
5600ignore count is positive, then instead of stopping, it just decrements
5601the ignore count by one and continues. As a result, if the ignore count
5602value is @var{n}, the breakpoint does not stop the next @var{n} times
5603your program reaches it.
5604
5605@table @code
5606@kindex ignore
5607@item ignore @var{bnum} @var{count}
5608Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5609The next @var{count} times the breakpoint is reached, your program's
5610execution does not stop; other than to decrement the ignore count, @value{GDBN}
5611takes no action.
5612
5613To make the breakpoint stop the next time it is reached, specify
5614a count of zero.
5615
5616When you use @code{continue} to resume execution of your program from a
5617breakpoint, you can specify an ignore count directly as an argument to
5618@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5619Stepping,,Continuing and Stepping}.
c906108c
SS
5620
5621If a breakpoint has a positive ignore count and a condition, the
5622condition is not checked. Once the ignore count reaches zero,
5623@value{GDBN} resumes checking the condition.
5624
5625You could achieve the effect of the ignore count with a condition such
5626as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5627is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5628Variables}.
c906108c
SS
5629@end table
5630
5631Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5632
5633
6d2ebf8b 5634@node Break Commands
79a6e687 5635@subsection Breakpoint Command Lists
c906108c
SS
5636
5637@cindex breakpoint commands
5638You can give any breakpoint (or watchpoint or catchpoint) a series of
5639commands to execute when your program stops due to that breakpoint. For
5640example, you might want to print the values of certain expressions, or
5641enable other breakpoints.
5642
5643@table @code
5644@kindex commands
ca91424e 5645@kindex end@r{ (breakpoint commands)}
18da0c51 5646@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5647@itemx @dots{} @var{command-list} @dots{}
5648@itemx end
95a42b64 5649Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5650themselves appear on the following lines. Type a line containing just
5651@code{end} to terminate the commands.
5652
5653To remove all commands from a breakpoint, type @code{commands} and
5654follow it immediately with @code{end}; that is, give no commands.
5655
95a42b64
TT
5656With no argument, @code{commands} refers to the last breakpoint,
5657watchpoint, or catchpoint set (not to the breakpoint most recently
5658encountered). If the most recent breakpoints were set with a single
5659command, then the @code{commands} will apply to all the breakpoints
5660set by that command. This applies to breakpoints set by
86b17b60
PA
5661@code{rbreak}, and also applies when a single @code{break} command
5662creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5663Expressions}).
c906108c
SS
5664@end table
5665
5666Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5667disabled within a @var{command-list}.
5668
5669You can use breakpoint commands to start your program up again. Simply
5670use the @code{continue} command, or @code{step}, or any other command
5671that resumes execution.
5672
5673Any other commands in the command list, after a command that resumes
5674execution, are ignored. This is because any time you resume execution
5675(even with a simple @code{next} or @code{step}), you may encounter
5676another breakpoint---which could have its own command list, leading to
5677ambiguities about which list to execute.
5678
5679@kindex silent
5680If the first command you specify in a command list is @code{silent}, the
5681usual message about stopping at a breakpoint is not printed. This may
5682be desirable for breakpoints that are to print a specific message and
5683then continue. If none of the remaining commands print anything, you
5684see no sign that the breakpoint was reached. @code{silent} is
5685meaningful only at the beginning of a breakpoint command list.
5686
5687The commands @code{echo}, @code{output}, and @code{printf} allow you to
5688print precisely controlled output, and are often useful in silent
79a6e687 5689breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5690
5691For example, here is how you could use breakpoint commands to print the
5692value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5693
474c8240 5694@smallexample
c906108c
SS
5695break foo if x>0
5696commands
5697silent
5698printf "x is %d\n",x
5699cont
5700end
474c8240 5701@end smallexample
c906108c
SS
5702
5703One application for breakpoint commands is to compensate for one bug so
5704you can test for another. Put a breakpoint just after the erroneous line
5705of code, give it a condition to detect the case in which something
5706erroneous has been done, and give it commands to assign correct values
5707to any variables that need them. End with the @code{continue} command
5708so that your program does not stop, and start with the @code{silent}
5709command so that no output is produced. Here is an example:
5710
474c8240 5711@smallexample
c906108c
SS
5712break 403
5713commands
5714silent
5715set x = y + 4
5716cont
5717end
474c8240 5718@end smallexample
c906108c 5719
e7e0cddf
SS
5720@node Dynamic Printf
5721@subsection Dynamic Printf
5722
5723@cindex dynamic printf
5724@cindex dprintf
5725The dynamic printf command @code{dprintf} combines a breakpoint with
5726formatted printing of your program's data to give you the effect of
5727inserting @code{printf} calls into your program on-the-fly, without
5728having to recompile it.
5729
5730In its most basic form, the output goes to the GDB console. However,
5731you can set the variable @code{dprintf-style} for alternate handling.
5732For instance, you can ask to format the output by calling your
5733program's @code{printf} function. This has the advantage that the
5734characters go to the program's output device, so they can recorded in
5735redirects to files and so forth.
5736
d3ce09f5
SS
5737If you are doing remote debugging with a stub or agent, you can also
5738ask to have the printf handled by the remote agent. In addition to
5739ensuring that the output goes to the remote program's device along
5740with any other output the program might produce, you can also ask that
5741the dprintf remain active even after disconnecting from the remote
5742target. Using the stub/agent is also more efficient, as it can do
5743everything without needing to communicate with @value{GDBN}.
5744
e7e0cddf
SS
5745@table @code
5746@kindex dprintf
5747@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5748Whenever execution reaches @var{location}, print the values of one or
5749more @var{expressions} under the control of the string @var{template}.
5750To print several values, separate them with commas.
5751
5752@item set dprintf-style @var{style}
5753Set the dprintf output to be handled in one of several different
5754styles enumerated below. A change of style affects all existing
5755dynamic printfs immediately. (If you need individual control over the
5756print commands, simply define normal breakpoints with
5757explicitly-supplied command lists.)
5758
18da0c51 5759@table @code
e7e0cddf
SS
5760@item gdb
5761@kindex dprintf-style gdb
5762Handle the output using the @value{GDBN} @code{printf} command.
5763
5764@item call
5765@kindex dprintf-style call
5766Handle the output by calling a function in your program (normally
5767@code{printf}).
5768
d3ce09f5
SS
5769@item agent
5770@kindex dprintf-style agent
5771Have the remote debugging agent (such as @code{gdbserver}) handle
5772the output itself. This style is only available for agents that
5773support running commands on the target.
18da0c51 5774@end table
d3ce09f5 5775
e7e0cddf
SS
5776@item set dprintf-function @var{function}
5777Set the function to call if the dprintf style is @code{call}. By
5778default its value is @code{printf}. You may set it to any expression.
5779that @value{GDBN} can evaluate to a function, as per the @code{call}
5780command.
5781
5782@item set dprintf-channel @var{channel}
5783Set a ``channel'' for dprintf. If set to a non-empty value,
5784@value{GDBN} will evaluate it as an expression and pass the result as
5785a first argument to the @code{dprintf-function}, in the manner of
5786@code{fprintf} and similar functions. Otherwise, the dprintf format
5787string will be the first argument, in the manner of @code{printf}.
5788
5789As an example, if you wanted @code{dprintf} output to go to a logfile
5790that is a standard I/O stream assigned to the variable @code{mylog},
5791you could do the following:
5792
5793@example
5794(gdb) set dprintf-style call
5795(gdb) set dprintf-function fprintf
5796(gdb) set dprintf-channel mylog
5797(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5798Dprintf 1 at 0x123456: file main.c, line 25.
5799(gdb) info break
58001 dprintf keep y 0x00123456 in main at main.c:25
5801 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5802 continue
5803(gdb)
5804@end example
5805
5806Note that the @code{info break} displays the dynamic printf commands
5807as normal breakpoint commands; you can thus easily see the effect of
5808the variable settings.
5809
d3ce09f5
SS
5810@item set disconnected-dprintf on
5811@itemx set disconnected-dprintf off
5812@kindex set disconnected-dprintf
5813Choose whether @code{dprintf} commands should continue to run if
5814@value{GDBN} has disconnected from the target. This only applies
5815if the @code{dprintf-style} is @code{agent}.
5816
5817@item show disconnected-dprintf off
5818@kindex show disconnected-dprintf
5819Show the current choice for disconnected @code{dprintf}.
5820
e7e0cddf
SS
5821@end table
5822
5823@value{GDBN} does not check the validity of function and channel,
5824relying on you to supply values that are meaningful for the contexts
5825in which they are being used. For instance, the function and channel
5826may be the values of local variables, but if that is the case, then
5827all enabled dynamic prints must be at locations within the scope of
5828those locals. If evaluation fails, @value{GDBN} will report an error.
5829
6149aea9
PA
5830@node Save Breakpoints
5831@subsection How to save breakpoints to a file
5832
5833To save breakpoint definitions to a file use the @w{@code{save
5834breakpoints}} command.
5835
5836@table @code
5837@kindex save breakpoints
5838@cindex save breakpoints to a file for future sessions
5839@item save breakpoints [@var{filename}]
5840This command saves all current breakpoint definitions together with
5841their commands and ignore counts, into a file @file{@var{filename}}
5842suitable for use in a later debugging session. This includes all
5843types of breakpoints (breakpoints, watchpoints, catchpoints,
5844tracepoints). To read the saved breakpoint definitions, use the
5845@code{source} command (@pxref{Command Files}). Note that watchpoints
5846with expressions involving local variables may fail to be recreated
5847because it may not be possible to access the context where the
5848watchpoint is valid anymore. Because the saved breakpoint definitions
5849are simply a sequence of @value{GDBN} commands that recreate the
5850breakpoints, you can edit the file in your favorite editing program,
5851and remove the breakpoint definitions you're not interested in, or
5852that can no longer be recreated.
5853@end table
5854
62e5f89c
SDJ
5855@node Static Probe Points
5856@subsection Static Probe Points
5857
5858@cindex static probe point, SystemTap
3133f8c1 5859@cindex static probe point, DTrace
62e5f89c
SDJ
5860@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5861for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5862runtime code and data footprint, and no dynamic relocations.
5863
5864Currently, the following types of probes are supported on
5865ELF-compatible systems:
5866
5867@itemize @bullet
62e5f89c 5868
3133f8c1
JM
5869@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5870@acronym{SDT} probes@footnote{See
62e5f89c 5871@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5872for more information on how to add @code{SystemTap} @acronym{SDT}
5873probes in your applications.}. @code{SystemTap} probes are usable
5874from assembly, C and C@t{++} languages@footnote{See
5875@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5876for a good reference on how the @acronym{SDT} probes are implemented.}.
5877
5878@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5879@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5880C@t{++} languages.
5881@end itemize
62e5f89c
SDJ
5882
5883@cindex semaphores on static probe points
3133f8c1
JM
5884Some @code{SystemTap} probes have an associated semaphore variable;
5885for instance, this happens automatically if you defined your probe
5886using a DTrace-style @file{.d} file. If your probe has a semaphore,
5887@value{GDBN} will automatically enable it when you specify a
5888breakpoint using the @samp{-probe-stap} notation. But, if you put a
5889breakpoint at a probe's location by some other method (e.g.,
5890@code{break file:line}), then @value{GDBN} will not automatically set
5891the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5892
5893You can examine the available static static probes using @code{info
5894probes}, with optional arguments:
5895
5896@table @code
5897@kindex info probes
3133f8c1
JM
5898@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5899If given, @var{type} is either @code{stap} for listing
5900@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5901probes. If omitted all probes are listed regardless of their types.
5902
62e5f89c
SDJ
5903If given, @var{provider} is a regular expression used to match against provider
5904names when selecting which probes to list. If omitted, probes by all
5905probes from all providers are listed.
5906
5907If given, @var{name} is a regular expression to match against probe names
5908when selecting which probes to list. If omitted, probe names are not
5909considered when deciding whether to display them.
5910
5911If given, @var{objfile} is a regular expression used to select which
5912object files (executable or shared libraries) to examine. If not
5913given, all object files are considered.
5914
5915@item info probes all
5916List the available static probes, from all types.
5917@end table
5918
9aca2ff8
JM
5919@cindex enabling and disabling probes
5920Some probe points can be enabled and/or disabled. The effect of
5921enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5922handled. Some @code{DTrace} probes can be enabled or
5923disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5924
5925You can enable (or disable) one or more probes using the following
5926commands, with optional arguments:
5927
5928@table @code
5929@kindex enable probes
5930@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5931If given, @var{provider} is a regular expression used to match against
5932provider names when selecting which probes to enable. If omitted,
5933all probes from all providers are enabled.
5934
5935If given, @var{name} is a regular expression to match against probe
5936names when selecting which probes to enable. If omitted, probe names
5937are not considered when deciding whether to enable them.
5938
5939If given, @var{objfile} is a regular expression used to select which
5940object files (executable or shared libraries) to examine. If not
5941given, all object files are considered.
5942
5943@kindex disable probes
5944@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5945See the @code{enable probes} command above for a description of the
5946optional arguments accepted by this command.
5947@end table
5948
62e5f89c
SDJ
5949@vindex $_probe_arg@r{, convenience variable}
5950A probe may specify up to twelve arguments. These are available at the
5951point at which the probe is defined---that is, when the current PC is
5952at the probe's location. The arguments are available using the
5953convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5954@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5955probes each probe argument is an integer of the appropriate size;
5956types are not preserved. In @code{DTrace} probes types are preserved
5957provided that they are recognized as such by @value{GDBN}; otherwise
5958the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5959convenience variable @code{$_probe_argc} holds the number of arguments
5960at the current probe point.
5961
5962These variables are always available, but attempts to access them at
5963any location other than a probe point will cause @value{GDBN} to give
5964an error message.
5965
5966
c906108c 5967@c @ifclear BARETARGET
6d2ebf8b 5968@node Error in Breakpoints
d4f3574e 5969@subsection ``Cannot insert breakpoints''
c906108c 5970
fa3a767f
PA
5971If you request too many active hardware-assisted breakpoints and
5972watchpoints, you will see this error message:
d4f3574e
SS
5973
5974@c FIXME: the precise wording of this message may change; the relevant
5975@c source change is not committed yet (Sep 3, 1999).
5976@smallexample
5977Stopped; cannot insert breakpoints.
5978You may have requested too many hardware breakpoints and watchpoints.
5979@end smallexample
5980
5981@noindent
5982This message is printed when you attempt to resume the program, since
5983only then @value{GDBN} knows exactly how many hardware breakpoints and
5984watchpoints it needs to insert.
5985
5986When this message is printed, you need to disable or remove some of the
5987hardware-assisted breakpoints and watchpoints, and then continue.
5988
79a6e687 5989@node Breakpoint-related Warnings
1485d690
KB
5990@subsection ``Breakpoint address adjusted...''
5991@cindex breakpoint address adjusted
5992
5993Some processor architectures place constraints on the addresses at
5994which breakpoints may be placed. For architectures thus constrained,
5995@value{GDBN} will attempt to adjust the breakpoint's address to comply
5996with the constraints dictated by the architecture.
5997
5998One example of such an architecture is the Fujitsu FR-V. The FR-V is
5999a VLIW architecture in which a number of RISC-like instructions may be
6000bundled together for parallel execution. The FR-V architecture
6001constrains the location of a breakpoint instruction within such a
6002bundle to the instruction with the lowest address. @value{GDBN}
6003honors this constraint by adjusting a breakpoint's address to the
6004first in the bundle.
6005
6006It is not uncommon for optimized code to have bundles which contain
6007instructions from different source statements, thus it may happen that
6008a breakpoint's address will be adjusted from one source statement to
6009another. Since this adjustment may significantly alter @value{GDBN}'s
6010breakpoint related behavior from what the user expects, a warning is
6011printed when the breakpoint is first set and also when the breakpoint
6012is hit.
6013
6014A warning like the one below is printed when setting a breakpoint
6015that's been subject to address adjustment:
6016
6017@smallexample
6018warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6019@end smallexample
6020
6021Such warnings are printed both for user settable and @value{GDBN}'s
6022internal breakpoints. If you see one of these warnings, you should
6023verify that a breakpoint set at the adjusted address will have the
6024desired affect. If not, the breakpoint in question may be removed and
b383017d 6025other breakpoints may be set which will have the desired behavior.
1485d690
KB
6026E.g., it may be sufficient to place the breakpoint at a later
6027instruction. A conditional breakpoint may also be useful in some
6028cases to prevent the breakpoint from triggering too often.
6029
6030@value{GDBN} will also issue a warning when stopping at one of these
6031adjusted breakpoints:
6032
6033@smallexample
6034warning: Breakpoint 1 address previously adjusted from 0x00010414
6035to 0x00010410.
6036@end smallexample
6037
6038When this warning is encountered, it may be too late to take remedial
6039action except in cases where the breakpoint is hit earlier or more
6040frequently than expected.
d4f3574e 6041
6d2ebf8b 6042@node Continuing and Stepping
79a6e687 6043@section Continuing and Stepping
c906108c
SS
6044
6045@cindex stepping
6046@cindex continuing
6047@cindex resuming execution
6048@dfn{Continuing} means resuming program execution until your program
6049completes normally. In contrast, @dfn{stepping} means executing just
6050one more ``step'' of your program, where ``step'' may mean either one
6051line of source code, or one machine instruction (depending on what
7a292a7a
SS
6052particular command you use). Either when continuing or when stepping,
6053your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 6054it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
6055@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6056or you may step into the signal's handler (@pxref{stepping and signal
6057handlers}).)
c906108c
SS
6058
6059@table @code
6060@kindex continue
41afff9a
EZ
6061@kindex c @r{(@code{continue})}
6062@kindex fg @r{(resume foreground execution)}
c906108c
SS
6063@item continue @r{[}@var{ignore-count}@r{]}
6064@itemx c @r{[}@var{ignore-count}@r{]}
6065@itemx fg @r{[}@var{ignore-count}@r{]}
6066Resume program execution, at the address where your program last stopped;
6067any breakpoints set at that address are bypassed. The optional argument
6068@var{ignore-count} allows you to specify a further number of times to
6069ignore a breakpoint at this location; its effect is like that of
79a6e687 6070@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
6071
6072The argument @var{ignore-count} is meaningful only when your program
6073stopped due to a breakpoint. At other times, the argument to
6074@code{continue} is ignored.
6075
d4f3574e
SS
6076The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6077debugged program is deemed to be the foreground program) are provided
6078purely for convenience, and have exactly the same behavior as
6079@code{continue}.
c906108c
SS
6080@end table
6081
6082To resume execution at a different place, you can use @code{return}
79a6e687 6083(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 6084calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 6085Different Address}) to go to an arbitrary location in your program.
c906108c
SS
6086
6087A typical technique for using stepping is to set a breakpoint
79a6e687 6088(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
6089beginning of the function or the section of your program where a problem
6090is believed to lie, run your program until it stops at that breakpoint,
6091and then step through the suspect area, examining the variables that are
6092interesting, until you see the problem happen.
6093
6094@table @code
6095@kindex step
41afff9a 6096@kindex s @r{(@code{step})}
c906108c
SS
6097@item step
6098Continue running your program until control reaches a different source
6099line, then stop it and return control to @value{GDBN}. This command is
6100abbreviated @code{s}.
6101
6102@quotation
6103@c "without debugging information" is imprecise; actually "without line
6104@c numbers in the debugging information". (gcc -g1 has debugging info but
6105@c not line numbers). But it seems complex to try to make that
6106@c distinction here.
6107@emph{Warning:} If you use the @code{step} command while control is
6108within a function that was compiled without debugging information,
6109execution proceeds until control reaches a function that does have
6110debugging information. Likewise, it will not step into a function which
6111is compiled without debugging information. To step through functions
6112without debugging information, use the @code{stepi} command, described
6113below.
6114@end quotation
6115
4a92d011
EZ
6116The @code{step} command only stops at the first instruction of a source
6117line. This prevents the multiple stops that could otherwise occur in
6118@code{switch} statements, @code{for} loops, etc. @code{step} continues
6119to stop if a function that has debugging information is called within
6120the line. In other words, @code{step} @emph{steps inside} any functions
6121called within the line.
c906108c 6122
d4f3574e
SS
6123Also, the @code{step} command only enters a function if there is line
6124number information for the function. Otherwise it acts like the
5d161b24 6125@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 6126on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 6127was any debugging information about the routine.
c906108c
SS
6128
6129@item step @var{count}
6130Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
6131breakpoint is reached, or a signal not related to stepping occurs before
6132@var{count} steps, stepping stops right away.
c906108c
SS
6133
6134@kindex next
41afff9a 6135@kindex n @r{(@code{next})}
c906108c
SS
6136@item next @r{[}@var{count}@r{]}
6137Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
6138This is similar to @code{step}, but function calls that appear within
6139the line of code are executed without stopping. Execution stops when
6140control reaches a different line of code at the original stack level
6141that was executing when you gave the @code{next} command. This command
6142is abbreviated @code{n}.
c906108c
SS
6143
6144An argument @var{count} is a repeat count, as for @code{step}.
6145
6146
6147@c FIX ME!! Do we delete this, or is there a way it fits in with
6148@c the following paragraph? --- Vctoria
6149@c
6150@c @code{next} within a function that lacks debugging information acts like
6151@c @code{step}, but any function calls appearing within the code of the
6152@c function are executed without stopping.
6153
d4f3574e
SS
6154The @code{next} command only stops at the first instruction of a
6155source line. This prevents multiple stops that could otherwise occur in
4a92d011 6156@code{switch} statements, @code{for} loops, etc.
c906108c 6157
b90a5f51
CF
6158@kindex set step-mode
6159@item set step-mode
6160@cindex functions without line info, and stepping
6161@cindex stepping into functions with no line info
6162@itemx set step-mode on
4a92d011 6163The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
6164stop at the first instruction of a function which contains no debug line
6165information rather than stepping over it.
6166
4a92d011
EZ
6167This is useful in cases where you may be interested in inspecting the
6168machine instructions of a function which has no symbolic info and do not
6169want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
6170
6171@item set step-mode off
4a92d011 6172Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
6173debug information. This is the default.
6174
9c16f35a
EZ
6175@item show step-mode
6176Show whether @value{GDBN} will stop in or step over functions without
6177source line debug information.
6178
c906108c 6179@kindex finish
8dfa32fc 6180@kindex fin @r{(@code{finish})}
c906108c
SS
6181@item finish
6182Continue running until just after function in the selected stack frame
8dfa32fc
JB
6183returns. Print the returned value (if any). This command can be
6184abbreviated as @code{fin}.
c906108c
SS
6185
6186Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 6187,Returning from a Function}).
c906108c 6188
000439d5
TT
6189@kindex set print finish
6190@kindex show print finish
6191@item set print finish @r{[}on|off@r{]}
6192@itemx show print finish
6193By default the @code{finish} command will show the value that is
6194returned by the function. This can be disabled using @code{set print
6195finish off}. When disabled, the value is still entered into the value
6196history (@pxref{Value History}), but not displayed.
6197
c906108c 6198@kindex until
41afff9a 6199@kindex u @r{(@code{until})}
09d4efe1 6200@cindex run until specified location
c906108c
SS
6201@item until
6202@itemx u
6203Continue running until a source line past the current line, in the
6204current stack frame, is reached. This command is used to avoid single
6205stepping through a loop more than once. It is like the @code{next}
6206command, except that when @code{until} encounters a jump, it
6207automatically continues execution until the program counter is greater
6208than the address of the jump.
6209
6210This means that when you reach the end of a loop after single stepping
6211though it, @code{until} makes your program continue execution until it
6212exits the loop. In contrast, a @code{next} command at the end of a loop
6213simply steps back to the beginning of the loop, which forces you to step
6214through the next iteration.
6215
6216@code{until} always stops your program if it attempts to exit the current
6217stack frame.
6218
6219@code{until} may produce somewhat counterintuitive results if the order
6220of machine code does not match the order of the source lines. For
6221example, in the following excerpt from a debugging session, the @code{f}
6222(@code{frame}) command shows that execution is stopped at line
6223@code{206}; yet when we use @code{until}, we get to line @code{195}:
6224
474c8240 6225@smallexample
c906108c
SS
6226(@value{GDBP}) f
6227#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6228206 expand_input();
6229(@value{GDBP}) until
6230195 for ( ; argc > 0; NEXTARG) @{
474c8240 6231@end smallexample
c906108c
SS
6232
6233This happened because, for execution efficiency, the compiler had
6234generated code for the loop closure test at the end, rather than the
6235start, of the loop---even though the test in a C @code{for}-loop is
6236written before the body of the loop. The @code{until} command appeared
6237to step back to the beginning of the loop when it advanced to this
6238expression; however, it has not really gone to an earlier
6239statement---not in terms of the actual machine code.
6240
6241@code{until} with no argument works by means of single
6242instruction stepping, and hence is slower than @code{until} with an
6243argument.
6244
6245@item until @var{location}
6246@itemx u @var{location}
697aa1b7
EZ
6247Continue running your program until either the specified @var{location} is
6248reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6249the forms described in @ref{Specify Location}.
6250This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6251hence is quicker than @code{until} without an argument. The specified
6252location is actually reached only if it is in the current frame. This
6253implies that @code{until} can be used to skip over recursive function
6254invocations. For instance in the code below, if the current location is
6255line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6256line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6257invocations have returned.
6258
6259@smallexample
626094 int factorial (int value)
626195 @{
626296 if (value > 1) @{
626397 value *= factorial (value - 1);
626498 @}
626599 return (value);
6266100 @}
6267@end smallexample
6268
6269
6270@kindex advance @var{location}
984359d2 6271@item advance @var{location}
09d4efe1 6272Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6273required, which should be of one of the forms described in
6274@ref{Specify Location}.
6275Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6276frame. This command is similar to @code{until}, but @code{advance} will
6277not skip over recursive function calls, and the target location doesn't
6278have to be in the same frame as the current one.
6279
c906108c
SS
6280
6281@kindex stepi
41afff9a 6282@kindex si @r{(@code{stepi})}
c906108c 6283@item stepi
96a2c332 6284@itemx stepi @var{arg}
c906108c
SS
6285@itemx si
6286Execute one machine instruction, then stop and return to the debugger.
6287
6288It is often useful to do @samp{display/i $pc} when stepping by machine
6289instructions. This makes @value{GDBN} automatically display the next
6290instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6291Display,, Automatic Display}.
c906108c
SS
6292
6293An argument is a repeat count, as in @code{step}.
6294
6295@need 750
6296@kindex nexti
41afff9a 6297@kindex ni @r{(@code{nexti})}
c906108c 6298@item nexti
96a2c332 6299@itemx nexti @var{arg}
c906108c
SS
6300@itemx ni
6301Execute one machine instruction, but if it is a function call,
6302proceed until the function returns.
6303
6304An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6305
6306@end table
6307
6308@anchor{range stepping}
6309@cindex range stepping
6310@cindex target-assisted range stepping
6311By default, and if available, @value{GDBN} makes use of
6312target-assisted @dfn{range stepping}. In other words, whenever you
6313use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6314tells the target to step the corresponding range of instruction
6315addresses instead of issuing multiple single-steps. This speeds up
6316line stepping, particularly for remote targets. Ideally, there should
6317be no reason you would want to turn range stepping off. However, it's
6318possible that a bug in the debug info, a bug in the remote stub (for
6319remote targets), or even a bug in @value{GDBN} could make line
6320stepping behave incorrectly when target-assisted range stepping is
6321enabled. You can use the following command to turn off range stepping
6322if necessary:
6323
6324@table @code
6325@kindex set range-stepping
6326@kindex show range-stepping
6327@item set range-stepping
6328@itemx show range-stepping
6329Control whether range stepping is enabled.
6330
6331If @code{on}, and the target supports it, @value{GDBN} tells the
6332target to step a range of addresses itself, instead of issuing
6333multiple single-steps. If @code{off}, @value{GDBN} always issues
6334single-steps, even if range stepping is supported by the target. The
6335default is @code{on}.
6336
c906108c
SS
6337@end table
6338
aad1c02c
TT
6339@node Skipping Over Functions and Files
6340@section Skipping Over Functions and Files
1bfeeb0f
JL
6341@cindex skipping over functions and files
6342
6343The program you are debugging may contain some functions which are
8244c20d 6344uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6345skip a function, all functions in a file or a particular function in
6346a particular file when stepping.
1bfeeb0f
JL
6347
6348For example, consider the following C function:
6349
6350@smallexample
6351101 int func()
6352102 @{
6353103 foo(boring());
6354104 bar(boring());
6355105 @}
6356@end smallexample
6357
6358@noindent
6359Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6360are not interested in stepping through @code{boring}. If you run @code{step}
6361at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6362step over both @code{foo} and @code{boring}!
6363
6364One solution is to @code{step} into @code{boring} and use the @code{finish}
6365command to immediately exit it. But this can become tedious if @code{boring}
6366is called from many places.
6367
6368A more flexible solution is to execute @kbd{skip boring}. This instructs
6369@value{GDBN} never to step into @code{boring}. Now when you execute
6370@code{step} at line 103, you'll step over @code{boring} and directly into
6371@code{foo}.
6372
cce0e923
DE
6373Functions may be skipped by providing either a function name, linespec
6374(@pxref{Specify Location}), regular expression that matches the function's
6375name, file name or a @code{glob}-style pattern that matches the file name.
6376
6377On Posix systems the form of the regular expression is
6378``Extended Regular Expressions''. See for example @samp{man 7 regex}
6379on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6380expression is whatever is provided by the @code{regcomp} function of
6381the underlying system.
6382See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6383description of @code{glob}-style patterns.
6384
6385@table @code
6386@kindex skip
6387@item skip @r{[}@var{options}@r{]}
6388The basic form of the @code{skip} command takes zero or more options
6389that specify what to skip.
6390The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6391
6392@table @code
cce0e923
DE
6393@item -file @var{file}
6394@itemx -fi @var{file}
6395Functions in @var{file} will be skipped over when stepping.
6396
6397@item -gfile @var{file-glob-pattern}
6398@itemx -gfi @var{file-glob-pattern}
6399@cindex skipping over files via glob-style patterns
6400Functions in files matching @var{file-glob-pattern} will be skipped
6401over when stepping.
6402
6403@smallexample
6404(gdb) skip -gfi utils/*.c
6405@end smallexample
6406
6407@item -function @var{linespec}
6408@itemx -fu @var{linespec}
6409Functions named by @var{linespec} or the function containing the line
6410named by @var{linespec} will be skipped over when stepping.
6411@xref{Specify Location}.
6412
6413@item -rfunction @var{regexp}
6414@itemx -rfu @var{regexp}
6415@cindex skipping over functions via regular expressions
6416Functions whose name matches @var{regexp} will be skipped over when stepping.
6417
6418This form is useful for complex function names.
6419For example, there is generally no need to step into C@t{++} @code{std::string}
6420constructors or destructors. Plus with C@t{++} templates it can be hard to
6421write out the full name of the function, and often it doesn't matter what
6422the template arguments are. Specifying the function to be skipped as a
6423regular expression makes this easier.
6424
6425@smallexample
6426(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6427@end smallexample
6428
6429If you want to skip every templated C@t{++} constructor and destructor
6430in the @code{std} namespace you can do:
6431
6432@smallexample
6433(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6434@end smallexample
6435@end table
6436
6437If no options are specified, the function you're currently debugging
6438will be skipped.
6439
1bfeeb0f 6440@kindex skip function
cce0e923 6441@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6442After running this command, the function named by @var{linespec} or the
6443function containing the line named by @var{linespec} will be skipped over when
983fb131 6444stepping. @xref{Specify Location}.
1bfeeb0f
JL
6445
6446If you do not specify @var{linespec}, the function you're currently debugging
6447will be skipped.
6448
6449(If you have a function called @code{file} that you want to skip, use
6450@kbd{skip function file}.)
6451
6452@kindex skip file
6453@item skip file @r{[}@var{filename}@r{]}
6454After running this command, any function whose source lives in @var{filename}
6455will be skipped over when stepping.
6456
cce0e923
DE
6457@smallexample
6458(gdb) skip file boring.c
6459File boring.c will be skipped when stepping.
6460@end smallexample
6461
1bfeeb0f
JL
6462If you do not specify @var{filename}, functions whose source lives in the file
6463you're currently debugging will be skipped.
6464@end table
6465
6466Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6467These are the commands for managing your list of skips:
6468
6469@table @code
6470@kindex info skip
6471@item info skip @r{[}@var{range}@r{]}
6472Print details about the specified skip(s). If @var{range} is not specified,
6473print a table with details about all functions and files marked for skipping.
6474@code{info skip} prints the following information about each skip:
6475
6476@table @emph
6477@item Identifier
6478A number identifying this skip.
1bfeeb0f 6479@item Enabled or Disabled
cce0e923
DE
6480Enabled skips are marked with @samp{y}.
6481Disabled skips are marked with @samp{n}.
6482@item Glob
6483If the file name is a @samp{glob} pattern this is @samp{y}.
6484Otherwise it is @samp{n}.
6485@item File
6486The name or @samp{glob} pattern of the file to be skipped.
6487If no file is specified this is @samp{<none>}.
6488@item RE
6489If the function name is a @samp{regular expression} this is @samp{y}.
6490Otherwise it is @samp{n}.
6491@item Function
6492The name or regular expression of the function to skip.
6493If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6494@end table
6495
6496@kindex skip delete
6497@item skip delete @r{[}@var{range}@r{]}
6498Delete the specified skip(s). If @var{range} is not specified, delete all
6499skips.
6500
6501@kindex skip enable
6502@item skip enable @r{[}@var{range}@r{]}
6503Enable the specified skip(s). If @var{range} is not specified, enable all
6504skips.
6505
6506@kindex skip disable
6507@item skip disable @r{[}@var{range}@r{]}
6508Disable the specified skip(s). If @var{range} is not specified, disable all
6509skips.
6510
3e68067f
SM
6511@kindex set debug skip
6512@item set debug skip @r{[}on|off@r{]}
6513Set whether to print the debug output about skipping files and functions.
6514
6515@kindex show debug skip
6516@item show debug skip
6517Show whether the debug output about skipping files and functions is printed.
6518
1bfeeb0f
JL
6519@end table
6520
6d2ebf8b 6521@node Signals
c906108c
SS
6522@section Signals
6523@cindex signals
6524
6525A signal is an asynchronous event that can happen in a program. The
6526operating system defines the possible kinds of signals, and gives each
6527kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6528signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6529@code{SIGSEGV} is the signal a program gets from referencing a place in
6530memory far away from all the areas in use; @code{SIGALRM} occurs when
6531the alarm clock timer goes off (which happens only if your program has
6532requested an alarm).
6533
6534@cindex fatal signals
6535Some signals, including @code{SIGALRM}, are a normal part of the
6536functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6537errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6538program has not specified in advance some other way to handle the signal.
6539@code{SIGINT} does not indicate an error in your program, but it is normally
6540fatal so it can carry out the purpose of the interrupt: to kill the program.
6541
6542@value{GDBN} has the ability to detect any occurrence of a signal in your
6543program. You can tell @value{GDBN} in advance what to do for each kind of
6544signal.
6545
6546@cindex handling signals
24f93129
EZ
6547Normally, @value{GDBN} is set up to let the non-erroneous signals like
6548@code{SIGALRM} be silently passed to your program
6549(so as not to interfere with their role in the program's functioning)
c906108c
SS
6550but to stop your program immediately whenever an error signal happens.
6551You can change these settings with the @code{handle} command.
6552
6553@table @code
6554@kindex info signals
09d4efe1 6555@kindex info handle
c906108c 6556@item info signals
96a2c332 6557@itemx info handle
c906108c
SS
6558Print a table of all the kinds of signals and how @value{GDBN} has been told to
6559handle each one. You can use this to see the signal numbers of all
6560the defined types of signals.
6561
45ac1734
EZ
6562@item info signals @var{sig}
6563Similar, but print information only about the specified signal number.
6564
d4f3574e 6565@code{info handle} is an alias for @code{info signals}.
c906108c 6566
ab04a2af
TT
6567@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6568Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6569for details about this command.
6570
c906108c 6571@kindex handle
45ac1734 6572@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6573Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6574can be the number of a signal or its name (with or without the
24f93129 6575@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6576@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6577known signals. Optional arguments @var{keywords}, described below,
6578say what change to make.
c906108c
SS
6579@end table
6580
6581@c @group
6582The keywords allowed by the @code{handle} command can be abbreviated.
6583Their full names are:
6584
6585@table @code
6586@item nostop
6587@value{GDBN} should not stop your program when this signal happens. It may
6588still print a message telling you that the signal has come in.
6589
6590@item stop
6591@value{GDBN} should stop your program when this signal happens. This implies
6592the @code{print} keyword as well.
6593
6594@item print
6595@value{GDBN} should print a message when this signal happens.
6596
6597@item noprint
6598@value{GDBN} should not mention the occurrence of the signal at all. This
6599implies the @code{nostop} keyword as well.
6600
6601@item pass
5ece1a18 6602@itemx noignore
c906108c
SS
6603@value{GDBN} should allow your program to see this signal; your program
6604can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6605and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6606
6607@item nopass
5ece1a18 6608@itemx ignore
c906108c 6609@value{GDBN} should not allow your program to see this signal.
5ece1a18 6610@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6611@end table
6612@c @end group
6613
d4f3574e
SS
6614When a signal stops your program, the signal is not visible to the
6615program until you
c906108c
SS
6616continue. Your program sees the signal then, if @code{pass} is in
6617effect for the signal in question @emph{at that time}. In other words,
6618after @value{GDBN} reports a signal, you can use the @code{handle}
6619command with @code{pass} or @code{nopass} to control whether your
6620program sees that signal when you continue.
6621
24f93129
EZ
6622The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6623non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6624@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6625erroneous signals.
6626
c906108c
SS
6627You can also use the @code{signal} command to prevent your program from
6628seeing a signal, or cause it to see a signal it normally would not see,
6629or to give it any signal at any time. For example, if your program stopped
6630due to some sort of memory reference error, you might store correct
6631values into the erroneous variables and continue, hoping to see more
6632execution; but your program would probably terminate immediately as
6633a result of the fatal signal once it saw the signal. To prevent this,
6634you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6635Program a Signal}.
c906108c 6636
e5f8a7cc
PA
6637@cindex stepping and signal handlers
6638@anchor{stepping and signal handlers}
6639
6640@value{GDBN} optimizes for stepping the mainline code. If a signal
6641that has @code{handle nostop} and @code{handle pass} set arrives while
6642a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6643in progress, @value{GDBN} lets the signal handler run and then resumes
6644stepping the mainline code once the signal handler returns. In other
6645words, @value{GDBN} steps over the signal handler. This prevents
6646signals that you've specified as not interesting (with @code{handle
6647nostop}) from changing the focus of debugging unexpectedly. Note that
6648the signal handler itself may still hit a breakpoint, stop for another
6649signal that has @code{handle stop} in effect, or for any other event
6650that normally results in stopping the stepping command sooner. Also
6651note that @value{GDBN} still informs you that the program received a
6652signal if @code{handle print} is set.
6653
6654@anchor{stepping into signal handlers}
6655
6656If you set @code{handle pass} for a signal, and your program sets up a
6657handler for it, then issuing a stepping command, such as @code{step}
6658or @code{stepi}, when your program is stopped due to the signal will
6659step @emph{into} the signal handler (if the target supports that).
6660
6661Likewise, if you use the @code{queue-signal} command to queue a signal
6662to be delivered to the current thread when execution of the thread
6663resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6664stepping command will step into the signal handler.
6665
6666Here's an example, using @code{stepi} to step to the first instruction
6667of @code{SIGUSR1}'s handler:
6668
6669@smallexample
6670(@value{GDBP}) handle SIGUSR1
6671Signal Stop Print Pass to program Description
6672SIGUSR1 Yes Yes Yes User defined signal 1
6673(@value{GDBP}) c
6674Continuing.
6675
6676Program received signal SIGUSR1, User defined signal 1.
6677main () sigusr1.c:28
667828 p = 0;
6679(@value{GDBP}) si
6680sigusr1_handler () at sigusr1.c:9
66819 @{
6682@end smallexample
6683
6684The same, but using @code{queue-signal} instead of waiting for the
6685program to receive the signal first:
6686
6687@smallexample
6688(@value{GDBP}) n
668928 p = 0;
6690(@value{GDBP}) queue-signal SIGUSR1
6691(@value{GDBP}) si
6692sigusr1_handler () at sigusr1.c:9
66939 @{
6694(@value{GDBP})
6695@end smallexample
6696
4aa995e1
PA
6697@cindex extra signal information
6698@anchor{extra signal information}
6699
6700On some targets, @value{GDBN} can inspect extra signal information
6701associated with the intercepted signal, before it is actually
6702delivered to the program being debugged. This information is exported
6703by the convenience variable @code{$_siginfo}, and consists of data
6704that is passed by the kernel to the signal handler at the time of the
6705receipt of a signal. The data type of the information itself is
6706target dependent. You can see the data type using the @code{ptype
6707$_siginfo} command. On Unix systems, it typically corresponds to the
6708standard @code{siginfo_t} type, as defined in the @file{signal.h}
6709system header.
6710
6711Here's an example, on a @sc{gnu}/Linux system, printing the stray
6712referenced address that raised a segmentation fault.
6713
6714@smallexample
6715@group
6716(@value{GDBP}) continue
6717Program received signal SIGSEGV, Segmentation fault.
67180x0000000000400766 in main ()
671969 *(int *)p = 0;
6720(@value{GDBP}) ptype $_siginfo
6721type = struct @{
6722 int si_signo;
6723 int si_errno;
6724 int si_code;
6725 union @{
6726 int _pad[28];
6727 struct @{...@} _kill;
6728 struct @{...@} _timer;
6729 struct @{...@} _rt;
6730 struct @{...@} _sigchld;
6731 struct @{...@} _sigfault;
6732 struct @{...@} _sigpoll;
6733 @} _sifields;
6734@}
6735(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6736type = struct @{
6737 void *si_addr;
6738@}
6739(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6740$1 = (void *) 0x7ffff7ff7000
6741@end group
6742@end smallexample
6743
6744Depending on target support, @code{$_siginfo} may also be writable.
6745
012b3a21
WT
6746@cindex Intel MPX boundary violations
6747@cindex boundary violations, Intel MPX
6748On some targets, a @code{SIGSEGV} can be caused by a boundary
6749violation, i.e., accessing an address outside of the allowed range.
6750In those cases @value{GDBN} may displays additional information,
6751depending on how @value{GDBN} has been told to handle the signal.
6752With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6753kind: "Upper" or "Lower", the memory address accessed and the
6754bounds, while with @code{handle nostop SIGSEGV} no additional
6755information is displayed.
6756
6757The usual output of a segfault is:
6758@smallexample
6759Program received signal SIGSEGV, Segmentation fault
67600x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
676168 value = *(p + len);
6762@end smallexample
6763
6764While a bound violation is presented as:
6765@smallexample
6766Program received signal SIGSEGV, Segmentation fault
6767Upper bound violation while accessing address 0x7fffffffc3b3
6768Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
67690x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
677068 value = *(p + len);
6771@end smallexample
6772
6d2ebf8b 6773@node Thread Stops
79a6e687 6774@section Stopping and Starting Multi-thread Programs
c906108c 6775
0606b73b
SL
6776@cindex stopped threads
6777@cindex threads, stopped
6778
6779@cindex continuing threads
6780@cindex threads, continuing
6781
6782@value{GDBN} supports debugging programs with multiple threads
6783(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6784are two modes of controlling execution of your program within the
6785debugger. In the default mode, referred to as @dfn{all-stop mode},
6786when any thread in your program stops (for example, at a breakpoint
6787or while being stepped), all other threads in the program are also stopped by
6788@value{GDBN}. On some targets, @value{GDBN} also supports
6789@dfn{non-stop mode}, in which other threads can continue to run freely while
6790you examine the stopped thread in the debugger.
6791
6792@menu
6793* All-Stop Mode:: All threads stop when GDB takes control
6794* Non-Stop Mode:: Other threads continue to execute
6795* Background Execution:: Running your program asynchronously
6796* Thread-Specific Breakpoints:: Controlling breakpoints
6797* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6798* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6799@end menu
6800
6801@node All-Stop Mode
6802@subsection All-Stop Mode
6803
6804@cindex all-stop mode
6805
6806In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6807@emph{all} threads of execution stop, not just the current thread. This
6808allows you to examine the overall state of the program, including
6809switching between threads, without worrying that things may change
6810underfoot.
6811
6812Conversely, whenever you restart the program, @emph{all} threads start
6813executing. @emph{This is true even when single-stepping} with commands
6814like @code{step} or @code{next}.
6815
6816In particular, @value{GDBN} cannot single-step all threads in lockstep.
6817Since thread scheduling is up to your debugging target's operating
6818system (not controlled by @value{GDBN}), other threads may
6819execute more than one statement while the current thread completes a
6820single step. Moreover, in general other threads stop in the middle of a
6821statement, rather than at a clean statement boundary, when the program
6822stops.
6823
6824You might even find your program stopped in another thread after
6825continuing or even single-stepping. This happens whenever some other
6826thread runs into a breakpoint, a signal, or an exception before the
6827first thread completes whatever you requested.
6828
6829@cindex automatic thread selection
6830@cindex switching threads automatically
6831@cindex threads, automatic switching
6832Whenever @value{GDBN} stops your program, due to a breakpoint or a
6833signal, it automatically selects the thread where that breakpoint or
6834signal happened. @value{GDBN} alerts you to the context switch with a
6835message such as @samp{[Switching to Thread @var{n}]} to identify the
6836thread.
6837
6838On some OSes, you can modify @value{GDBN}'s default behavior by
6839locking the OS scheduler to allow only a single thread to run.
6840
6841@table @code
6842@item set scheduler-locking @var{mode}
6843@cindex scheduler locking mode
6844@cindex lock scheduler
f2665db5
MM
6845Set the scheduler locking mode. It applies to normal execution,
6846record mode, and replay mode. If it is @code{off}, then there is no
6847locking and any thread may run at any time. If @code{on}, then only
6848the current thread may run when the inferior is resumed. The
6849@code{step} mode optimizes for single-stepping; it prevents other
6850threads from preempting the current thread while you are stepping, so
6851that the focus of debugging does not change unexpectedly. Other
6852threads never get a chance to run when you step, and they are
6853completely free to run when you use commands like @samp{continue},
6854@samp{until}, or @samp{finish}. However, unless another thread hits a
6855breakpoint during its timeslice, @value{GDBN} does not change the
6856current thread away from the thread that you are debugging. The
6857@code{replay} mode behaves like @code{off} in record mode and like
6858@code{on} in replay mode.
0606b73b
SL
6859
6860@item show scheduler-locking
6861Display the current scheduler locking mode.
6862@end table
6863
d4db2f36
PA
6864@cindex resume threads of multiple processes simultaneously
6865By default, when you issue one of the execution commands such as
6866@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6867threads of the current inferior to run. For example, if @value{GDBN}
6868is attached to two inferiors, each with two threads, the
6869@code{continue} command resumes only the two threads of the current
6870inferior. This is useful, for example, when you debug a program that
6871forks and you want to hold the parent stopped (so that, for instance,
6872it doesn't run to exit), while you debug the child. In other
6873situations, you may not be interested in inspecting the current state
6874of any of the processes @value{GDBN} is attached to, and you may want
6875to resume them all until some breakpoint is hit. In the latter case,
6876you can instruct @value{GDBN} to allow all threads of all the
6877inferiors to run with the @w{@code{set schedule-multiple}} command.
6878
6879@table @code
6880@kindex set schedule-multiple
6881@item set schedule-multiple
6882Set the mode for allowing threads of multiple processes to be resumed
6883when an execution command is issued. When @code{on}, all threads of
6884all processes are allowed to run. When @code{off}, only the threads
6885of the current process are resumed. The default is @code{off}. The
6886@code{scheduler-locking} mode takes precedence when set to @code{on},
6887or while you are stepping and set to @code{step}.
6888
6889@item show schedule-multiple
6890Display the current mode for resuming the execution of threads of
6891multiple processes.
6892@end table
6893
0606b73b
SL
6894@node Non-Stop Mode
6895@subsection Non-Stop Mode
6896
6897@cindex non-stop mode
6898
6899@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6900@c with more details.
0606b73b
SL
6901
6902For some multi-threaded targets, @value{GDBN} supports an optional
6903mode of operation in which you can examine stopped program threads in
6904the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6905minimizes intrusion when debugging live systems, such as programs
6906where some threads have real-time constraints or must continue to
0606b73b
SL
6907respond to external events. This is referred to as @dfn{non-stop} mode.
6908
6909In non-stop mode, when a thread stops to report a debugging event,
6910@emph{only} that thread is stopped; @value{GDBN} does not stop other
6911threads as well, in contrast to the all-stop mode behavior. Additionally,
6912execution commands such as @code{continue} and @code{step} apply by default
6913only to the current thread in non-stop mode, rather than all threads as
6914in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6915ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6916one thread while allowing others to run freely, stepping
97d8f0ee 6917one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6918independently and simultaneously.
6919
6920To enter non-stop mode, use this sequence of commands before you run
6921or attach to your program:
6922
0606b73b 6923@smallexample
0606b73b
SL
6924# If using the CLI, pagination breaks non-stop.
6925set pagination off
6926
6927# Finally, turn it on!
6928set non-stop on
6929@end smallexample
6930
6931You can use these commands to manipulate the non-stop mode setting:
6932
6933@table @code
6934@kindex set non-stop
6935@item set non-stop on
6936Enable selection of non-stop mode.
6937@item set non-stop off
6938Disable selection of non-stop mode.
6939@kindex show non-stop
6940@item show non-stop
6941Show the current non-stop enablement setting.
6942@end table
6943
6944Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6945not whether the currently-executing program is being run in non-stop mode.
0606b73b 6946In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6947@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6948not possible to switch modes once debugging has started. Furthermore,
6949since not all targets support non-stop mode, even when you have enabled
6950non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6951default.
6952
6953In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6954by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6955To continue all threads, issue @code{continue -a} or @code{c -a}.
6956
97d8f0ee 6957You can use @value{GDBN}'s background execution commands
0606b73b 6958(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6959while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6960The MI execution commands (@pxref{GDB/MI Program Execution}) are
6961always executed asynchronously in non-stop mode.
6962
6963Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6964running in the background, or @kbd{Ctrl-c} during foreground execution.
6965In all-stop mode, this stops the whole process;
6966but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6967To stop the whole program, use @code{interrupt -a}.
6968
6969Other execution commands do not currently support the @code{-a} option.
6970
6971In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6972that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6973thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6974command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6975changed to a different thread just as you entered a command to operate on the
6976previously current thread.
6977
6978@node Background Execution
6979@subsection Background Execution
6980
6981@cindex foreground execution
6982@cindex background execution
6983@cindex asynchronous execution
6984@cindex execution, foreground, background and asynchronous
6985
6986@value{GDBN}'s execution commands have two variants: the normal
6987foreground (synchronous) behavior, and a background
97d8f0ee 6988(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6989the program to report that some thread has stopped before prompting for
6990another command. In background execution, @value{GDBN} immediately gives
6991a command prompt so that you can issue other commands while your program runs.
6992
32fc0df9
PA
6993If the target doesn't support async mode, @value{GDBN} issues an error
6994message if you attempt to use the background execution commands.
6995
74fdb8ff 6996@cindex @code{&}, background execution of commands
0606b73b
SL
6997To specify background execution, add a @code{&} to the command. For example,
6998the background form of the @code{continue} command is @code{continue&}, or
6999just @code{c&}. The execution commands that accept background execution
7000are:
7001
7002@table @code
7003@kindex run&
7004@item run
7005@xref{Starting, , Starting your Program}.
7006
7007@item attach
7008@kindex attach&
7009@xref{Attach, , Debugging an Already-running Process}.
7010
7011@item step
7012@kindex step&
7013@xref{Continuing and Stepping, step}.
7014
7015@item stepi
7016@kindex stepi&
7017@xref{Continuing and Stepping, stepi}.
7018
7019@item next
7020@kindex next&
7021@xref{Continuing and Stepping, next}.
7022
7ce58dd2
DE
7023@item nexti
7024@kindex nexti&
7025@xref{Continuing and Stepping, nexti}.
7026
0606b73b
SL
7027@item continue
7028@kindex continue&
7029@xref{Continuing and Stepping, continue}.
7030
7031@item finish
7032@kindex finish&
7033@xref{Continuing and Stepping, finish}.
7034
7035@item until
7036@kindex until&
7037@xref{Continuing and Stepping, until}.
7038
7039@end table
7040
7041Background execution is especially useful in conjunction with non-stop
7042mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7043However, you can also use these commands in the normal all-stop mode with
7044the restriction that you cannot issue another execution command until the
7045previous one finishes. Examples of commands that are valid in all-stop
7046mode while the program is running include @code{help} and @code{info break}.
7047
7048You can interrupt your program while it is running in the background by
7049using the @code{interrupt} command.
7050
7051@table @code
7052@kindex interrupt
7053@item interrupt
7054@itemx interrupt -a
7055
97d8f0ee 7056Suspend execution of the running program. In all-stop mode,
0606b73b 7057@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 7058only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
7059use @code{interrupt -a}.
7060@end table
7061
0606b73b
SL
7062@node Thread-Specific Breakpoints
7063@subsection Thread-Specific Breakpoints
7064
c906108c 7065When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 7066Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
7067breakpoints on all threads, or on a particular thread.
7068
7069@table @code
7070@cindex breakpoints and threads
7071@cindex thread breakpoints
5d5658a1
PA
7072@kindex break @dots{} thread @var{thread-id}
7073@item break @var{location} thread @var{thread-id}
7074@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 7075@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
7076writing them (@pxref{Specify Location}), but the effect is always to
7077specify some source line.
c906108c 7078
5d5658a1 7079Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 7080to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
7081particular thread reaches this breakpoint. The @var{thread-id} specifier
7082is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 7083in the first column of the @samp{info threads} display.
c906108c 7084
5d5658a1 7085If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
7086breakpoint, the breakpoint applies to @emph{all} threads of your
7087program.
7088
7089You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 7090well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 7091after the breakpoint condition, like this:
c906108c
SS
7092
7093@smallexample
2df3850c 7094(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
7095@end smallexample
7096
7097@end table
7098
f4fb82a1
PA
7099Thread-specific breakpoints are automatically deleted when
7100@value{GDBN} detects the corresponding thread is no longer in the
7101thread list. For example:
7102
7103@smallexample
7104(@value{GDBP}) c
7105Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7106@end smallexample
7107
7108There are several ways for a thread to disappear, such as a regular
7109thread exit, but also when you detach from the process with the
7110@code{detach} command (@pxref{Attach, ,Debugging an Already-running
7111Process}), or if @value{GDBN} loses the remote connection
7112(@pxref{Remote Debugging}), etc. Note that with some targets,
7113@value{GDBN} is only able to detect a thread has exited when the user
7114explictly asks for the thread list with the @code{info threads}
7115command.
7116
0606b73b
SL
7117@node Interrupted System Calls
7118@subsection Interrupted System Calls
c906108c 7119
36d86913
MC
7120@cindex thread breakpoints and system calls
7121@cindex system calls and thread breakpoints
7122@cindex premature return from system calls
0606b73b
SL
7123There is an unfortunate side effect when using @value{GDBN} to debug
7124multi-threaded programs. If one thread stops for a
36d86913
MC
7125breakpoint, or for some other reason, and another thread is blocked in a
7126system call, then the system call may return prematurely. This is a
7127consequence of the interaction between multiple threads and the signals
7128that @value{GDBN} uses to implement breakpoints and other events that
7129stop execution.
7130
7131To handle this problem, your program should check the return value of
7132each system call and react appropriately. This is good programming
7133style anyways.
7134
7135For example, do not write code like this:
7136
7137@smallexample
7138 sleep (10);
7139@end smallexample
7140
7141The call to @code{sleep} will return early if a different thread stops
7142at a breakpoint or for some other reason.
7143
7144Instead, write this:
7145
7146@smallexample
7147 int unslept = 10;
7148 while (unslept > 0)
7149 unslept = sleep (unslept);
7150@end smallexample
7151
7152A system call is allowed to return early, so the system is still
7153conforming to its specification. But @value{GDBN} does cause your
7154multi-threaded program to behave differently than it would without
7155@value{GDBN}.
7156
7157Also, @value{GDBN} uses internal breakpoints in the thread library to
7158monitor certain events such as thread creation and thread destruction.
7159When such an event happens, a system call in another thread may return
7160prematurely, even though your program does not appear to stop.
7161
d914c394
SS
7162@node Observer Mode
7163@subsection Observer Mode
7164
7165If you want to build on non-stop mode and observe program behavior
7166without any chance of disruption by @value{GDBN}, you can set
7167variables to disable all of the debugger's attempts to modify state,
7168whether by writing memory, inserting breakpoints, etc. These operate
7169at a low level, intercepting operations from all commands.
7170
7171When all of these are set to @code{off}, then @value{GDBN} is said to
7172be @dfn{observer mode}. As a convenience, the variable
7173@code{observer} can be set to disable these, plus enable non-stop
7174mode.
7175
7176Note that @value{GDBN} will not prevent you from making nonsensical
7177combinations of these settings. For instance, if you have enabled
7178@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7179then breakpoints that work by writing trap instructions into the code
7180stream will still not be able to be placed.
7181
7182@table @code
7183
7184@kindex observer
7185@item set observer on
7186@itemx set observer off
7187When set to @code{on}, this disables all the permission variables
7188below (except for @code{insert-fast-tracepoints}), plus enables
7189non-stop debugging. Setting this to @code{off} switches back to
7190normal debugging, though remaining in non-stop mode.
7191
7192@item show observer
7193Show whether observer mode is on or off.
7194
7195@kindex may-write-registers
7196@item set may-write-registers on
7197@itemx set may-write-registers off
7198This controls whether @value{GDBN} will attempt to alter the values of
7199registers, such as with assignment expressions in @code{print}, or the
7200@code{jump} command. It defaults to @code{on}.
7201
7202@item show may-write-registers
7203Show the current permission to write registers.
7204
7205@kindex may-write-memory
7206@item set may-write-memory on
7207@itemx set may-write-memory off
7208This controls whether @value{GDBN} will attempt to alter the contents
7209of memory, such as with assignment expressions in @code{print}. It
7210defaults to @code{on}.
7211
7212@item show may-write-memory
7213Show the current permission to write memory.
7214
7215@kindex may-insert-breakpoints
7216@item set may-insert-breakpoints on
7217@itemx set may-insert-breakpoints off
7218This controls whether @value{GDBN} will attempt to insert breakpoints.
7219This affects all breakpoints, including internal breakpoints defined
7220by @value{GDBN}. It defaults to @code{on}.
7221
7222@item show may-insert-breakpoints
7223Show the current permission to insert breakpoints.
7224
7225@kindex may-insert-tracepoints
7226@item set may-insert-tracepoints on
7227@itemx set may-insert-tracepoints off
7228This controls whether @value{GDBN} will attempt to insert (regular)
7229tracepoints at the beginning of a tracing experiment. It affects only
7230non-fast tracepoints, fast tracepoints being under the control of
7231@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7232
7233@item show may-insert-tracepoints
7234Show the current permission to insert tracepoints.
7235
7236@kindex may-insert-fast-tracepoints
7237@item set may-insert-fast-tracepoints on
7238@itemx set may-insert-fast-tracepoints off
7239This controls whether @value{GDBN} will attempt to insert fast
7240tracepoints at the beginning of a tracing experiment. It affects only
7241fast tracepoints, regular (non-fast) tracepoints being under the
7242control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7243
7244@item show may-insert-fast-tracepoints
7245Show the current permission to insert fast tracepoints.
7246
7247@kindex may-interrupt
7248@item set may-interrupt on
7249@itemx set may-interrupt off
7250This controls whether @value{GDBN} will attempt to interrupt or stop
7251program execution. When this variable is @code{off}, the
7252@code{interrupt} command will have no effect, nor will
7253@kbd{Ctrl-c}. It defaults to @code{on}.
7254
7255@item show may-interrupt
7256Show the current permission to interrupt or stop the program.
7257
7258@end table
c906108c 7259
bacec72f
MS
7260@node Reverse Execution
7261@chapter Running programs backward
7262@cindex reverse execution
7263@cindex running programs backward
7264
7265When you are debugging a program, it is not unusual to realize that
7266you have gone too far, and some event of interest has already happened.
7267If the target environment supports it, @value{GDBN} can allow you to
7268``rewind'' the program by running it backward.
7269
7270A target environment that supports reverse execution should be able
7271to ``undo'' the changes in machine state that have taken place as the
7272program was executing normally. Variables, registers etc.@: should
7273revert to their previous values. Obviously this requires a great
7274deal of sophistication on the part of the target environment; not
7275all target environments can support reverse execution.
7276
7277When a program is executed in reverse, the instructions that
7278have most recently been executed are ``un-executed'', in reverse
7279order. The program counter runs backward, following the previous
7280thread of execution in reverse. As each instruction is ``un-executed'',
7281the values of memory and/or registers that were changed by that
7282instruction are reverted to their previous states. After executing
7283a piece of source code in reverse, all side effects of that code
7284should be ``undone'', and all variables should be returned to their
7285prior values@footnote{
7286Note that some side effects are easier to undo than others. For instance,
7287memory and registers are relatively easy, but device I/O is hard. Some
7288targets may be able undo things like device I/O, and some may not.
7289
7290The contract between @value{GDBN} and the reverse executing target
7291requires only that the target do something reasonable when
7292@value{GDBN} tells it to execute backwards, and then report the
7293results back to @value{GDBN}. Whatever the target reports back to
7294@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7295assumes that the memory and registers that the target reports are in a
6b92c0d3 7296consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7297}.
7298
73f8a590
PA
7299On some platforms, @value{GDBN} has built-in support for reverse
7300execution, activated with the @code{record} or @code{record btrace}
7301commands. @xref{Process Record and Replay}. Some remote targets,
7302typically full system emulators, support reverse execution directly
7303without requiring any special command.
7304
bacec72f
MS
7305If you are debugging in a target environment that supports
7306reverse execution, @value{GDBN} provides the following commands.
7307
7308@table @code
7309@kindex reverse-continue
7310@kindex rc @r{(@code{reverse-continue})}
7311@item reverse-continue @r{[}@var{ignore-count}@r{]}
7312@itemx rc @r{[}@var{ignore-count}@r{]}
7313Beginning at the point where your program last stopped, start executing
7314in reverse. Reverse execution will stop for breakpoints and synchronous
7315exceptions (signals), just like normal execution. Behavior of
7316asynchronous signals depends on the target environment.
7317
7318@kindex reverse-step
7319@kindex rs @r{(@code{step})}
7320@item reverse-step @r{[}@var{count}@r{]}
7321Run the program backward until control reaches the start of a
7322different source line; then stop it, and return control to @value{GDBN}.
7323
7324Like the @code{step} command, @code{reverse-step} will only stop
7325at the beginning of a source line. It ``un-executes'' the previously
7326executed source line. If the previous source line included calls to
7327debuggable functions, @code{reverse-step} will step (backward) into
7328the called function, stopping at the beginning of the @emph{last}
7329statement in the called function (typically a return statement).
7330
7331Also, as with the @code{step} command, if non-debuggable functions are
7332called, @code{reverse-step} will run thru them backward without stopping.
7333
7334@kindex reverse-stepi
7335@kindex rsi @r{(@code{reverse-stepi})}
7336@item reverse-stepi @r{[}@var{count}@r{]}
7337Reverse-execute one machine instruction. Note that the instruction
7338to be reverse-executed is @emph{not} the one pointed to by the program
7339counter, but the instruction executed prior to that one. For instance,
7340if the last instruction was a jump, @code{reverse-stepi} will take you
7341back from the destination of the jump to the jump instruction itself.
7342
7343@kindex reverse-next
7344@kindex rn @r{(@code{reverse-next})}
7345@item reverse-next @r{[}@var{count}@r{]}
7346Run backward to the beginning of the previous line executed in
7347the current (innermost) stack frame. If the line contains function
7348calls, they will be ``un-executed'' without stopping. Starting from
7349the first line of a function, @code{reverse-next} will take you back
7350to the caller of that function, @emph{before} the function was called,
7351just as the normal @code{next} command would take you from the last
7352line of a function back to its return to its caller
16af530a 7353@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7354
7355@kindex reverse-nexti
7356@kindex rni @r{(@code{reverse-nexti})}
7357@item reverse-nexti @r{[}@var{count}@r{]}
7358Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7359in reverse, except that called functions are ``un-executed'' atomically.
7360That is, if the previously executed instruction was a return from
540aa8e7 7361another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7362in reverse until the call to that function (from the current stack
7363frame) is reached.
7364
7365@kindex reverse-finish
7366@item reverse-finish
7367Just as the @code{finish} command takes you to the point where the
7368current function returns, @code{reverse-finish} takes you to the point
7369where it was called. Instead of ending up at the end of the current
7370function invocation, you end up at the beginning.
7371
7372@kindex set exec-direction
7373@item set exec-direction
7374Set the direction of target execution.
984359d2 7375@item set exec-direction reverse
bacec72f
MS
7376@cindex execute forward or backward in time
7377@value{GDBN} will perform all execution commands in reverse, until the
7378exec-direction mode is changed to ``forward''. Affected commands include
7379@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7380command cannot be used in reverse mode.
7381@item set exec-direction forward
7382@value{GDBN} will perform all execution commands in the normal fashion.
7383This is the default.
7384@end table
7385
c906108c 7386
a2311334
EZ
7387@node Process Record and Replay
7388@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7389@cindex process record and replay
7390@cindex recording inferior's execution and replaying it
7391
8e05493c
EZ
7392On some platforms, @value{GDBN} provides a special @dfn{process record
7393and replay} target that can record a log of the process execution, and
7394replay it later with both forward and reverse execution commands.
a2311334
EZ
7395
7396@cindex replay mode
7397When this target is in use, if the execution log includes the record
7398for the next instruction, @value{GDBN} will debug in @dfn{replay
7399mode}. In the replay mode, the inferior does not really execute code
7400instructions. Instead, all the events that normally happen during
7401code execution are taken from the execution log. While code is not
7402really executed in replay mode, the values of registers (including the
7403program counter register) and the memory of the inferior are still
8e05493c
EZ
7404changed as they normally would. Their contents are taken from the
7405execution log.
a2311334
EZ
7406
7407@cindex record mode
7408If the record for the next instruction is not in the execution log,
7409@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7410inferior executes normally, and @value{GDBN} records the execution log
7411for future replay.
7412
8e05493c
EZ
7413The process record and replay target supports reverse execution
7414(@pxref{Reverse Execution}), even if the platform on which the
7415inferior runs does not. However, the reverse execution is limited in
7416this case by the range of the instructions recorded in the execution
7417log. In other words, reverse execution on platforms that don't
7418support it directly can only be done in the replay mode.
7419
7420When debugging in the reverse direction, @value{GDBN} will work in
7421replay mode as long as the execution log includes the record for the
7422previous instruction; otherwise, it will work in record mode, if the
7423platform supports reverse execution, or stop if not.
7424
73f8a590
PA
7425Currently, process record and replay is supported on ARM, Aarch64,
7426Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7427GNU/Linux. Process record and replay can be used both when native
7428debugging, and when remote debugging via @code{gdbserver}.
7429
a2311334
EZ
7430For architecture environments that support process record and replay,
7431@value{GDBN} provides the following commands:
53cc454a
HZ
7432
7433@table @code
7434@kindex target record
59ea5688
MM
7435@kindex target record-full
7436@kindex target record-btrace
53cc454a 7437@kindex record
59ea5688
MM
7438@kindex record full
7439@kindex record btrace
f4abbc16 7440@kindex record btrace bts
b20a6524 7441@kindex record btrace pt
f4abbc16 7442@kindex record bts
b20a6524 7443@kindex record pt
53cc454a 7444@kindex rec
59ea5688
MM
7445@kindex rec full
7446@kindex rec btrace
f4abbc16 7447@kindex rec btrace bts
b20a6524 7448@kindex rec btrace pt
f4abbc16 7449@kindex rec bts
b20a6524 7450@kindex rec pt
59ea5688
MM
7451@item record @var{method}
7452This command starts the process record and replay target. The
7453recording method can be specified as parameter. Without a parameter
7454the command uses the @code{full} recording method. The following
7455recording methods are available:
a2311334 7456
59ea5688
MM
7457@table @code
7458@item full
7459Full record/replay recording using @value{GDBN}'s software record and
7460replay implementation. This method allows replaying and reverse
7461execution.
7462
f4abbc16 7463@item btrace @var{format}
73f8a590
PA
7464Hardware-supported instruction recording, supported on Intel
7465processors. This method does not record data. Further, the data is
7466collected in a ring buffer so old data will be overwritten when the
7467buffer is full. It allows limited reverse execution. Variables and
7468registers are not available during reverse execution. In remote
7469debugging, recording continues on disconnect. Recorded data can be
7470inspected after reconnecting. The recording may be stopped using
7471@code{record stop}.
59ea5688 7472
f4abbc16
MM
7473The recording format can be specified as parameter. Without a parameter
7474the command chooses the recording format. The following recording
7475formats are available:
7476
7477@table @code
7478@item bts
7479@cindex branch trace store
7480Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7481this format, the processor stores a from/to record for each executed
7482branch in the btrace ring buffer.
b20a6524
MM
7483
7484@item pt
bc504a31
PA
7485@cindex Intel Processor Trace
7486Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7487format, the processor stores the execution trace in a compressed form
7488that is afterwards decoded by @value{GDBN}.
7489
7490The trace can be recorded with very low overhead. The compressed
7491trace format also allows small trace buffers to already contain a big
7492number of instructions compared to @acronym{BTS}.
7493
7494Decoding the recorded execution trace, on the other hand, is more
7495expensive than decoding @acronym{BTS} trace. This is mostly due to the
7496increased number of instructions to process. You should increase the
7497buffer-size with care.
f4abbc16
MM
7498@end table
7499
7500Not all recording formats may be available on all processors.
59ea5688
MM
7501@end table
7502
7503The process record and replay target can only debug a process that is
7504already running. Therefore, you need first to start the process with
7505the @kbd{run} or @kbd{start} commands, and then start the recording
7506with the @kbd{record @var{method}} command.
7507
a2311334
EZ
7508@cindex displaced stepping, and process record and replay
7509Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7510will be automatically disabled when process record and replay target
7511is started. That's because the process record and replay target
7512doesn't support displaced stepping.
7513
7514@cindex non-stop mode, and process record and replay
7515@cindex asynchronous execution, and process record and replay
7516If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7517the asynchronous execution mode (@pxref{Background Execution}), not
7518all recording methods are available. The @code{full} recording method
7519does not support these two modes.
53cc454a
HZ
7520
7521@kindex record stop
7522@kindex rec s
7523@item record stop
a2311334
EZ
7524Stop the process record and replay target. When process record and
7525replay target stops, the entire execution log will be deleted and the
7526inferior will either be terminated, or will remain in its final state.
53cc454a 7527
a2311334
EZ
7528When you stop the process record and replay target in record mode (at
7529the end of the execution log), the inferior will be stopped at the
7530next instruction that would have been recorded. In other words, if
7531you record for a while and then stop recording, the inferior process
7532will be left in the same state as if the recording never happened.
53cc454a 7533
a2311334
EZ
7534On the other hand, if the process record and replay target is stopped
7535while in replay mode (that is, not at the end of the execution log,
7536but at some earlier point), the inferior process will become ``live''
7537at that earlier state, and it will then be possible to continue the
7538usual ``live'' debugging of the process from that state.
53cc454a 7539
a2311334
EZ
7540When the inferior process exits, or @value{GDBN} detaches from it,
7541process record and replay target will automatically stop itself.
53cc454a 7542
742ce053
MM
7543@kindex record goto
7544@item record goto
7545Go to a specific location in the execution log. There are several
7546ways to specify the location to go to:
7547
7548@table @code
7549@item record goto begin
7550@itemx record goto start
7551Go to the beginning of the execution log.
7552
7553@item record goto end
7554Go to the end of the execution log.
7555
7556@item record goto @var{n}
7557Go to instruction number @var{n} in the execution log.
7558@end table
7559
24e933df
HZ
7560@kindex record save
7561@item record save @var{filename}
7562Save the execution log to a file @file{@var{filename}}.
7563Default filename is @file{gdb_record.@var{process_id}}, where
7564@var{process_id} is the process ID of the inferior.
7565
59ea5688
MM
7566This command may not be available for all recording methods.
7567
24e933df
HZ
7568@kindex record restore
7569@item record restore @var{filename}
7570Restore the execution log from a file @file{@var{filename}}.
7571File must have been created with @code{record save}.
7572
59ea5688
MM
7573@kindex set record full
7574@item set record full insn-number-max @var{limit}
f81d1120 7575@itemx set record full insn-number-max unlimited
59ea5688
MM
7576Set the limit of instructions to be recorded for the @code{full}
7577recording method. Default value is 200000.
53cc454a 7578
a2311334
EZ
7579If @var{limit} is a positive number, then @value{GDBN} will start
7580deleting instructions from the log once the number of the record
7581instructions becomes greater than @var{limit}. For every new recorded
7582instruction, @value{GDBN} will delete the earliest recorded
7583instruction to keep the number of recorded instructions at the limit.
7584(Since deleting recorded instructions loses information, @value{GDBN}
7585lets you control what happens when the limit is reached, by means of
7586the @code{stop-at-limit} option, described below.)
53cc454a 7587
f81d1120
PA
7588If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7589delete recorded instructions from the execution log. The number of
7590recorded instructions is limited only by the available memory.
53cc454a 7591
59ea5688
MM
7592@kindex show record full
7593@item show record full insn-number-max
7594Show the limit of instructions to be recorded with the @code{full}
7595recording method.
53cc454a 7596
59ea5688
MM
7597@item set record full stop-at-limit
7598Control the behavior of the @code{full} recording method when the
7599number of recorded instructions reaches the limit. If ON (the
7600default), @value{GDBN} will stop when the limit is reached for the
7601first time and ask you whether you want to stop the inferior or
7602continue running it and recording the execution log. If you decide
7603to continue recording, each new recorded instruction will cause the
7604oldest one to be deleted.
53cc454a 7605
a2311334
EZ
7606If this option is OFF, @value{GDBN} will automatically delete the
7607oldest record to make room for each new one, without asking.
53cc454a 7608
59ea5688 7609@item show record full stop-at-limit
a2311334 7610Show the current setting of @code{stop-at-limit}.
53cc454a 7611
59ea5688 7612@item set record full memory-query
bb08c432 7613Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7614changes caused by an instruction for the @code{full} recording method.
7615If ON, @value{GDBN} will query whether to stop the inferior in that
7616case.
bb08c432
HZ
7617
7618If this option is OFF (the default), @value{GDBN} will automatically
7619ignore the effect of such instructions on memory. Later, when
7620@value{GDBN} replays this execution log, it will mark the log of this
7621instruction as not accessible, and it will not affect the replay
7622results.
7623
59ea5688 7624@item show record full memory-query
bb08c432
HZ
7625Show the current setting of @code{memory-query}.
7626
67b5c0c1
MM
7627@kindex set record btrace
7628The @code{btrace} record target does not trace data. As a
7629convenience, when replaying, @value{GDBN} reads read-only memory off
7630the live program directly, assuming that the addresses of the
7631read-only areas don't change. This for example makes it possible to
7632disassemble code while replaying, but not to print variables.
7633In some cases, being able to inspect variables might be useful.
7634You can use the following command for that:
7635
7636@item set record btrace replay-memory-access
7637Control the behavior of the @code{btrace} recording method when
7638accessing memory during replay. If @code{read-only} (the default),
7639@value{GDBN} will only allow accesses to read-only memory.
7640If @code{read-write}, @value{GDBN} will allow accesses to read-only
7641and to read-write memory. Beware that the accessed memory corresponds
7642to the live target and not necessarily to the current replay
7643position.
7644
4a4495d6
MM
7645@item set record btrace cpu @var{identifier}
7646Set the processor to be used for enabling workarounds for processor
7647errata when decoding the trace.
7648
7649Processor errata are defects in processor operation, caused by its
7650design or manufacture. They can cause a trace not to match the
7651specification. This, in turn, may cause trace decode to fail.
7652@value{GDBN} can detect erroneous trace packets and correct them, thus
7653avoiding the decoding failures. These corrections are known as
7654@dfn{errata workarounds}, and are enabled based on the processor on
7655which the trace was recorded.
7656
7657By default, @value{GDBN} attempts to detect the processor
7658automatically, and apply the necessary workarounds for it. However,
7659you may need to specify the processor if @value{GDBN} does not yet
7660support it. This command allows you to do that, and also allows to
7661disable the workarounds.
7662
7663The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7664form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7665there are two special identifiers, @code{none} and @code{auto}
7666(default).
7667
7668The following vendor identifiers and corresponding processor
7669identifiers are currently supported:
7670
7671@multitable @columnfractions .1 .9
7672
7673@item @code{intel}
7674@tab @var{family}/@var{model}[/@var{stepping}]
7675
7676@end multitable
7677
7678On GNU/Linux systems, the processor @var{family}, @var{model}, and
7679@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7680
7681If @var{identifier} is @code{auto}, enable errata workarounds for the
7682processor on which the trace was recorded. If @var{identifier} is
7683@code{none}, errata workarounds are disabled.
7684
7685For example, when using an old @value{GDBN} on a new system, decode
7686may fail because @value{GDBN} does not support the new processor. It
7687often suffices to specify an older processor that @value{GDBN}
7688supports.
7689
7690@smallexample
7691(gdb) info record
7692Active record target: record-btrace
7693Recording format: Intel Processor Trace.
7694Buffer size: 16kB.
7695Failed to configure the Intel Processor Trace decoder: unknown cpu.
7696(gdb) set record btrace cpu intel:6/158
7697(gdb) info record
7698Active record target: record-btrace
7699Recording format: Intel Processor Trace.
7700Buffer size: 16kB.
7701Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7702@end smallexample
7703
67b5c0c1
MM
7704@kindex show record btrace
7705@item show record btrace replay-memory-access
7706Show the current setting of @code{replay-memory-access}.
7707
4a4495d6
MM
7708@item show record btrace cpu
7709Show the processor to be used for enabling trace decode errata
7710workarounds.
7711
d33501a5
MM
7712@kindex set record btrace bts
7713@item set record btrace bts buffer-size @var{size}
7714@itemx set record btrace bts buffer-size unlimited
7715Set the requested ring buffer size for branch tracing in @acronym{BTS}
7716format. Default is 64KB.
7717
7718If @var{size} is a positive number, then @value{GDBN} will try to
7719allocate a buffer of at least @var{size} bytes for each new thread
7720that uses the btrace recording method and the @acronym{BTS} format.
7721The actually obtained buffer size may differ from the requested
7722@var{size}. Use the @code{info record} command to see the actual
7723buffer size for each thread that uses the btrace recording method and
7724the @acronym{BTS} format.
7725
7726If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7727allocate a buffer of 4MB.
7728
7729Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7730also need longer to process the branch trace data before it can be used.
7731
7732@item show record btrace bts buffer-size @var{size}
7733Show the current setting of the requested ring buffer size for branch
7734tracing in @acronym{BTS} format.
7735
b20a6524
MM
7736@kindex set record btrace pt
7737@item set record btrace pt buffer-size @var{size}
7738@itemx set record btrace pt buffer-size unlimited
bc504a31 7739Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7740Processor Trace format. Default is 16KB.
7741
7742If @var{size} is a positive number, then @value{GDBN} will try to
7743allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7744that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7745format. The actually obtained buffer size may differ from the
7746requested @var{size}. Use the @code{info record} command to see the
7747actual buffer size for each thread.
7748
7749If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7750allocate a buffer of 4MB.
7751
7752Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7753also need longer to process the branch trace data before it can be used.
7754
7755@item show record btrace pt buffer-size @var{size}
7756Show the current setting of the requested ring buffer size for branch
bc504a31 7757tracing in Intel Processor Trace format.
b20a6524 7758
29153c24
MS
7759@kindex info record
7760@item info record
59ea5688
MM
7761Show various statistics about the recording depending on the recording
7762method:
7763
7764@table @code
7765@item full
7766For the @code{full} recording method, it shows the state of process
7767record and its in-memory execution log buffer, including:
29153c24
MS
7768
7769@itemize @bullet
7770@item
7771Whether in record mode or replay mode.
7772@item
7773Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7774@item
7775Highest recorded instruction number.
7776@item
7777Current instruction about to be replayed (if in replay mode).
7778@item
7779Number of instructions contained in the execution log.
7780@item
7781Maximum number of instructions that may be contained in the execution log.
7782@end itemize
53cc454a 7783
59ea5688 7784@item btrace
d33501a5
MM
7785For the @code{btrace} recording method, it shows:
7786
7787@itemize @bullet
7788@item
7789Recording format.
7790@item
7791Number of instructions that have been recorded.
7792@item
7793Number of blocks of sequential control-flow formed by the recorded
7794instructions.
7795@item
7796Whether in record mode or replay mode.
7797@end itemize
7798
7799For the @code{bts} recording format, it also shows:
7800@itemize @bullet
7801@item
7802Size of the perf ring buffer.
7803@end itemize
b20a6524
MM
7804
7805For the @code{pt} recording format, it also shows:
7806@itemize @bullet
7807@item
7808Size of the perf ring buffer.
7809@end itemize
59ea5688
MM
7810@end table
7811
53cc454a
HZ
7812@kindex record delete
7813@kindex rec del
7814@item record delete
a2311334 7815When record target runs in replay mode (``in the past''), delete the
53cc454a 7816subsequent execution log and begin to record a new execution log starting
a2311334 7817from the current address. This means you will abandon the previously
53cc454a 7818recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7819
7820@kindex record instruction-history
7821@kindex rec instruction-history
7822@item record instruction-history
7823Disassembles instructions from the recorded execution log. By
7824default, ten instructions are disassembled. This can be changed using
7825the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7826are printed in execution order.
7827
0c532a29
MM
7828It can also print mixed source+disassembly if you specify the the
7829@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7830as well as in symbolic form by specifying the @code{/r} modifier.
7831
7832The current position marker is printed for the instruction at the
7833current program counter value. This instruction can appear multiple
7834times in the trace and the current position marker will be printed
7835every time. To omit the current position marker, specify the
7836@code{/p} modifier.
7837
7838To better align the printed instructions when the trace contains
7839instructions from more than one function, the function name may be
7840omitted by specifying the @code{/f} modifier.
7841
da8c46d2
MM
7842Speculatively executed instructions are prefixed with @samp{?}. This
7843feature is not available for all recording formats.
7844
7845There are several ways to specify what part of the execution log to
7846disassemble:
59ea5688
MM
7847
7848@table @code
7849@item record instruction-history @var{insn}
7850Disassembles ten instructions starting from instruction number
7851@var{insn}.
7852
7853@item record instruction-history @var{insn}, +/-@var{n}
7854Disassembles @var{n} instructions around instruction number
7855@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7856@var{n} instructions after instruction number @var{insn}. If
7857@var{n} is preceded with @code{-}, disassembles @var{n}
7858instructions before instruction number @var{insn}.
7859
7860@item record instruction-history
7861Disassembles ten more instructions after the last disassembly.
7862
7863@item record instruction-history -
7864Disassembles ten more instructions before the last disassembly.
7865
792005b0 7866@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7867Disassembles instructions beginning with instruction number
7868@var{begin} until instruction number @var{end}. The instruction
0688d04e 7869number @var{end} is included.
59ea5688
MM
7870@end table
7871
7872This command may not be available for all recording methods.
7873
7874@kindex set record
f81d1120
PA
7875@item set record instruction-history-size @var{size}
7876@itemx set record instruction-history-size unlimited
59ea5688
MM
7877Define how many instructions to disassemble in the @code{record
7878instruction-history} command. The default value is 10.
f81d1120 7879A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7880
7881@kindex show record
7882@item show record instruction-history-size
7883Show how many instructions to disassemble in the @code{record
7884instruction-history} command.
7885
7886@kindex record function-call-history
7887@kindex rec function-call-history
7888@item record function-call-history
7889Prints the execution history at function granularity. It prints one
7890line for each sequence of instructions that belong to the same
7891function giving the name of that function, the source lines
7892for this instruction sequence (if the @code{/l} modifier is
7893specified), and the instructions numbers that form the sequence (if
8710b709
MM
7894the @code{/i} modifier is specified). The function names are indented
7895to reflect the call stack depth if the @code{/c} modifier is
7896specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7897given together.
59ea5688
MM
7898
7899@smallexample
7900(@value{GDBP}) @b{list 1, 10}
79011 void foo (void)
79022 @{
79033 @}
79044
79055 void bar (void)
79066 @{
79077 ...
79088 foo ();
79099 ...
791010 @}
8710b709
MM
7911(@value{GDBP}) @b{record function-call-history /ilc}
79121 bar inst 1,4 at foo.c:6,8
79132 foo inst 5,10 at foo.c:2,3
79143 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7915@end smallexample
7916
7917By default, ten lines are printed. This can be changed using the
7918@code{set record function-call-history-size} command. Functions are
7919printed in execution order. There are several ways to specify what
7920to print:
7921
7922@table @code
7923@item record function-call-history @var{func}
7924Prints ten functions starting from function number @var{func}.
7925
7926@item record function-call-history @var{func}, +/-@var{n}
7927Prints @var{n} functions around function number @var{func}. If
7928@var{n} is preceded with @code{+}, prints @var{n} functions after
7929function number @var{func}. If @var{n} is preceded with @code{-},
7930prints @var{n} functions before function number @var{func}.
7931
7932@item record function-call-history
7933Prints ten more functions after the last ten-line print.
7934
7935@item record function-call-history -
7936Prints ten more functions before the last ten-line print.
7937
792005b0 7938@item record function-call-history @var{begin}, @var{end}
59ea5688 7939Prints functions beginning with function number @var{begin} until
0688d04e 7940function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7941@end table
7942
7943This command may not be available for all recording methods.
7944
f81d1120
PA
7945@item set record function-call-history-size @var{size}
7946@itemx set record function-call-history-size unlimited
59ea5688
MM
7947Define how many lines to print in the
7948@code{record function-call-history} command. The default value is 10.
f81d1120 7949A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7950
7951@item show record function-call-history-size
7952Show how many lines to print in the
7953@code{record function-call-history} command.
53cc454a
HZ
7954@end table
7955
7956
6d2ebf8b 7957@node Stack
c906108c
SS
7958@chapter Examining the Stack
7959
7960When your program has stopped, the first thing you need to know is where it
7961stopped and how it got there.
7962
7963@cindex call stack
5d161b24
DB
7964Each time your program performs a function call, information about the call
7965is generated.
7966That information includes the location of the call in your program,
7967the arguments of the call,
c906108c 7968and the local variables of the function being called.
5d161b24 7969The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7970The stack frames are allocated in a region of memory called the @dfn{call
7971stack}.
7972
7973When your program stops, the @value{GDBN} commands for examining the
7974stack allow you to see all of this information.
7975
7976@cindex selected frame
7977One of the stack frames is @dfn{selected} by @value{GDBN} and many
7978@value{GDBN} commands refer implicitly to the selected frame. In
7979particular, whenever you ask @value{GDBN} for the value of a variable in
7980your program, the value is found in the selected frame. There are
7981special @value{GDBN} commands to select whichever frame you are
79a6e687 7982interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7983
7984When your program stops, @value{GDBN} automatically selects the
5d161b24 7985currently executing frame and describes it briefly, similar to the
79a6e687 7986@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7987
7988@menu
7989* Frames:: Stack frames
7990* Backtrace:: Backtraces
7991* Selection:: Selecting a frame
7992* Frame Info:: Information on a frame
0a232300 7993* Frame Apply:: Applying a command to several frames
0f59c28f 7994* Frame Filter Management:: Managing frame filters
c906108c
SS
7995
7996@end menu
7997
6d2ebf8b 7998@node Frames
79a6e687 7999@section Stack Frames
c906108c 8000
d4f3574e 8001@cindex frame, definition
c906108c
SS
8002@cindex stack frame
8003The call stack is divided up into contiguous pieces called @dfn{stack
8004frames}, or @dfn{frames} for short; each frame is the data associated
8005with one call to one function. The frame contains the arguments given
8006to the function, the function's local variables, and the address at
8007which the function is executing.
8008
8009@cindex initial frame
8010@cindex outermost frame
8011@cindex innermost frame
8012When your program is started, the stack has only one frame, that of the
8013function @code{main}. This is called the @dfn{initial} frame or the
8014@dfn{outermost} frame. Each time a function is called, a new frame is
8015made. Each time a function returns, the frame for that function invocation
8016is eliminated. If a function is recursive, there can be many frames for
8017the same function. The frame for the function in which execution is
8018actually occurring is called the @dfn{innermost} frame. This is the most
8019recently created of all the stack frames that still exist.
8020
8021@cindex frame pointer
8022Inside your program, stack frames are identified by their addresses. A
8023stack frame consists of many bytes, each of which has its own address; each
8024kind of computer has a convention for choosing one byte whose
8025address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
8026in a register called the @dfn{frame pointer register}
8027(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 8028
f67ffa6a 8029@cindex frame level
c906108c 8030@cindex frame number
f67ffa6a
AB
8031@value{GDBN} labels each existing stack frame with a @dfn{level}, a
8032number that is zero for the innermost frame, one for the frame that
8033called it, and so on upward. These level numbers give you a way of
8034designating stack frames in @value{GDBN} commands. The terms
8035@dfn{frame number} and @dfn{frame level} can be used interchangeably to
8036describe this number.
c906108c 8037
6d2ebf8b
SS
8038@c The -fomit-frame-pointer below perennially causes hbox overflow
8039@c underflow problems.
c906108c
SS
8040@cindex frameless execution
8041Some compilers provide a way to compile functions so that they operate
e22ea452 8042without stack frames. (For example, the @value{NGCC} option
474c8240 8043@smallexample
6d2ebf8b 8044@samp{-fomit-frame-pointer}
474c8240 8045@end smallexample
6d2ebf8b 8046generates functions without a frame.)
c906108c
SS
8047This is occasionally done with heavily used library functions to save
8048the frame setup time. @value{GDBN} has limited facilities for dealing
8049with these function invocations. If the innermost function invocation
8050has no stack frame, @value{GDBN} nevertheless regards it as though
8051it had a separate frame, which is numbered zero as usual, allowing
8052correct tracing of the function call chain. However, @value{GDBN} has
8053no provision for frameless functions elsewhere in the stack.
8054
6d2ebf8b 8055@node Backtrace
c906108c
SS
8056@section Backtraces
8057
09d4efe1
EZ
8058@cindex traceback
8059@cindex call stack traces
c906108c
SS
8060A backtrace is a summary of how your program got where it is. It shows one
8061line per frame, for many frames, starting with the currently executing
8062frame (frame zero), followed by its caller (frame one), and on up the
8063stack.
8064
1e611234 8065@anchor{backtrace-command}
c906108c 8066@kindex backtrace
41afff9a 8067@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
8068To print a backtrace of the entire stack, use the @code{backtrace}
8069command, or its alias @code{bt}. This command will print one line per
8070frame for frames in the stack. By default, all stack frames are
8071printed. You can stop the backtrace at any time by typing the system
8072interrupt character, normally @kbd{Ctrl-c}.
8073
8074@table @code
3345721a
PA
8075@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8076@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8077Print the backtrace of the entire stack.
8078
8079The optional @var{count} can be one of the following:
ea3b0687
TT
8080
8081@table @code
8082@item @var{n}
8083@itemx @var{n}
8084Print only the innermost @var{n} frames, where @var{n} is a positive
8085number.
8086
8087@item -@var{n}
8088@itemx -@var{n}
8089Print only the outermost @var{n} frames, where @var{n} is a positive
8090number.
3345721a 8091@end table
ea3b0687 8092
3345721a
PA
8093Options:
8094
8095@table @code
8096@item -full
ea3b0687 8097Print the values of the local variables also. This can be combined
3345721a 8098with the optional @var{count} to limit the number of frames shown.
ea3b0687 8099
3345721a 8100@item -no-filters
1e611234
PM
8101Do not run Python frame filters on this backtrace. @xref{Frame
8102Filter API}, for more information. Additionally use @ref{disable
8103frame-filter all} to turn off all frame filters. This is only
8104relevant when @value{GDBN} has been configured with @code{Python}
8105support.
978d6c75 8106
3345721a 8107@item -hide
978d6c75
TT
8108A Python frame filter might decide to ``elide'' some frames. Normally
8109such elided frames are still printed, but they are indented relative
3345721a 8110to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 8111option causes elided frames to not be printed at all.
c906108c 8112@end table
3345721a
PA
8113
8114The @code{backtrace} command also supports a number of options that
8115allow overriding relevant global print settings as set by @code{set
8116backtrace} and @code{set print} subcommands:
8117
8118@table @code
8119@item -past-main [@code{on}|@code{off}]
8120Set whether backtraces should continue past @code{main}. Related setting:
8121@ref{set backtrace past-main}.
8122
8123@item -past-entry [@code{on}|@code{off}]
8124Set whether backtraces should continue past the entry point of a program.
8125Related setting: @ref{set backtrace past-entry}.
8126
8127@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8128Set printing of function arguments at function entry.
8129Related setting: @ref{set print entry-values}.
8130
8131@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8132Set printing of non-scalar frame arguments.
8133Related setting: @ref{set print frame-arguments}.
8134
8135@item -raw-frame-arguments [@code{on}|@code{off}]
8136Set whether to print frame arguments in raw form.
8137Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
8138
8139@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8140Set printing of frame information.
8141Related setting: @ref{set print frame-info}.
3345721a
PA
8142@end table
8143
8144The optional @var{qualifier} is maintained for backward compatibility.
8145It can be one of the following:
8146
8147@table @code
8148@item full
8149Equivalent to the @code{-full} option.
8150
8151@item no-filters
8152Equivalent to the @code{-no-filters} option.
8153
8154@item hide
8155Equivalent to the @code{-hide} option.
8156@end table
8157
ea3b0687 8158@end table
c906108c
SS
8159
8160@kindex where
8161@kindex info stack
c906108c
SS
8162The names @code{where} and @code{info stack} (abbreviated @code{info s})
8163are additional aliases for @code{backtrace}.
8164
839c27b7
EZ
8165@cindex multiple threads, backtrace
8166In a multi-threaded program, @value{GDBN} by default shows the
8167backtrace only for the current thread. To display the backtrace for
8168several or all of the threads, use the command @code{thread apply}
8169(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8170apply all backtrace}, @value{GDBN} will display the backtrace for all
8171the threads; this is handy when you debug a core dump of a
8172multi-threaded program.
8173
c906108c
SS
8174Each line in the backtrace shows the frame number and the function name.
8175The program counter value is also shown---unless you use @code{set
8176print address off}. The backtrace also shows the source file name and
8177line number, as well as the arguments to the function. The program
8178counter value is omitted if it is at the beginning of the code for that
8179line number.
8180
8181Here is an example of a backtrace. It was made with the command
8182@samp{bt 3}, so it shows the innermost three frames.
8183
8184@smallexample
8185@group
5d161b24 8186#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 8187 at builtin.c:993
4f5376b2 8188#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
8189#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8190 at macro.c:71
8191(More stack frames follow...)
8192@end group
8193@end smallexample
8194
8195@noindent
8196The display for frame zero does not begin with a program counter
8197value, indicating that your program has stopped at the beginning of the
8198code for line @code{993} of @code{builtin.c}.
8199
4f5376b2
JB
8200@noindent
8201The value of parameter @code{data} in frame 1 has been replaced by
8202@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8203only if it is a scalar (integer, pointer, enumeration, etc). See command
8204@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8205on how to configure the way function parameter values are printed.
bc4268a5
PW
8206The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8207what frame information is printed.
4f5376b2 8208
585fdaa1 8209@cindex optimized out, in backtrace
18999be5
EZ
8210@cindex function call arguments, optimized out
8211If your program was compiled with optimizations, some compilers will
8212optimize away arguments passed to functions if those arguments are
8213never used after the call. Such optimizations generate code that
8214passes arguments through registers, but doesn't store those arguments
8215in the stack frame. @value{GDBN} has no way of displaying such
8216arguments in stack frames other than the innermost one. Here's what
8217such a backtrace might look like:
8218
8219@smallexample
8220@group
8221#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8222 at builtin.c:993
585fdaa1
PA
8223#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8224#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
8225 at macro.c:71
8226(More stack frames follow...)
8227@end group
8228@end smallexample
8229
8230@noindent
8231The values of arguments that were not saved in their stack frames are
585fdaa1 8232shown as @samp{<optimized out>}.
18999be5
EZ
8233
8234If you need to display the values of such optimized-out arguments,
8235either deduce that from other variables whose values depend on the one
8236you are interested in, or recompile without optimizations.
8237
a8f24a35
EZ
8238@cindex backtrace beyond @code{main} function
8239@cindex program entry point
8240@cindex startup code, and backtrace
25d29d70
AC
8241Most programs have a standard user entry point---a place where system
8242libraries and startup code transition into user code. For C this is
d416eeec
EZ
8243@code{main}@footnote{
8244Note that embedded programs (the so-called ``free-standing''
8245environment) are not required to have a @code{main} function as the
8246entry point. They could even have multiple entry points.}.
8247When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8248it will terminate the backtrace, to avoid tracing into highly
8249system-specific (and generally uninteresting) code.
8250
8251If you need to examine the startup code, or limit the number of levels
8252in a backtrace, you can change this behavior:
95f90d25
DJ
8253
8254@table @code
25d29d70
AC
8255@item set backtrace past-main
8256@itemx set backtrace past-main on
3345721a 8257@anchor{set backtrace past-main}
4644b6e3 8258@kindex set backtrace
25d29d70
AC
8259Backtraces will continue past the user entry point.
8260
8261@item set backtrace past-main off
95f90d25
DJ
8262Backtraces will stop when they encounter the user entry point. This is the
8263default.
8264
25d29d70 8265@item show backtrace past-main
4644b6e3 8266@kindex show backtrace
25d29d70
AC
8267Display the current user entry point backtrace policy.
8268
2315ffec
RC
8269@item set backtrace past-entry
8270@itemx set backtrace past-entry on
3345721a 8271@anchor{set backtrace past-entry}
a8f24a35 8272Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8273This entry point is encoded by the linker when the application is built,
8274and is likely before the user entry point @code{main} (or equivalent) is called.
8275
8276@item set backtrace past-entry off
d3e8051b 8277Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8278application. This is the default.
8279
8280@item show backtrace past-entry
8281Display the current internal entry point backtrace policy.
8282
25d29d70
AC
8283@item set backtrace limit @var{n}
8284@itemx set backtrace limit 0
f81d1120 8285@itemx set backtrace limit unlimited
3345721a 8286@anchor{set backtrace limit}
25d29d70 8287@cindex backtrace limit
f81d1120
PA
8288Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8289or zero means unlimited levels.
95f90d25 8290
25d29d70
AC
8291@item show backtrace limit
8292Display the current limit on backtrace levels.
95f90d25
DJ
8293@end table
8294
1b56eb55
JK
8295You can control how file names are displayed.
8296
8297@table @code
8298@item set filename-display
8299@itemx set filename-display relative
8300@cindex filename-display
8301Display file names relative to the compilation directory. This is the default.
8302
8303@item set filename-display basename
8304Display only basename of a filename.
8305
8306@item set filename-display absolute
8307Display an absolute filename.
8308
8309@item show filename-display
8310Show the current way to display filenames.
8311@end table
8312
6d2ebf8b 8313@node Selection
79a6e687 8314@section Selecting a Frame
c906108c
SS
8315
8316Most commands for examining the stack and other data in your program work on
8317whichever stack frame is selected at the moment. Here are the commands for
8318selecting a stack frame; all of them finish by printing a brief description
8319of the stack frame just selected.
8320
8321@table @code
d4f3574e 8322@kindex frame@r{, selecting}
41afff9a 8323@kindex f @r{(@code{frame})}
f67ffa6a
AB
8324@item frame @r{[} @var{frame-selection-spec} @r{]}
8325@item f @r{[} @var{frame-selection-spec} @r{]}
8326The @command{frame} command allows different stack frames to be
8327selected. The @var{frame-selection-spec} can be any of the following:
8328
8329@table @code
8330@kindex frame level
8331@item @var{num}
8332@item level @var{num}
8333Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8334(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8335innermost one, and so on. The highest level frame is usually the one
8336for @code{main}.
8337
8338As this is the most common method of navigating the frame stack, the
8339string @command{level} can be omitted. For example, the following two
8340commands are equivalent:
8341
8342@smallexample
8343(@value{GDBP}) frame 3
8344(@value{GDBP}) frame level 3
8345@end smallexample
8346
8347@kindex frame address
8348@item address @var{stack-address}
8349Select the frame with stack address @var{stack-address}. The
8350@var{stack-address} for a frame can be seen in the output of
8351@command{info frame}, for example:
8352
8353@smallexample
8354(gdb) info frame
8355Stack level 1, frame at 0x7fffffffda30:
8356 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8357 tail call frame, caller of frame at 0x7fffffffda30
8358 source language c++.
8359 Arglist at unknown address.
8360 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8361@end smallexample
8362
8363The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8364indicated by the line:
8365
8366@smallexample
8367Stack level 1, frame at 0x7fffffffda30:
8368@end smallexample
8369
8370@kindex frame function
8371@item function @var{function-name}
8372Select the stack frame for function @var{function-name}. If there are
8373multiple stack frames for function @var{function-name} then the inner
8374most stack frame is selected.
8375
8376@kindex frame view
8377@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8378View a frame that is not part of @value{GDBN}'s backtrace. The frame
8379viewed has stack address @var{stack-addr}, and optionally, a program
8380counter address of @var{pc-addr}.
8381
8382This is useful mainly if the chaining of stack frames has been
8383damaged by a bug, making it impossible for @value{GDBN} to assign
8384numbers properly to all frames. In addition, this can be useful
8385when your program has multiple stacks and switches between them.
8386
8387When viewing a frame outside the current backtrace using
8388@command{frame view} then you can always return to the original
8389stack using one of the previous stack frame selection instructions,
8390for example @command{frame level 0}.
8391
8392@end table
c906108c
SS
8393
8394@kindex up
8395@item up @var{n}
697aa1b7
EZ
8396Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8397numbers @var{n}, this advances toward the outermost frame, to higher
8398frame numbers, to frames that have existed longer.
c906108c
SS
8399
8400@kindex down
41afff9a 8401@kindex do @r{(@code{down})}
c906108c 8402@item down @var{n}
697aa1b7
EZ
8403Move @var{n} frames down the stack; @var{n} defaults to 1. For
8404positive numbers @var{n}, this advances toward the innermost frame, to
8405lower frame numbers, to frames that were created more recently.
8406You may abbreviate @code{down} as @code{do}.
c906108c
SS
8407@end table
8408
8409All of these commands end by printing two lines of output describing the
8410frame. The first line shows the frame number, the function name, the
8411arguments, and the source file and line number of execution in that
5d161b24 8412frame. The second line shows the text of that source line.
c906108c
SS
8413
8414@need 1000
8415For example:
8416
8417@smallexample
8418@group
8419(@value{GDBP}) up
8420#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8421 at env.c:10
842210 read_input_file (argv[i]);
8423@end group
8424@end smallexample
8425
8426After such a printout, the @code{list} command with no arguments
8427prints ten lines centered on the point of execution in the frame.
87885426
FN
8428You can also edit the program at the point of execution with your favorite
8429editing program by typing @code{edit}.
79a6e687 8430@xref{List, ,Printing Source Lines},
87885426 8431for details.
c906108c
SS
8432
8433@table @code
fc58fa65 8434@kindex select-frame
f67ffa6a 8435@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8436The @code{select-frame} command is a variant of @code{frame} that does
8437not display the new frame after selecting it. This command is
8438intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8439output might be unnecessary and distracting. The
8440@var{frame-selection-spec} is as for the @command{frame} command
8441described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8442
c906108c
SS
8443@kindex down-silently
8444@kindex up-silently
8445@item up-silently @var{n}
8446@itemx down-silently @var{n}
8447These two commands are variants of @code{up} and @code{down},
8448respectively; they differ in that they do their work silently, without
8449causing display of the new frame. They are intended primarily for use
8450in @value{GDBN} command scripts, where the output might be unnecessary and
8451distracting.
8452@end table
8453
6d2ebf8b 8454@node Frame Info
79a6e687 8455@section Information About a Frame
c906108c
SS
8456
8457There are several other commands to print information about the selected
8458stack frame.
8459
8460@table @code
8461@item frame
8462@itemx f
8463When used without any argument, this command does not change which
8464frame is selected, but prints a brief description of the currently
8465selected stack frame. It can be abbreviated @code{f}. With an
8466argument, this command is used to select a stack frame.
79a6e687 8467@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8468
8469@kindex info frame
41afff9a 8470@kindex info f @r{(@code{info frame})}
c906108c
SS
8471@item info frame
8472@itemx info f
8473This command prints a verbose description of the selected stack frame,
8474including:
8475
8476@itemize @bullet
5d161b24
DB
8477@item
8478the address of the frame
c906108c
SS
8479@item
8480the address of the next frame down (called by this frame)
8481@item
8482the address of the next frame up (caller of this frame)
8483@item
8484the language in which the source code corresponding to this frame is written
8485@item
8486the address of the frame's arguments
8487@item
d4f3574e
SS
8488the address of the frame's local variables
8489@item
c906108c
SS
8490the program counter saved in it (the address of execution in the caller frame)
8491@item
8492which registers were saved in the frame
8493@end itemize
8494
8495@noindent The verbose description is useful when
8496something has gone wrong that has made the stack format fail to fit
8497the usual conventions.
8498
f67ffa6a
AB
8499@item info frame @r{[} @var{frame-selection-spec} @r{]}
8500@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8501Print a verbose description of the frame selected by
8502@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8503same as for the @command{frame} command (@pxref{Selection, ,Selecting
8504a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8505
8506@kindex info args
d321477b 8507@item info args [-q]
c906108c
SS
8508Print the arguments of the selected frame, each on a separate line.
8509
d321477b
PW
8510The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8511printing header information and messages explaining why no argument
8512have been printed.
8513
8514@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8515Like @kbd{info args}, but only print the arguments selected
8516with the provided regexp(s).
8517
8518If @var{regexp} is provided, print only the arguments whose names
8519match the regular expression @var{regexp}.
8520
8521If @var{type_regexp} is provided, print only the arguments whose
8522types, as printed by the @code{whatis} command, match
8523the regular expression @var{type_regexp}.
8524If @var{type_regexp} contains space(s), it should be enclosed in
8525quote characters. If needed, use backslash to escape the meaning
8526of special characters or quotes.
8527
8528If both @var{regexp} and @var{type_regexp} are provided, an argument
8529is printed only if its name matches @var{regexp} and its type matches
8530@var{type_regexp}.
8531
8532@item info locals [-q]
c906108c
SS
8533@kindex info locals
8534Print the local variables of the selected frame, each on a separate
8535line. These are all variables (declared either static or automatic)
8536accessible at the point of execution of the selected frame.
8537
d321477b
PW
8538The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8539printing header information and messages explaining why no local variables
8540have been printed.
8541
8542@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8543Like @kbd{info locals}, but only print the local variables selected
8544with the provided regexp(s).
8545
8546If @var{regexp} is provided, print only the local variables whose names
8547match the regular expression @var{regexp}.
8548
8549If @var{type_regexp} is provided, print only the local variables whose
8550types, as printed by the @code{whatis} command, match
8551the regular expression @var{type_regexp}.
8552If @var{type_regexp} contains space(s), it should be enclosed in
8553quote characters. If needed, use backslash to escape the meaning
8554of special characters or quotes.
8555
8556If both @var{regexp} and @var{type_regexp} are provided, a local variable
8557is printed only if its name matches @var{regexp} and its type matches
8558@var{type_regexp}.
8559
8560The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8561combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8562For example, your program might use Resource Acquisition Is
8563Initialization types (RAII) such as @code{lock_something_t}: each
8564local variable of type @code{lock_something_t} automatically places a
8565lock that is destroyed when the variable goes out of scope. You can
8566then list all acquired locks in your program by doing
8567@smallexample
8568thread apply all -s frame apply all -s info locals -q -t lock_something_t
8569@end smallexample
8570@noindent
8571or the equivalent shorter form
8572@smallexample
8573tfaas i lo -q -t lock_something_t
8574@end smallexample
8575
c906108c
SS
8576@end table
8577
0a232300
PW
8578@node Frame Apply
8579@section Applying a Command to Several Frames.
8580@kindex frame apply
8581@cindex apply command to several frames
8582@table @code
3345721a 8583@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8584The @code{frame apply} command allows you to apply the named
8585@var{command} to one or more frames.
8586
8587@table @code
8588@item @code{all}
8589Specify @code{all} to apply @var{command} to all frames.
8590
8591@item @var{count}
8592Use @var{count} to apply @var{command} to the innermost @var{count}
8593frames, where @var{count} is a positive number.
8594
8595@item @var{-count}
8596Use @var{-count} to apply @var{command} to the outermost @var{count}
8597frames, where @var{count} is a positive number.
8598
8599@item @code{level}
8600Use @code{level} to apply @var{command} to the set of frames identified
8601by the @var{level} list. @var{level} is a frame level or a range of frame
8602levels as @var{level1}-@var{level2}. The frame level is the number shown
8603in the first field of the @samp{backtrace} command output.
8604E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8605at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8606
8607@end table
8608
0a232300
PW
8609Note that the frames on which @code{frame apply} applies a command are
8610also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8611backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8612@xref{Backtrace,,Backtraces}.
8613
3345721a
PA
8614The @code{frame apply} command also supports a number of options that
8615allow overriding relevant @code{set backtrace} settings:
8616
8617@table @code
8618@item -past-main [@code{on}|@code{off}]
8619Whether backtraces should continue past @code{main}.
8620Related setting: @ref{set backtrace past-main}.
8621
8622@item -past-entry [@code{on}|@code{off}]
8623Whether backtraces should continue past the entry point of a program.
8624Related setting: @ref{set backtrace past-entry}.
8625@end table
0a232300
PW
8626
8627By default, @value{GDBN} displays some frame information before the
8628output produced by @var{command}, and an error raised during the
8629execution of a @var{command} will abort @code{frame apply}. The
3345721a 8630following options can be used to fine-tune these behaviors:
0a232300
PW
8631
8632@table @code
8633@item -c
8634The flag @code{-c}, which stands for @samp{continue}, causes any
8635errors in @var{command} to be displayed, and the execution of
8636@code{frame apply} then continues.
8637@item -s
8638The flag @code{-s}, which stands for @samp{silent}, causes any errors
8639or empty output produced by a @var{command} to be silently ignored.
8640That is, the execution continues, but the frame information and errors
8641are not printed.
8642@item -q
8643The flag @code{-q} (@samp{quiet}) disables printing the frame
8644information.
8645@end table
8646
8647The following example shows how the flags @code{-c} and @code{-s} are
8648working when applying the command @code{p j} to all frames, where
8649variable @code{j} can only be successfully printed in the outermost
8650@code{#1 main} frame.
8651
8652@smallexample
8653@group
8654(gdb) frame apply all p j
8655#0 some_function (i=5) at fun.c:4
8656No symbol "j" in current context.
8657(gdb) frame apply all -c p j
8658#0 some_function (i=5) at fun.c:4
8659No symbol "j" in current context.
8660#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8661$1 = 5
8662(gdb) frame apply all -s p j
8663#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8664$2 = 5
8665(gdb)
8666@end group
8667@end smallexample
8668
8669By default, @samp{frame apply}, prints the frame location
8670information before the command output:
8671
8672@smallexample
8673@group
8674(gdb) frame apply all p $sp
8675#0 some_function (i=5) at fun.c:4
8676$4 = (void *) 0xffffd1e0
8677#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8678$5 = (void *) 0xffffd1f0
8679(gdb)
8680@end group
8681@end smallexample
8682
3345721a 8683If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8684@smallexample
8685@group
8686(gdb) frame apply all -q p $sp
8687$12 = (void *) 0xffffd1e0
8688$13 = (void *) 0xffffd1f0
8689(gdb)
8690@end group
8691@end smallexample
8692
3345721a
PA
8693@end table
8694
0a232300
PW
8695@table @code
8696
8697@kindex faas
8698@cindex apply a command to all frames (ignoring errors and empty output)
8699@item faas @var{command}
8700Shortcut for @code{frame apply all -s @var{command}}.
8701Applies @var{command} on all frames, ignoring errors and empty output.
8702
8703It can for example be used to print a local variable or a function
8704argument without knowing the frame where this variable or argument
8705is, using:
8706@smallexample
8707(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8708@end smallexample
8709
3345721a 8710The @code{faas} command accepts the same options as the @code{frame
ed788fee 8711apply} command. @xref{Frame Apply,,frame apply}.
3345721a 8712
0a232300
PW
8713Note that the command @code{tfaas @var{command}} applies @var{command}
8714on all frames of all threads. See @xref{Threads,,Threads}.
8715@end table
8716
8717
fc58fa65
AB
8718@node Frame Filter Management
8719@section Management of Frame Filters.
8720@cindex managing frame filters
8721
8722Frame filters are Python based utilities to manage and decorate the
8723output of frames. @xref{Frame Filter API}, for further information.
8724
8725Managing frame filters is performed by several commands available
8726within @value{GDBN}, detailed here.
8727
8728@table @code
8729@kindex info frame-filter
8730@item info frame-filter
8731Print a list of installed frame filters from all dictionaries, showing
8732their name, priority and enabled status.
8733
8734@kindex disable frame-filter
8735@anchor{disable frame-filter all}
8736@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8737Disable a frame filter in the dictionary matching
8738@var{filter-dictionary} and @var{filter-name}. The
8739@var{filter-dictionary} may be @code{all}, @code{global},
8740@code{progspace}, or the name of the object file where the frame filter
8741dictionary resides. When @code{all} is specified, all frame filters
8742across all dictionaries are disabled. The @var{filter-name} is the name
8743of the frame filter and is used when @code{all} is not the option for
8744@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8745may be enabled again later.
8746
8747@kindex enable frame-filter
8748@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8749Enable a frame filter in the dictionary matching
8750@var{filter-dictionary} and @var{filter-name}. The
8751@var{filter-dictionary} may be @code{all}, @code{global},
8752@code{progspace} or the name of the object file where the frame filter
8753dictionary resides. When @code{all} is specified, all frame filters across
8754all dictionaries are enabled. The @var{filter-name} is the name of the frame
8755filter and is used when @code{all} is not the option for
8756@var{filter-dictionary}.
8757
8758Example:
8759
8760@smallexample
8761(gdb) info frame-filter
8762
8763global frame-filters:
8764 Priority Enabled Name
8765 1000 No PrimaryFunctionFilter
8766 100 Yes Reverse
8767
8768progspace /build/test frame-filters:
8769 Priority Enabled Name
8770 100 Yes ProgspaceFilter
8771
8772objfile /build/test frame-filters:
8773 Priority Enabled Name
6b92c0d3 8774 999 Yes BuildProgramFilter
fc58fa65
AB
8775
8776(gdb) disable frame-filter /build/test BuildProgramFilter
8777(gdb) info frame-filter
8778
8779global frame-filters:
8780 Priority Enabled Name
8781 1000 No PrimaryFunctionFilter
8782 100 Yes Reverse
8783
8784progspace /build/test frame-filters:
8785 Priority Enabled Name
8786 100 Yes ProgspaceFilter
8787
8788objfile /build/test frame-filters:
8789 Priority Enabled Name
8790 999 No BuildProgramFilter
8791
8792(gdb) enable frame-filter global PrimaryFunctionFilter
8793(gdb) info frame-filter
8794
8795global frame-filters:
8796 Priority Enabled Name
8797 1000 Yes PrimaryFunctionFilter
8798 100 Yes Reverse
8799
8800progspace /build/test frame-filters:
8801 Priority Enabled Name
8802 100 Yes ProgspaceFilter
8803
8804objfile /build/test frame-filters:
8805 Priority Enabled Name
8806 999 No BuildProgramFilter
8807@end smallexample
8808
8809@kindex set frame-filter priority
8810@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8811Set the @var{priority} of a frame filter in the dictionary matching
8812@var{filter-dictionary}, and the frame filter name matching
8813@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8814@code{progspace} or the name of the object file where the frame filter
8815dictionary resides. The @var{priority} is an integer.
8816
8817@kindex show frame-filter priority
8818@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8819Show the @var{priority} of a frame filter in the dictionary matching
8820@var{filter-dictionary}, and the frame filter name matching
8821@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8822@code{progspace} or the name of the object file where the frame filter
8823dictionary resides.
8824
8825Example:
8826
8827@smallexample
8828(gdb) info frame-filter
8829
8830global frame-filters:
8831 Priority Enabled Name
8832 1000 Yes PrimaryFunctionFilter
8833 100 Yes Reverse
8834
8835progspace /build/test frame-filters:
8836 Priority Enabled Name
8837 100 Yes ProgspaceFilter
8838
8839objfile /build/test frame-filters:
8840 Priority Enabled Name
8841 999 No BuildProgramFilter
8842
8843(gdb) set frame-filter priority global Reverse 50
8844(gdb) info frame-filter
8845
8846global frame-filters:
8847 Priority Enabled Name
8848 1000 Yes PrimaryFunctionFilter
8849 50 Yes Reverse
8850
8851progspace /build/test frame-filters:
8852 Priority Enabled Name
8853 100 Yes ProgspaceFilter
8854
8855objfile /build/test frame-filters:
8856 Priority Enabled Name
8857 999 No BuildProgramFilter
8858@end smallexample
8859@end table
c906108c 8860
6d2ebf8b 8861@node Source
c906108c
SS
8862@chapter Examining Source Files
8863
8864@value{GDBN} can print parts of your program's source, since the debugging
8865information recorded in the program tells @value{GDBN} what source files were
8866used to build it. When your program stops, @value{GDBN} spontaneously prints
8867the line where it stopped. Likewise, when you select a stack frame
79a6e687 8868(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8869execution in that frame has stopped. You can print other portions of
8870source files by explicit command.
8871
7a292a7a 8872If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8873prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8874@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8875
8876@menu
8877* List:: Printing source lines
2a25a5ba 8878* Specify Location:: How to specify code locations
87885426 8879* Edit:: Editing source files
c906108c 8880* Search:: Searching source files
c906108c
SS
8881* Source Path:: Specifying source directories
8882* Machine Code:: Source and machine code
8883@end menu
8884
6d2ebf8b 8885@node List
79a6e687 8886@section Printing Source Lines
c906108c
SS
8887
8888@kindex list
41afff9a 8889@kindex l @r{(@code{list})}
c906108c 8890To print lines from a source file, use the @code{list} command
5d161b24 8891(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8892There are several ways to specify what part of the file you want to
8893print; see @ref{Specify Location}, for the full list.
c906108c
SS
8894
8895Here are the forms of the @code{list} command most commonly used:
8896
8897@table @code
8898@item list @var{linenum}
8899Print lines centered around line number @var{linenum} in the
8900current source file.
8901
8902@item list @var{function}
8903Print lines centered around the beginning of function
8904@var{function}.
8905
8906@item list
8907Print more lines. If the last lines printed were printed with a
8908@code{list} command, this prints lines following the last lines
8909printed; however, if the last line printed was a solitary line printed
8910as part of displaying a stack frame (@pxref{Stack, ,Examining the
8911Stack}), this prints lines centered around that line.
8912
8913@item list -
8914Print lines just before the lines last printed.
8915@end table
8916
9c16f35a 8917@cindex @code{list}, how many lines to display
c906108c
SS
8918By default, @value{GDBN} prints ten source lines with any of these forms of
8919the @code{list} command. You can change this using @code{set listsize}:
8920
8921@table @code
8922@kindex set listsize
8923@item set listsize @var{count}
f81d1120 8924@itemx set listsize unlimited
c906108c
SS
8925Make the @code{list} command display @var{count} source lines (unless
8926the @code{list} argument explicitly specifies some other number).
f81d1120 8927Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8928
8929@kindex show listsize
8930@item show listsize
8931Display the number of lines that @code{list} prints.
8932@end table
8933
8934Repeating a @code{list} command with @key{RET} discards the argument,
8935so it is equivalent to typing just @code{list}. This is more useful
8936than listing the same lines again. An exception is made for an
8937argument of @samp{-}; that argument is preserved in repetition so that
8938each repetition moves up in the source file.
8939
c906108c 8940In general, the @code{list} command expects you to supply zero, one or two
629500fa 8941@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8942of writing them (@pxref{Specify Location}), but the effect is always
8943to specify some source line.
8944
c906108c
SS
8945Here is a complete description of the possible arguments for @code{list}:
8946
8947@table @code
629500fa
KS
8948@item list @var{location}
8949Print lines centered around the line specified by @var{location}.
c906108c
SS
8950
8951@item list @var{first},@var{last}
8952Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8953locations. When a @code{list} command has two locations, and the
8954source file of the second location is omitted, this refers to
8955the same source file as the first location.
c906108c
SS
8956
8957@item list ,@var{last}
8958Print lines ending with @var{last}.
8959
8960@item list @var{first},
8961Print lines starting with @var{first}.
8962
8963@item list +
8964Print lines just after the lines last printed.
8965
8966@item list -
8967Print lines just before the lines last printed.
8968
8969@item list
8970As described in the preceding table.
8971@end table
8972
2a25a5ba
EZ
8973@node Specify Location
8974@section Specifying a Location
8975@cindex specifying location
629500fa
KS
8976@cindex location
8977@cindex source location
8978
8979@menu
8980* Linespec Locations:: Linespec locations
8981* Explicit Locations:: Explicit locations
8982* Address Locations:: Address locations
8983@end menu
c906108c 8984
2a25a5ba
EZ
8985Several @value{GDBN} commands accept arguments that specify a location
8986of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8987debugger, a location usually specifies some line in the source code.
8988Locations may be specified using three different formats:
8989linespec locations, explicit locations, or address locations.
c906108c 8990
629500fa
KS
8991@node Linespec Locations
8992@subsection Linespec Locations
8993@cindex linespec locations
8994
8995A @dfn{linespec} is a colon-separated list of source location parameters such
8996as file name, function name, etc. Here are all the different ways of
8997specifying a linespec:
c906108c 8998
2a25a5ba
EZ
8999@table @code
9000@item @var{linenum}
9001Specifies the line number @var{linenum} of the current source file.
c906108c 9002
2a25a5ba
EZ
9003@item -@var{offset}
9004@itemx +@var{offset}
9005Specifies the line @var{offset} lines before or after the @dfn{current
9006line}. For the @code{list} command, the current line is the last one
9007printed; for the breakpoint commands, this is the line at which
9008execution stopped in the currently selected @dfn{stack frame}
9009(@pxref{Frames, ,Frames}, for a description of stack frames.) When
9010used as the second of the two linespecs in a @code{list} command,
9011this specifies the line @var{offset} lines up or down from the first
9012linespec.
9013
9014@item @var{filename}:@var{linenum}
9015Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
9016If @var{filename} is a relative file name, then it will match any
9017source file name with the same trailing components. For example, if
9018@var{filename} is @samp{gcc/expr.c}, then it will match source file
9019name of @file{/build/trunk/gcc/expr.c}, but not
9020@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
9021
9022@item @var{function}
9023Specifies the line that begins the body of the function @var{function}.
2a25a5ba 9024For example, in C, this is the line with the open brace.
c906108c 9025
a20714ff
PA
9026By default, in C@t{++} and Ada, @var{function} is interpreted as
9027specifying all functions named @var{function} in all scopes. For
9028C@t{++}, this means in all namespaces and classes. For Ada, this
9029means in all packages.
9030
9031For example, assuming a program with C@t{++} symbols named
9032@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9033func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9034
9035Commands that accept a linespec let you override this with the
9036@code{-qualified} option. For example, @w{@kbd{break -qualified
9037func}} sets a breakpoint on a free-function named @code{func} ignoring
9038any C@t{++} class methods and namespace functions called @code{func}.
9039
9040@xref{Explicit Locations}.
9041
9ef07c8c
TT
9042@item @var{function}:@var{label}
9043Specifies the line where @var{label} appears in @var{function}.
9044
c906108c 9045@item @var{filename}:@var{function}
2a25a5ba
EZ
9046Specifies the line that begins the body of the function @var{function}
9047in the file @var{filename}. You only need the file name with a
9048function name to avoid ambiguity when there are identically named
9049functions in different source files.
c906108c 9050
0f5238ed 9051@item @var{label}
629500fa
KS
9052Specifies the line at which the label named @var{label} appears
9053in the function corresponding to the currently selected stack frame.
9054If there is no current selected stack frame (for instance, if the inferior
9055is not running), then @value{GDBN} will not search for a label.
9056
9057@cindex breakpoint at static probe point
9058@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9059The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9060applications to embed static probes. @xref{Static Probe Points}, for more
9061information on finding and using static probes. This form of linespec
9062specifies the location of such a static probe.
9063
9064If @var{objfile} is given, only probes coming from that shared library
9065or executable matching @var{objfile} as a regular expression are considered.
9066If @var{provider} is given, then only probes from that provider are considered.
9067If several probes match the spec, @value{GDBN} will insert a breakpoint at
9068each one of those probes.
9069@end table
9070
9071@node Explicit Locations
9072@subsection Explicit Locations
9073@cindex explicit locations
9074
9075@dfn{Explicit locations} allow the user to directly specify the source
9076location's parameters using option-value pairs.
9077
9078Explicit locations are useful when several functions, labels, or
9079file names have the same name (base name for files) in the program's
9080sources. In these cases, explicit locations point to the source
9081line you meant more accurately and unambiguously. Also, using
9082explicit locations might be faster in large programs.
9083
9084For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9085defined in the file named @file{foo} or the label @code{bar} in a function
9086named @code{foo}. @value{GDBN} must search either the file system or
9087the symbol table to know.
9088
9089The list of valid explicit location options is summarized in the
9090following table:
9091
9092@table @code
9093@item -source @var{filename}
9094The value specifies the source file name. To differentiate between
9095files with the same base name, prepend as many directories as is necessary
9096to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9097@value{GDBN} will use the first file it finds with the given base
9098name. This option requires the use of either @code{-function} or @code{-line}.
9099
9100@item -function @var{function}
9101The value specifies the name of a function. Operations
9102on function locations unmodified by other options (such as @code{-label}
9103or @code{-line}) refer to the line that begins the body of the function.
9104In C, for example, this is the line with the open brace.
9105
a20714ff
PA
9106By default, in C@t{++} and Ada, @var{function} is interpreted as
9107specifying all functions named @var{function} in all scopes. For
9108C@t{++}, this means in all namespaces and classes. For Ada, this
9109means in all packages.
9110
9111For example, assuming a program with C@t{++} symbols named
9112@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9113-function func}} and @w{@kbd{break -function B::func}} set a
9114breakpoint on both symbols.
9115
9116You can use the @kbd{-qualified} flag to override this (see below).
9117
9118@item -qualified
9119
9120This flag makes @value{GDBN} interpret a function name specified with
9121@kbd{-function} as a complete fully-qualified name.
9122
9123For example, assuming a C@t{++} program with symbols named
9124@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9125-function B::func}} command sets a breakpoint on @code{B::func}, only.
9126
9127(Note: the @kbd{-qualified} option can precede a linespec as well
9128(@pxref{Linespec Locations}), so the particular example above could be
9129simplified as @w{@kbd{break -qualified B::func}}.)
9130
629500fa
KS
9131@item -label @var{label}
9132The value specifies the name of a label. When the function
9133name is not specified, the label is searched in the function of the currently
9134selected stack frame.
9135
9136@item -line @var{number}
9137The value specifies a line offset for the location. The offset may either
9138be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9139the command. When specified without any other options, the line offset is
9140relative to the current line.
9141@end table
9142
9143Explicit location options may be abbreviated by omitting any non-unique
a20714ff 9144trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
9145
9146@node Address Locations
9147@subsection Address Locations
9148@cindex address locations
9149
9150@dfn{Address locations} indicate a specific program address. They have
9151the generalized form *@var{address}.
9152
9153For line-oriented commands, such as @code{list} and @code{edit}, this
9154specifies a source line that contains @var{address}. For @code{break} and
9155other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
9156parts of your program which do not have debugging information or
9157source files.
9158
9159Here @var{address} may be any expression valid in the current working
9160language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 9161address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
9162semantics of expressions used in locations to cover several situations
9163that frequently occur during debugging. Here are the various forms
5fa54e5d 9164of @var{address}:
2a25a5ba
EZ
9165
9166@table @code
9167@item @var{expression}
9168Any expression valid in the current working language.
9169
9170@item @var{funcaddr}
9171An address of a function or procedure derived from its name. In C,
9c37b5ae 9172C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
9173simply the function's name @var{function} (and actually a special case
9174of a valid expression). In Pascal and Modula-2, this is
9175@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9176(although the Pascal form also works).
9177
9178This form specifies the address of the function's first instruction,
9179before the stack frame and arguments have been set up.
9180
9a284c97 9181@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
9182Like @var{funcaddr} above, but also specifies the name of the source
9183file explicitly. This is useful if the name of the function does not
9184specify the function unambiguously, e.g., if there are several
9185functions with identical names in different source files.
c906108c
SS
9186@end table
9187
87885426 9188@node Edit
79a6e687 9189@section Editing Source Files
87885426
FN
9190@cindex editing source files
9191
9192@kindex edit
9193@kindex e @r{(@code{edit})}
9194To edit the lines in a source file, use the @code{edit} command.
9195The editing program of your choice
9196is invoked with the current line set to
9197the active line in the program.
9198Alternatively, there are several ways to specify what part of the file you
2a25a5ba 9199want to print if you want to see other parts of the program:
87885426
FN
9200
9201@table @code
2a25a5ba
EZ
9202@item edit @var{location}
9203Edit the source file specified by @code{location}. Editing starts at
9204that @var{location}, e.g., at the specified source line of the
9205specified file. @xref{Specify Location}, for all the possible forms
9206of the @var{location} argument; here are the forms of the @code{edit}
9207command most commonly used:
87885426 9208
2a25a5ba 9209@table @code
87885426
FN
9210@item edit @var{number}
9211Edit the current source file with @var{number} as the active line number.
9212
9213@item edit @var{function}
9214Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 9215@end table
87885426 9216
87885426
FN
9217@end table
9218
79a6e687 9219@subsection Choosing your Editor
87885426
FN
9220You can customize @value{GDBN} to use any editor you want
9221@footnote{
9222The only restriction is that your editor (say @code{ex}), recognizes the
9223following command-line syntax:
10998722 9224@smallexample
87885426 9225ex +@var{number} file
10998722 9226@end smallexample
15387254
EZ
9227The optional numeric value +@var{number} specifies the number of the line in
9228the file where to start editing.}.
9229By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
9230by setting the environment variable @code{EDITOR} before using
9231@value{GDBN}. For example, to configure @value{GDBN} to use the
9232@code{vi} editor, you could use these commands with the @code{sh} shell:
9233@smallexample
87885426
FN
9234EDITOR=/usr/bin/vi
9235export EDITOR
15387254 9236gdb @dots{}
10998722 9237@end smallexample
87885426 9238or in the @code{csh} shell,
10998722 9239@smallexample
87885426 9240setenv EDITOR /usr/bin/vi
15387254 9241gdb @dots{}
10998722 9242@end smallexample
87885426 9243
6d2ebf8b 9244@node Search
79a6e687 9245@section Searching Source Files
15387254 9246@cindex searching source files
c906108c
SS
9247
9248There are two commands for searching through the current source file for a
9249regular expression.
9250
9251@table @code
9252@kindex search
9253@kindex forward-search
1e96de83 9254@kindex fo @r{(@code{forward-search})}
c906108c
SS
9255@item forward-search @var{regexp}
9256@itemx search @var{regexp}
9257The command @samp{forward-search @var{regexp}} checks each line,
9258starting with the one following the last line listed, for a match for
5d161b24 9259@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9260synonym @samp{search @var{regexp}} or abbreviate the command name as
9261@code{fo}.
9262
09d4efe1 9263@kindex reverse-search
c906108c
SS
9264@item reverse-search @var{regexp}
9265The command @samp{reverse-search @var{regexp}} checks each line, starting
9266with the one before the last line listed and going backward, for a match
9267for @var{regexp}. It lists the line that is found. You can abbreviate
9268this command as @code{rev}.
9269@end table
c906108c 9270
6d2ebf8b 9271@node Source Path
79a6e687 9272@section Specifying Source Directories
c906108c
SS
9273
9274@cindex source path
9275@cindex directories for source files
9276Executable programs sometimes do not record the directories of the source
9277files from which they were compiled, just the names. Even when they do,
9278the directories could be moved between the compilation and your debugging
9279session. @value{GDBN} has a list of directories to search for source files;
9280this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9281it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9282in the list, until it finds a file with the desired name.
9283
9284For example, suppose an executable references the file
f1b620e9
MG
9285@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9286directory, and the @dfn{source path} is @file{/mnt/cross}.
9287@value{GDBN} would look for the source file in the following
9288locations:
9289
9290@enumerate
9291
9292@item @file{/usr/src/foo-1.0/lib/foo.c}
9293@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9294@item @file{/mnt/cross/foo.c}
9295
9296@end enumerate
9297
9298If the source file is not present at any of the above locations then
9299an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9300source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9301Likewise, the subdirectories of the source path are not searched: if
9302the source path is @file{/mnt/cross}, and the binary refers to
9303@file{foo.c}, @value{GDBN} would not find it under
9304@file{/mnt/cross/usr/src/foo-1.0/lib}.
9305
9306Plain file names, relative file names with leading directories, file
f1b620e9
MG
9307names containing dots, etc.@: are all treated as described above,
9308except that non-absolute file names are not looked up literally. If
9309the @dfn{source path} is @file{/mnt/cross}, the source file is
9310recorded as @file{../lib/foo.c}, and no compilation directory is
9311recorded, then @value{GDBN} will search in the following locations:
9312
9313@enumerate
9314
9315@item @file{/mnt/cross/../lib/foo.c}
9316@item @file{/mnt/cross/foo.c}
9317
9318@end enumerate
9319
9320@kindex cdir
9321@kindex cwd
9322@vindex $cdir@r{, convenience variable}
9323@vindex $cwd@r{, convenience variable}
9324@cindex compilation directory
9325@cindex current directory
9326@cindex working directory
9327@cindex directory, current
9328@cindex directory, compilation
9329The @dfn{source path} will always include two special entries
9330@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9331(if one is recorded) and the current working directory respectively.
9332
9333@samp{$cdir} causes @value{GDBN} to search within the compilation
9334directory, if one is recorded in the debug information. If no
9335compilation directory is recorded in the debug information then
9336@samp{$cdir} is ignored.
9337
9338@samp{$cwd} is not the same as @samp{.}---the former tracks the
9339current working directory as it changes during your @value{GDBN}
9340session, while the latter is immediately expanded to the current
9341directory at the time you add an entry to the source path.
9342
9343If a compilation directory is recorded in the debug information, and
9344@value{GDBN} has not found the source file after the first search
9345using @dfn{source path}, then @value{GDBN} will combine the
9346compilation directory and the filename, and then search for the source
9347file again using the @dfn{source path}.
9348
9349For example, if the executable records the source file as
9350@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9351recorded as @file{/project/build}, and the @dfn{source path} is
9352@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9353the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9354search for the source file in the following locations:
f1b620e9
MG
9355
9356@enumerate
9357
9358@item @file{/usr/src/foo-1.0/lib/foo.c}
9359@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9360@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9361@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9362@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9363@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9364@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9365@item @file{/mnt/cross/foo.c}
9366@item @file{/project/build/foo.c}
9367@item @file{/home/user/foo.c}
9368
9369@end enumerate
9370
9371If the file name in the previous example had been recorded in the
9372executable as a relative path rather than an absolute path, then the
9373first look up would not have occurred, but all of the remaining steps
9374would be similar.
9375
9376When searching for source files on MS-DOS and MS-Windows, where
9377absolute paths start with a drive letter (e.g.
9378@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9379from the file name before appending it to a search directory from
9380@dfn{source path}; for instance if the executable references the
9381source file @file{C:/project/foo.c} and @dfn{source path} is set to
9382@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9383locations for the source file:
9384
9385@enumerate
9386
9387@item @file{C:/project/foo.c}
9388@item @file{D:/mnt/cross/project/foo.c}
9389@item @file{D:/mnt/cross/foo.c}
9390
9391@end enumerate
0b66e38c
EZ
9392
9393Note that the executable search path is @emph{not} used to locate the
cd852561 9394source files.
c906108c
SS
9395
9396Whenever you reset or rearrange the source path, @value{GDBN} clears out
9397any information it has cached about where source files are found and where
9398each line is in the file.
9399
9400@kindex directory
9401@kindex dir
f1b620e9
MG
9402When you start @value{GDBN}, its source path includes only @samp{$cdir}
9403and @samp{$cwd}, in that order.
c906108c
SS
9404To add other directories, use the @code{directory} command.
9405
4b505b12
AS
9406The search path is used to find both program source files and @value{GDBN}
9407script files (read using the @samp{-command} option and @samp{source} command).
9408
30daae6c
JB
9409In addition to the source path, @value{GDBN} provides a set of commands
9410that manage a list of source path substitution rules. A @dfn{substitution
9411rule} specifies how to rewrite source directories stored in the program's
9412debug information in case the sources were moved to a different
9413directory between compilation and debugging. A rule is made of
9414two strings, the first specifying what needs to be rewritten in
9415the path, and the second specifying how it should be rewritten.
9416In @ref{set substitute-path}, we name these two parts @var{from} and
9417@var{to} respectively. @value{GDBN} does a simple string replacement
9418of @var{from} with @var{to} at the start of the directory part of the
9419source file name, and uses that result instead of the original file
9420name to look up the sources.
9421
9422Using the previous example, suppose the @file{foo-1.0} tree has been
9423moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9424@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9425@file{/mnt/cross}. The first lookup will then be
9426@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9427of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9428substitution rule, use the @code{set substitute-path} command
9429(@pxref{set substitute-path}).
9430
9431To avoid unexpected substitution results, a rule is applied only if the
9432@var{from} part of the directory name ends at a directory separator.
9433For instance, a rule substituting @file{/usr/source} into
9434@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9435not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9436is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9437not be applied to @file{/root/usr/source/baz.c} either.
9438
9439In many cases, you can achieve the same result using the @code{directory}
9440command. However, @code{set substitute-path} can be more efficient in
9441the case where the sources are organized in a complex tree with multiple
9442subdirectories. With the @code{directory} command, you need to add each
9443subdirectory of your project. If you moved the entire tree while
9444preserving its internal organization, then @code{set substitute-path}
9445allows you to direct the debugger to all the sources with one single
9446command.
9447
9448@code{set substitute-path} is also more than just a shortcut command.
9449The source path is only used if the file at the original location no
9450longer exists. On the other hand, @code{set substitute-path} modifies
9451the debugger behavior to look at the rewritten location instead. So, if
9452for any reason a source file that is not relevant to your executable is
9453located at the original location, a substitution rule is the only
3f94c067 9454method available to point @value{GDBN} at the new location.
30daae6c 9455
29b0e8a2
JM
9456@cindex @samp{--with-relocated-sources}
9457@cindex default source path substitution
9458You can configure a default source path substitution rule by
9459configuring @value{GDBN} with the
9460@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9461should be the name of a directory under @value{GDBN}'s configured
9462prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9463directory names in debug information under @var{dir} will be adjusted
9464automatically if the installed @value{GDBN} is moved to a new
9465location. This is useful if @value{GDBN}, libraries or executables
9466with debug information and corresponding source code are being moved
9467together.
9468
c906108c
SS
9469@table @code
9470@item directory @var{dirname} @dots{}
9471@item dir @var{dirname} @dots{}
9472Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9473directory names may be given to this command, separated by @samp{:}
9474(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9475part of absolute file names) or
c906108c
SS
9476whitespace. You may specify a directory that is already in the source
9477path; this moves it forward, so @value{GDBN} searches it sooner.
9478
f1b620e9
MG
9479The special strings @samp{$cdir} (to refer to the compilation
9480directory, if one is recorded), and @samp{$cwd} (to refer to the
9481current working directory) can also be included in the list of
9482directories @var{dirname}. Though these will already be in the source
9483path they will be moved forward in the list so @value{GDBN} searches
9484them sooner.
c906108c
SS
9485
9486@item directory
cd852561 9487Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9488
9489@c RET-repeat for @code{directory} is explicitly disabled, but since
9490@c repeating it would be a no-op we do not say that. (thanks to RMS)
9491
99e7ae30
DE
9492@item set directories @var{path-list}
9493@kindex set directories
9494Set the source path to @var{path-list}.
9495@samp{$cdir:$cwd} are added if missing.
9496
c906108c
SS
9497@item show directories
9498@kindex show directories
9499Print the source path: show which directories it contains.
30daae6c
JB
9500
9501@anchor{set substitute-path}
9502@item set substitute-path @var{from} @var{to}
9503@kindex set substitute-path
9504Define a source path substitution rule, and add it at the end of the
9505current list of existing substitution rules. If a rule with the same
9506@var{from} was already defined, then the old rule is also deleted.
9507
9508For example, if the file @file{/foo/bar/baz.c} was moved to
9509@file{/mnt/cross/baz.c}, then the command
9510
9511@smallexample
c58b006b 9512(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9513@end smallexample
9514
9515@noindent
c58b006b 9516will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9517@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9518@file{baz.c} even though it was moved.
9519
9520In the case when more than one substitution rule have been defined,
9521the rules are evaluated one by one in the order where they have been
9522defined. The first one matching, if any, is selected to perform
9523the substitution.
9524
9525For instance, if we had entered the following commands:
9526
9527@smallexample
9528(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9529(@value{GDBP}) set substitute-path /usr/src /mnt/src
9530@end smallexample
9531
9532@noindent
9533@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9534@file{/mnt/include/defs.h} by using the first rule. However, it would
9535use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9536@file{/mnt/src/lib/foo.c}.
9537
9538
9539@item unset substitute-path [path]
9540@kindex unset substitute-path
9541If a path is specified, search the current list of substitution rules
9542for a rule that would rewrite that path. Delete that rule if found.
9543A warning is emitted by the debugger if no rule could be found.
9544
9545If no path is specified, then all substitution rules are deleted.
9546
9547@item show substitute-path [path]
9548@kindex show substitute-path
9549If a path is specified, then print the source path substitution rule
9550which would rewrite that path, if any.
9551
9552If no path is specified, then print all existing source path substitution
9553rules.
9554
c906108c
SS
9555@end table
9556
9557If your source path is cluttered with directories that are no longer of
9558interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9559versions of source. You can correct the situation as follows:
9560
9561@enumerate
9562@item
cd852561 9563Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9564
9565@item
9566Use @code{directory} with suitable arguments to reinstall the
9567directories you want in the source path. You can add all the
9568directories in one command.
9569@end enumerate
9570
6d2ebf8b 9571@node Machine Code
79a6e687 9572@section Source and Machine Code
15387254 9573@cindex source line and its code address
c906108c
SS
9574
9575You can use the command @code{info line} to map source lines to program
9576addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9577a range of addresses as machine instructions. You can use the command
9578@code{set disassemble-next-line} to set whether to disassemble next
9579source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9580mode, the @code{info line} command causes the arrow to point to the
5d161b24 9581line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9582well as hex.
9583
9584@table @code
9585@kindex info line
db1ae9c5
AB
9586@item info line
9587@itemx info line @var{location}
c906108c 9588Print the starting and ending addresses of the compiled code for
629500fa 9589source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9590the ways documented in @ref{Specify Location}. With no @var{location}
9591information about the current source line is printed.
c906108c
SS
9592@end table
9593
9594For example, we can use @code{info line} to discover the location of
9595the object code for the first line of function
9596@code{m4_changequote}:
9597
9598@smallexample
96a2c332 9599(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9600Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9601 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9602@end smallexample
9603
9604@noindent
15387254 9605@cindex code address and its source line
c906108c 9606We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9607@var{location}) what source line covers a particular address:
c906108c
SS
9608@smallexample
9609(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9610Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9611 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9612@end smallexample
9613
9614@cindex @code{$_} and @code{info line}
15387254 9615@cindex @code{x} command, default address
41afff9a 9616@kindex x@r{(examine), and} info line
c906108c
SS
9617After @code{info line}, the default address for the @code{x} command
9618is changed to the starting address of the line, so that @samp{x/i} is
9619sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9620,Examining Memory}). Also, this address is saved as the value of the
c906108c 9621convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9622Variables}).
c906108c 9623
db1ae9c5
AB
9624@cindex info line, repeated calls
9625After @code{info line}, using @code{info line} again without
9626specifying a location will display information about the next source
9627line.
9628
c906108c
SS
9629@table @code
9630@kindex disassemble
9631@cindex assembly instructions
9632@cindex instructions, assembly
9633@cindex machine instructions
9634@cindex listing machine instructions
9635@item disassemble
d14508fe 9636@itemx disassemble /m
6ff0ba5f 9637@itemx disassemble /s
9b117ef3 9638@itemx disassemble /r
c906108c 9639This specialized command dumps a range of memory as machine
d14508fe 9640instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9641the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9642as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9643The default memory range is the function surrounding the
c906108c
SS
9644program counter of the selected frame. A single argument to this
9645command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9646surrounding this value. When two arguments are given, they should
9647be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9648arguments specify a range of addresses to dump, in one of two forms:
9649
9650@table @code
9651@item @var{start},@var{end}
9652the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9653@item @var{start},+@var{length}
9654the addresses from @var{start} (inclusive) to
9655@code{@var{start}+@var{length}} (exclusive).
9656@end table
9657
9658@noindent
9659When 2 arguments are specified, the name of the function is also
9660printed (since there could be several functions in the given range).
21a0512e
PP
9661
9662The argument(s) can be any expression yielding a numeric value, such as
9663@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9664
9665If the range of memory being disassembled contains current program counter,
9666the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9667@end table
9668
c906108c
SS
9669The following example shows the disassembly of a range of addresses of
9670HP PA-RISC 2.0 code:
9671
9672@smallexample
21a0512e 9673(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9674Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9675 0x32c4 <main+204>: addil 0,dp
9676 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9677 0x32cc <main+212>: ldil 0x3000,r31
9678 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9679 0x32d4 <main+220>: ldo 0(r31),rp
9680 0x32d8 <main+224>: addil -0x800,dp
9681 0x32dc <main+228>: ldo 0x588(r1),r26
9682 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9683End of assembler dump.
9684@end smallexample
c906108c 9685
6ff0ba5f
DE
9686Here is an example showing mixed source+assembly for Intel x86
9687with @code{/m} or @code{/s}, when the program is stopped just after
9688function prologue in a non-optimized function with no inline code.
d14508fe
DE
9689
9690@smallexample
9691(@value{GDBP}) disas /m main
9692Dump of assembler code for function main:
96935 @{
9c419145
PP
9694 0x08048330 <+0>: push %ebp
9695 0x08048331 <+1>: mov %esp,%ebp
9696 0x08048333 <+3>: sub $0x8,%esp
9697 0x08048336 <+6>: and $0xfffffff0,%esp
9698 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9699
97006 printf ("Hello.\n");
9c419145
PP
9701=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9702 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9703
97047 return 0;
97058 @}
9c419145
PP
9706 0x08048348 <+24>: mov $0x0,%eax
9707 0x0804834d <+29>: leave
9708 0x0804834e <+30>: ret
d14508fe
DE
9709
9710End of assembler dump.
9711@end smallexample
9712
6ff0ba5f
DE
9713The @code{/m} option is deprecated as its output is not useful when
9714there is either inlined code or re-ordered code.
9715The @code{/s} option is the preferred choice.
9716Here is an example for AMD x86-64 showing the difference between
9717@code{/m} output and @code{/s} output.
9718This example has one inline function defined in a header file,
9719and the code is compiled with @samp{-O2} optimization.
9720Note how the @code{/m} output is missing the disassembly of
9721several instructions that are present in the @code{/s} output.
9722
9723@file{foo.h}:
9724
9725@smallexample
9726int
9727foo (int a)
9728@{
9729 if (a < 0)
9730 return a * 2;
9731 if (a == 0)
9732 return 1;
9733 return a + 10;
9734@}
9735@end smallexample
9736
9737@file{foo.c}:
9738
9739@smallexample
9740#include "foo.h"
9741volatile int x, y;
9742int
9743main ()
9744@{
9745 x = foo (y);
9746 return 0;
9747@}
9748@end smallexample
9749
9750@smallexample
9751(@value{GDBP}) disas /m main
9752Dump of assembler code for function main:
97535 @{
9754
97556 x = foo (y);
9756 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9757 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9758
97597 return 0;
97608 @}
9761 0x000000000040041d <+29>: xor %eax,%eax
9762 0x000000000040041f <+31>: retq
9763 0x0000000000400420 <+32>: add %eax,%eax
9764 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9765
9766End of assembler dump.
9767(@value{GDBP}) disas /s main
9768Dump of assembler code for function main:
9769foo.c:
97705 @{
97716 x = foo (y);
9772 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9773
9774foo.h:
97754 if (a < 0)
9776 0x0000000000400406 <+6>: test %eax,%eax
9777 0x0000000000400408 <+8>: js 0x400420 <main+32>
9778
97796 if (a == 0)
97807 return 1;
97818 return a + 10;
9782 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9783 0x000000000040040d <+13>: test %eax,%eax
9784 0x000000000040040f <+15>: mov $0x1,%eax
9785 0x0000000000400414 <+20>: cmovne %edx,%eax
9786
9787foo.c:
97886 x = foo (y);
9789 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9790
97917 return 0;
97928 @}
9793 0x000000000040041d <+29>: xor %eax,%eax
9794 0x000000000040041f <+31>: retq
9795
9796foo.h:
97975 return a * 2;
9798 0x0000000000400420 <+32>: add %eax,%eax
9799 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9800End of assembler dump.
9801@end smallexample
9802
53a71c06
CR
9803Here is another example showing raw instructions in hex for AMD x86-64,
9804
9805@smallexample
9806(gdb) disas /r 0x400281,+10
9807Dump of assembler code from 0x400281 to 0x40028b:
9808 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9809 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9810 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9811 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9812End of assembler dump.
9813@end smallexample
9814
629500fa 9815Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9816So, for example, if you want to disassemble function @code{bar}
9817in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9818and not @samp{disassemble foo.c:bar}.
9819
c906108c
SS
9820Some architectures have more than one commonly-used set of instruction
9821mnemonics or other syntax.
9822
76d17f34
EZ
9823For programs that were dynamically linked and use shared libraries,
9824instructions that call functions or branch to locations in the shared
9825libraries might show a seemingly bogus location---it's actually a
9826location of the relocation table. On some architectures, @value{GDBN}
9827might be able to resolve these to actual function names.
9828
65b48a81
PB
9829@table @code
9830@kindex set disassembler-options
9831@cindex disassembler options
9832@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9833This command controls the passing of target specific information to
9834the disassembler. For a list of valid options, please refer to the
9835@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9836manual and/or the output of @kbd{objdump --help}
f5a476a7 9837(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9838The default value is the empty string.
9839
9840If it is necessary to specify more than one disassembler option, then
9841multiple options can be placed together into a comma separated list.
471b9d15 9842Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9843and S/390.
9844
9845@kindex show disassembler-options
9846@item show disassembler-options
9847Show the current setting of the disassembler options.
9848@end table
9849
c906108c 9850@table @code
d4f3574e 9851@kindex set disassembly-flavor
d4f3574e
SS
9852@cindex Intel disassembly flavor
9853@cindex AT&T disassembly flavor
9854@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9855Select the instruction set to use when disassembling the
9856program via the @code{disassemble} or @code{x/i} commands.
9857
9858Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9859can set @var{instruction-set} to either @code{intel} or @code{att}.
9860The default is @code{att}, the AT&T flavor used by default by Unix
9861assemblers for x86-based targets.
9c16f35a
EZ
9862
9863@kindex show disassembly-flavor
9864@item show disassembly-flavor
9865Show the current setting of the disassembly flavor.
c906108c
SS
9866@end table
9867
91440f57
HZ
9868@table @code
9869@kindex set disassemble-next-line
9870@kindex show disassemble-next-line
9871@item set disassemble-next-line
9872@itemx show disassemble-next-line
32ae1842
EZ
9873Control whether or not @value{GDBN} will disassemble the next source
9874line or instruction when execution stops. If ON, @value{GDBN} will
9875display disassembly of the next source line when execution of the
9876program being debugged stops. This is @emph{in addition} to
9877displaying the source line itself, which @value{GDBN} always does if
9878possible. If the next source line cannot be displayed for some reason
9879(e.g., if @value{GDBN} cannot find the source file, or there's no line
9880info in the debug info), @value{GDBN} will display disassembly of the
9881next @emph{instruction} instead of showing the next source line. If
9882AUTO, @value{GDBN} will display disassembly of next instruction only
9883if the source line cannot be displayed. This setting causes
9884@value{GDBN} to display some feedback when you step through a function
9885with no line info or whose source file is unavailable. The default is
9886OFF, which means never display the disassembly of the next line or
9887instruction.
91440f57
HZ
9888@end table
9889
c906108c 9890
6d2ebf8b 9891@node Data
c906108c
SS
9892@chapter Examining Data
9893
9894@cindex printing data
9895@cindex examining data
9896@kindex print
9897@kindex inspect
c906108c 9898The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9899command (abbreviated @code{p}), or its synonym @code{inspect}. It
9900evaluates and prints the value of an expression of the language your
9901program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9902Different Languages}). It may also print the expression using a
9903Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9904
9905@table @code
3345721a
PA
9906@item print [[@var{options}] --] @var{expr}
9907@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9908@var{expr} is an expression (in the source language). By default the
9909value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9910you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9911@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9912Formats}.
c906108c 9913
3345721a
PA
9914@anchor{print options}
9915The @code{print} command supports a number of options that allow
9916overriding relevant global print settings as set by @code{set print}
9917subcommands:
9918
9919@table @code
9920@item -address [@code{on}|@code{off}]
9921Set printing of addresses.
9922Related setting: @ref{set print address}.
9923
9924@item -array [@code{on}|@code{off}]
9925Pretty formatting of arrays.
9926Related setting: @ref{set print array}.
9927
9928@item -array-indexes [@code{on}|@code{off}]
9929Set printing of array indexes.
9930Related setting: @ref{set print array-indexes}.
9931
9932@item -elements @var{number-of-elements}|@code{unlimited}
9933Set limit on string chars or array elements to print. The value
9934@code{unlimited} causes there to be no limit. Related setting:
9935@ref{set print elements}.
9936
9937@item -max-depth @var{depth}|@code{unlimited}
9938Set the threshold after which nested structures are replaced with
9939ellipsis. Related setting: @ref{set print max-depth}.
9940
9941@item -null-stop [@code{on}|@code{off}]
9942Set printing of char arrays to stop at first null char. Related
9943setting: @ref{set print null-stop}.
9944
9945@item -object [@code{on}|@code{off}]
9946Set printing C@t{++} virtual function tables. Related setting:
9947@ref{set print object}.
9948
9949@item -pretty [@code{on}|@code{off}]
9950Set pretty formatting of structures. Related setting: @ref{set print
9951pretty}.
9952
d8edc8b7
PW
9953@item -raw-values [@code{on}|@code{off}]
9954Set whether to print values in raw form, bypassing any
9955pretty-printers for that value. Related setting: @ref{set print
9956raw-values}.
9957
3345721a
PA
9958@item -repeats @var{number-of-repeats}|@code{unlimited}
9959Set threshold for repeated print elements. @code{unlimited} causes
9960all elements to be individually printed. Related setting: @ref{set
9961print repeats}.
9962
9963@item -static-members [@code{on}|@code{off}]
9964Set printing C@t{++} static members. Related setting: @ref{set print
9965static-members}.
9966
9967@item -symbol [@code{on}|@code{off}]
9968Set printing of symbol names when printing pointers. Related setting:
9969@ref{set print symbol}.
9970
9971@item -union [@code{on}|@code{off}]
9972Set printing of unions interior to structures. Related setting:
9973@ref{set print union}.
9974
9975@item -vtbl [@code{on}|@code{off}]
9976Set printing of C++ virtual function tables. Related setting:
9977@ref{set print vtbl}.
9978@end table
9979
9980Because the @code{print} command accepts arbitrary expressions which
9981may look like options (including abbreviations), if you specify any
9982command option, then you must use a double dash (@code{--}) to mark
9983the end of option processing.
9984
d8edc8b7 9985For example, this prints the value of the @code{-p} expression:
3345721a
PA
9986
9987@smallexample
d8edc8b7 9988(@value{GDBP}) print -p
3345721a
PA
9989@end smallexample
9990
9991While this repeats the last value in the value history (see below)
d8edc8b7 9992with the @code{-pretty} option in effect:
3345721a
PA
9993
9994@smallexample
d8edc8b7 9995(@value{GDBP}) print -p --
3345721a
PA
9996@end smallexample
9997
9998Here is an example including both on option and an expression:
9999
10000@smallexample
10001@group
10002(@value{GDBP}) print -pretty -- *myptr
10003$1 = @{
10004 next = 0x0,
10005 flags = @{
10006 sweet = 1,
10007 sour = 1
10008 @},
10009 meat = 0x54 "Pork"
10010@}
10011@end group
10012@end smallexample
10013
10014@item print [@var{options}]
10015@itemx print [@var{options}] /@var{f}
15387254 10016@cindex reprint the last value
d4f3574e 10017If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 10018@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
10019conveniently inspect the same value in an alternative format.
10020@end table
10021
10022A more low-level way of examining data is with the @code{x} command.
10023It examines data in memory at a specified address and prints it in a
79a6e687 10024specified format. @xref{Memory, ,Examining Memory}.
c906108c 10025
7a292a7a 10026If you are interested in information about types, or about how the
d4f3574e
SS
10027fields of a struct or a class are declared, use the @code{ptype @var{exp}}
10028command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 10029Table}.
c906108c 10030
06fc020f
SCR
10031@cindex exploring hierarchical data structures
10032@kindex explore
10033Another way of examining values of expressions and type information is
10034through the Python extension command @code{explore} (available only if
10035the @value{GDBN} build is configured with @code{--with-python}). It
10036offers an interactive way to start at the highest level (or, the most
10037abstract level) of the data type of an expression (or, the data type
10038itself) and explore all the way down to leaf scalar values/fields
10039embedded in the higher level data types.
10040
10041@table @code
10042@item explore @var{arg}
10043@var{arg} is either an expression (in the source language), or a type
10044visible in the current context of the program being debugged.
10045@end table
10046
10047The working of the @code{explore} command can be illustrated with an
10048example. If a data type @code{struct ComplexStruct} is defined in your
10049C program as
10050
10051@smallexample
10052struct SimpleStruct
10053@{
10054 int i;
10055 double d;
10056@};
10057
10058struct ComplexStruct
10059@{
10060 struct SimpleStruct *ss_p;
10061 int arr[10];
10062@};
10063@end smallexample
10064
10065@noindent
10066followed by variable declarations as
10067
10068@smallexample
10069struct SimpleStruct ss = @{ 10, 1.11 @};
10070struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10071@end smallexample
10072
10073@noindent
10074then, the value of the variable @code{cs} can be explored using the
10075@code{explore} command as follows.
10076
10077@smallexample
10078(gdb) explore cs
10079The value of `cs' is a struct/class of type `struct ComplexStruct' with
10080the following fields:
10081
10082 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10083 arr = <Enter 1 to explore this field of type `int [10]'>
10084
10085Enter the field number of choice:
10086@end smallexample
10087
10088@noindent
10089Since the fields of @code{cs} are not scalar values, you are being
10090prompted to chose the field you want to explore. Let's say you choose
10091the field @code{ss_p} by entering @code{0}. Then, since this field is a
10092pointer, you will be asked if it is pointing to a single value. From
10093the declaration of @code{cs} above, it is indeed pointing to a single
10094value, hence you enter @code{y}. If you enter @code{n}, then you will
10095be asked if it were pointing to an array of values, in which case this
10096field will be explored as if it were an array.
10097
10098@smallexample
10099`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10100Continue exploring it as a pointer to a single value [y/n]: y
10101The value of `*(cs.ss_p)' is a struct/class of type `struct
10102SimpleStruct' with the following fields:
10103
10104 i = 10 .. (Value of type `int')
10105 d = 1.1100000000000001 .. (Value of type `double')
10106
10107Press enter to return to parent value:
10108@end smallexample
10109
10110@noindent
10111If the field @code{arr} of @code{cs} was chosen for exploration by
10112entering @code{1} earlier, then since it is as array, you will be
10113prompted to enter the index of the element in the array that you want
10114to explore.
10115
10116@smallexample
10117`cs.arr' is an array of `int'.
10118Enter the index of the element you want to explore in `cs.arr': 5
10119
10120`(cs.arr)[5]' is a scalar value of type `int'.
10121
10122(cs.arr)[5] = 4
10123
10124Press enter to return to parent value:
10125@end smallexample
10126
10127In general, at any stage of exploration, you can go deeper towards the
10128leaf values by responding to the prompts appropriately, or hit the
10129return key to return to the enclosing data structure (the @i{higher}
10130level data structure).
10131
10132Similar to exploring values, you can use the @code{explore} command to
10133explore types. Instead of specifying a value (which is typically a
10134variable name or an expression valid in the current context of the
10135program being debugged), you specify a type name. If you consider the
10136same example as above, your can explore the type
10137@code{struct ComplexStruct} by passing the argument
10138@code{struct ComplexStruct} to the @code{explore} command.
10139
10140@smallexample
10141(gdb) explore struct ComplexStruct
10142@end smallexample
10143
10144@noindent
10145By responding to the prompts appropriately in the subsequent interactive
10146session, you can explore the type @code{struct ComplexStruct} in a
10147manner similar to how the value @code{cs} was explored in the above
10148example.
10149
10150The @code{explore} command also has two sub-commands,
10151@code{explore value} and @code{explore type}. The former sub-command is
10152a way to explicitly specify that value exploration of the argument is
10153being invoked, while the latter is a way to explicitly specify that type
10154exploration of the argument is being invoked.
10155
10156@table @code
10157@item explore value @var{expr}
10158@cindex explore value
10159This sub-command of @code{explore} explores the value of the
10160expression @var{expr} (if @var{expr} is an expression valid in the
10161current context of the program being debugged). The behavior of this
10162command is identical to that of the behavior of the @code{explore}
10163command being passed the argument @var{expr}.
10164
10165@item explore type @var{arg}
10166@cindex explore type
10167This sub-command of @code{explore} explores the type of @var{arg} (if
10168@var{arg} is a type visible in the current context of program being
10169debugged), or the type of the value/expression @var{arg} (if @var{arg}
10170is an expression valid in the current context of the program being
10171debugged). If @var{arg} is a type, then the behavior of this command is
10172identical to that of the @code{explore} command being passed the
10173argument @var{arg}. If @var{arg} is an expression, then the behavior of
10174this command will be identical to that of the @code{explore} command
10175being passed the type of @var{arg} as the argument.
10176@end table
10177
c906108c
SS
10178@menu
10179* Expressions:: Expressions
6ba66d6a 10180* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
10181* Variables:: Program variables
10182* Arrays:: Artificial arrays
10183* Output Formats:: Output formats
10184* Memory:: Examining memory
10185* Auto Display:: Automatic display
10186* Print Settings:: Print settings
4c374409 10187* Pretty Printing:: Python pretty printing
c906108c
SS
10188* Value History:: Value history
10189* Convenience Vars:: Convenience variables
a72c3253 10190* Convenience Funs:: Convenience functions
c906108c 10191* Registers:: Registers
c906108c 10192* Floating Point Hardware:: Floating point hardware
53c69bd7 10193* Vector Unit:: Vector Unit
721c2651 10194* OS Information:: Auxiliary data provided by operating system
29e57380 10195* Memory Region Attributes:: Memory region attributes
16d9dec6 10196* Dump/Restore Files:: Copy between memory and a file
384ee23f 10197* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
10198* Character Sets:: Debugging programs that use a different
10199 character set than GDB does
b12039c6 10200* Caching Target Data:: Data caching for targets
08388c79 10201* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 10202* Value Sizes:: Managing memory allocated for values
c906108c
SS
10203@end menu
10204
6d2ebf8b 10205@node Expressions
c906108c
SS
10206@section Expressions
10207
10208@cindex expressions
10209@code{print} and many other @value{GDBN} commands accept an expression and
10210compute its value. Any kind of constant, variable or operator defined
10211by the programming language you are using is valid in an expression in
e2e0bcd1
JB
10212@value{GDBN}. This includes conditional expressions, function calls,
10213casts, and string constants. It also includes preprocessor macros, if
10214you compiled your program to include this information; see
10215@ref{Compilation}.
c906108c 10216
15387254 10217@cindex arrays in expressions
d4f3574e
SS
10218@value{GDBN} supports array constants in expressions input by
10219the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
10220you can use the command @code{print @{1, 2, 3@}} to create an array
10221of three integers. If you pass an array to a function or assign it
10222to a program variable, @value{GDBN} copies the array to memory that
10223is @code{malloc}ed in the target program.
c906108c 10224
c906108c
SS
10225Because C is so widespread, most of the expressions shown in examples in
10226this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10227Languages}, for information on how to use expressions in other
10228languages.
10229
10230In this section, we discuss operators that you can use in @value{GDBN}
10231expressions regardless of your programming language.
10232
15387254 10233@cindex casts, in expressions
c906108c
SS
10234Casts are supported in all languages, not just in C, because it is so
10235useful to cast a number into a pointer in order to examine a structure
10236at that address in memory.
10237@c FIXME: casts supported---Mod2 true?
c906108c
SS
10238
10239@value{GDBN} supports these operators, in addition to those common
10240to programming languages:
10241
10242@table @code
10243@item @@
10244@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10245@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10246
10247@item ::
10248@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10249function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10250
10251@cindex @{@var{type}@}
10252@cindex type casting memory
10253@cindex memory, viewing as typed object
10254@cindex casts, to view memory
10255@item @{@var{type}@} @var{addr}
10256Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10257memory. The address @var{addr} may be any expression whose value is
10258an integer or pointer (but parentheses are required around binary
10259operators, just as in a cast). This construct is allowed regardless
10260of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10261@end table
10262
6ba66d6a
JB
10263@node Ambiguous Expressions
10264@section Ambiguous Expressions
10265@cindex ambiguous expressions
10266
10267Expressions can sometimes contain some ambiguous elements. For instance,
10268some programming languages (notably Ada, C@t{++} and Objective-C) permit
10269a single function name to be defined several times, for application in
10270different contexts. This is called @dfn{overloading}. Another example
10271involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10272templates and is typically instantiated several times, resulting in
10273the same function name being defined in different contexts.
10274
10275In some cases and depending on the language, it is possible to adjust
10276the expression to remove the ambiguity. For instance in C@t{++}, you
10277can specify the signature of the function you want to break on, as in
10278@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10279qualified name of your function often makes the expression unambiguous
10280as well.
10281
10282When an ambiguity that needs to be resolved is detected, the debugger
10283has the capability to display a menu of numbered choices for each
10284possibility, and then waits for the selection with the prompt @samp{>}.
10285The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10286aborts the current command. If the command in which the expression was
10287used allows more than one choice to be selected, the next option in the
10288menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10289choices.
10290
10291For example, the following session excerpt shows an attempt to set a
10292breakpoint at the overloaded symbol @code{String::after}.
10293We choose three particular definitions of that function name:
10294
10295@c FIXME! This is likely to change to show arg type lists, at least
10296@smallexample
10297@group
10298(@value{GDBP}) b String::after
10299[0] cancel
10300[1] all
10301[2] file:String.cc; line number:867
10302[3] file:String.cc; line number:860
10303[4] file:String.cc; line number:875
10304[5] file:String.cc; line number:853
10305[6] file:String.cc; line number:846
10306[7] file:String.cc; line number:735
10307> 2 4 6
10308Breakpoint 1 at 0xb26c: file String.cc, line 867.
10309Breakpoint 2 at 0xb344: file String.cc, line 875.
10310Breakpoint 3 at 0xafcc: file String.cc, line 846.
10311Multiple breakpoints were set.
10312Use the "delete" command to delete unwanted
10313 breakpoints.
10314(@value{GDBP})
10315@end group
10316@end smallexample
10317
10318@table @code
10319@kindex set multiple-symbols
10320@item set multiple-symbols @var{mode}
10321@cindex multiple-symbols menu
10322
10323This option allows you to adjust the debugger behavior when an expression
10324is ambiguous.
10325
10326By default, @var{mode} is set to @code{all}. If the command with which
10327the expression is used allows more than one choice, then @value{GDBN}
10328automatically selects all possible choices. For instance, inserting
10329a breakpoint on a function using an ambiguous name results in a breakpoint
10330inserted on each possible match. However, if a unique choice must be made,
10331then @value{GDBN} uses the menu to help you disambiguate the expression.
10332For instance, printing the address of an overloaded function will result
10333in the use of the menu.
10334
10335When @var{mode} is set to @code{ask}, the debugger always uses the menu
10336when an ambiguity is detected.
10337
10338Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10339an error due to the ambiguity and the command is aborted.
10340
10341@kindex show multiple-symbols
10342@item show multiple-symbols
10343Show the current value of the @code{multiple-symbols} setting.
10344@end table
10345
6d2ebf8b 10346@node Variables
79a6e687 10347@section Program Variables
c906108c
SS
10348
10349The most common kind of expression to use is the name of a variable
10350in your program.
10351
10352Variables in expressions are understood in the selected stack frame
79a6e687 10353(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10354
10355@itemize @bullet
10356@item
10357global (or file-static)
10358@end itemize
10359
5d161b24 10360@noindent or
c906108c
SS
10361
10362@itemize @bullet
10363@item
10364visible according to the scope rules of the
10365programming language from the point of execution in that frame
5d161b24 10366@end itemize
c906108c
SS
10367
10368@noindent This means that in the function
10369
474c8240 10370@smallexample
c906108c
SS
10371foo (a)
10372 int a;
10373@{
10374 bar (a);
10375 @{
10376 int b = test ();
10377 bar (b);
10378 @}
10379@}
474c8240 10380@end smallexample
c906108c
SS
10381
10382@noindent
10383you can examine and use the variable @code{a} whenever your program is
10384executing within the function @code{foo}, but you can only use or
10385examine the variable @code{b} while your program is executing inside
10386the block where @code{b} is declared.
10387
10388@cindex variable name conflict
10389There is an exception: you can refer to a variable or function whose
10390scope is a single source file even if the current execution point is not
10391in this file. But it is possible to have more than one such variable or
10392function with the same name (in different source files). If that
10393happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10394you can specify a static variable in a particular function or file by
15387254 10395using the colon-colon (@code{::}) notation:
c906108c 10396
d4f3574e 10397@cindex colon-colon, context for variables/functions
12c27660 10398@ifnotinfo
c906108c 10399@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10400@cindex @code{::}, context for variables/functions
12c27660 10401@end ifnotinfo
474c8240 10402@smallexample
c906108c
SS
10403@var{file}::@var{variable}
10404@var{function}::@var{variable}
474c8240 10405@end smallexample
c906108c
SS
10406
10407@noindent
10408Here @var{file} or @var{function} is the name of the context for the
10409static @var{variable}. In the case of file names, you can use quotes to
10410make sure @value{GDBN} parses the file name as a single word---for example,
10411to print a global value of @code{x} defined in @file{f2.c}:
10412
474c8240 10413@smallexample
c906108c 10414(@value{GDBP}) p 'f2.c'::x
474c8240 10415@end smallexample
c906108c 10416
72384ba3
PH
10417The @code{::} notation is normally used for referring to
10418static variables, since you typically disambiguate uses of local variables
10419in functions by selecting the appropriate frame and using the
10420simple name of the variable. However, you may also use this notation
10421to refer to local variables in frames enclosing the selected frame:
10422
10423@smallexample
10424void
10425foo (int a)
10426@{
10427 if (a < 10)
10428 bar (a);
10429 else
10430 process (a); /* Stop here */
10431@}
10432
10433int
10434bar (int a)
10435@{
10436 foo (a + 5);
10437@}
10438@end smallexample
10439
10440@noindent
10441For example, if there is a breakpoint at the commented line,
10442here is what you might see
10443when the program stops after executing the call @code{bar(0)}:
10444
10445@smallexample
10446(@value{GDBP}) p a
10447$1 = 10
10448(@value{GDBP}) p bar::a
10449$2 = 5
10450(@value{GDBP}) up 2
10451#2 0x080483d0 in foo (a=5) at foobar.c:12
10452(@value{GDBP}) p a
10453$3 = 5
10454(@value{GDBP}) p bar::a
10455$4 = 0
10456@end smallexample
10457
b37052ae 10458@cindex C@t{++} scope resolution
805e1f19
TT
10459These uses of @samp{::} are very rarely in conflict with the very
10460similar use of the same notation in C@t{++}. When they are in
10461conflict, the C@t{++} meaning takes precedence; however, this can be
10462overridden by quoting the file or function name with single quotes.
10463
10464For example, suppose the program is stopped in a method of a class
10465that has a field named @code{includefile}, and there is also an
10466include file named @file{includefile} that defines a variable,
10467@code{some_global}.
10468
10469@smallexample
10470(@value{GDBP}) p includefile
10471$1 = 23
10472(@value{GDBP}) p includefile::some_global
10473A syntax error in expression, near `'.
10474(@value{GDBP}) p 'includefile'::some_global
10475$2 = 27
10476@end smallexample
c906108c
SS
10477
10478@cindex wrong values
10479@cindex variable values, wrong
15387254
EZ
10480@cindex function entry/exit, wrong values of variables
10481@cindex optimized code, wrong values of variables
c906108c
SS
10482@quotation
10483@emph{Warning:} Occasionally, a local variable may appear to have the
10484wrong value at certain points in a function---just after entry to a new
10485scope, and just before exit.
10486@end quotation
10487You may see this problem when you are stepping by machine instructions.
10488This is because, on most machines, it takes more than one instruction to
10489set up a stack frame (including local variable definitions); if you are
10490stepping by machine instructions, variables may appear to have the wrong
10491values until the stack frame is completely built. On exit, it usually
10492also takes more than one machine instruction to destroy a stack frame;
10493after you begin stepping through that group of instructions, local
10494variable definitions may be gone.
10495
10496This may also happen when the compiler does significant optimizations.
10497To be sure of always seeing accurate values, turn off all optimization
10498when compiling.
10499
d4f3574e
SS
10500@cindex ``No symbol "foo" in current context''
10501Another possible effect of compiler optimizations is to optimize
10502unused variables out of existence, or assign variables to registers (as
10503opposed to memory addresses). Depending on the support for such cases
10504offered by the debug info format used by the compiler, @value{GDBN}
10505might not be able to display values for such local variables. If that
10506happens, @value{GDBN} will print a message like this:
10507
474c8240 10508@smallexample
d4f3574e 10509No symbol "foo" in current context.
474c8240 10510@end smallexample
d4f3574e
SS
10511
10512To solve such problems, either recompile without optimizations, or use a
10513different debug info format, if the compiler supports several such
e0f8f636
TT
10514formats. @xref{Compilation}, for more information on choosing compiler
10515options. @xref{C, ,C and C@t{++}}, for more information about debug
10516info formats that are best suited to C@t{++} programs.
d4f3574e 10517
ab1adacd
EZ
10518If you ask to print an object whose contents are unknown to
10519@value{GDBN}, e.g., because its data type is not completely specified
10520by the debug information, @value{GDBN} will say @samp{<incomplete
10521type>}. @xref{Symbols, incomplete type}, for more about this.
10522
d69cf9b2
PA
10523@cindex no debug info variables
10524If you try to examine or use the value of a (global) variable for
10525which @value{GDBN} has no type information, e.g., because the program
10526includes no debug information, @value{GDBN} displays an error message.
10527@xref{Symbols, unknown type}, for more about unknown types. If you
10528cast the variable to its declared type, @value{GDBN} gets the
10529variable's value using the cast-to type as the variable's type. For
10530example, in a C program:
10531
10532@smallexample
10533 (@value{GDBP}) p var
10534 'var' has unknown type; cast it to its declared type
10535 (@value{GDBP}) p (float) var
10536 $1 = 3.14
10537@end smallexample
10538
36b11add
JK
10539If you append @kbd{@@entry} string to a function parameter name you get its
10540value at the time the function got called. If the value is not available an
10541error message is printed. Entry values are available only with some compilers.
10542Entry values are normally also printed at the function parameter list according
10543to @ref{set print entry-values}.
10544
10545@smallexample
10546Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1054729 i++;
10548(gdb) next
1054930 e (i);
10550(gdb) print i
10551$1 = 31
10552(gdb) print i@@entry
10553$2 = 30
10554@end smallexample
10555
3a60f64e
JK
10556Strings are identified as arrays of @code{char} values without specified
10557signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10558printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10559@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10560defines literal string type @code{"char"} as @code{char} without a sign.
10561For program code
10562
10563@smallexample
10564char var0[] = "A";
10565signed char var1[] = "A";
10566@end smallexample
10567
10568You get during debugging
10569@smallexample
10570(gdb) print var0
10571$1 = "A"
10572(gdb) print var1
10573$2 = @{65 'A', 0 '\0'@}
10574@end smallexample
10575
6d2ebf8b 10576@node Arrays
79a6e687 10577@section Artificial Arrays
c906108c
SS
10578
10579@cindex artificial array
15387254 10580@cindex arrays
41afff9a 10581@kindex @@@r{, referencing memory as an array}
c906108c
SS
10582It is often useful to print out several successive objects of the
10583same type in memory; a section of an array, or an array of
10584dynamically determined size for which only a pointer exists in the
10585program.
10586
10587You can do this by referring to a contiguous span of memory as an
10588@dfn{artificial array}, using the binary operator @samp{@@}. The left
10589operand of @samp{@@} should be the first element of the desired array
10590and be an individual object. The right operand should be the desired length
10591of the array. The result is an array value whose elements are all of
10592the type of the left argument. The first element is actually the left
10593argument; the second element comes from bytes of memory immediately
10594following those that hold the first element, and so on. Here is an
10595example. If a program says
10596
474c8240 10597@smallexample
c906108c 10598int *array = (int *) malloc (len * sizeof (int));
474c8240 10599@end smallexample
c906108c
SS
10600
10601@noindent
10602you can print the contents of @code{array} with
10603
474c8240 10604@smallexample
c906108c 10605p *array@@len
474c8240 10606@end smallexample
c906108c
SS
10607
10608The left operand of @samp{@@} must reside in memory. Array values made
10609with @samp{@@} in this way behave just like other arrays in terms of
10610subscripting, and are coerced to pointers when used in expressions.
10611Artificial arrays most often appear in expressions via the value history
79a6e687 10612(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10613
10614Another way to create an artificial array is to use a cast.
10615This re-interprets a value as if it were an array.
10616The value need not be in memory:
474c8240 10617@smallexample
c906108c
SS
10618(@value{GDBP}) p/x (short[2])0x12345678
10619$1 = @{0x1234, 0x5678@}
474c8240 10620@end smallexample
c906108c
SS
10621
10622As a convenience, if you leave the array length out (as in
c3f6f71d 10623@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10624the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10625@smallexample
c906108c
SS
10626(@value{GDBP}) p/x (short[])0x12345678
10627$2 = @{0x1234, 0x5678@}
474c8240 10628@end smallexample
c906108c
SS
10629
10630Sometimes the artificial array mechanism is not quite enough; in
10631moderately complex data structures, the elements of interest may not
10632actually be adjacent---for example, if you are interested in the values
10633of pointers in an array. One useful work-around in this situation is
10634to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10635Variables}) as a counter in an expression that prints the first
c906108c
SS
10636interesting value, and then repeat that expression via @key{RET}. For
10637instance, suppose you have an array @code{dtab} of pointers to
10638structures, and you are interested in the values of a field @code{fv}
10639in each structure. Here is an example of what you might type:
10640
474c8240 10641@smallexample
c906108c
SS
10642set $i = 0
10643p dtab[$i++]->fv
10644@key{RET}
10645@key{RET}
10646@dots{}
474c8240 10647@end smallexample
c906108c 10648
6d2ebf8b 10649@node Output Formats
79a6e687 10650@section Output Formats
c906108c
SS
10651
10652@cindex formatted output
10653@cindex output formats
10654By default, @value{GDBN} prints a value according to its data type. Sometimes
10655this is not what you want. For example, you might want to print a number
10656in hex, or a pointer in decimal. Or you might want to view data in memory
10657at a certain address as a character string or as an instruction. To do
10658these things, specify an @dfn{output format} when you print a value.
10659
10660The simplest use of output formats is to say how to print a value
10661already computed. This is done by starting the arguments of the
10662@code{print} command with a slash and a format letter. The format
10663letters supported are:
10664
10665@table @code
10666@item x
10667Regard the bits of the value as an integer, and print the integer in
10668hexadecimal.
10669
10670@item d
10671Print as integer in signed decimal.
10672
10673@item u
10674Print as integer in unsigned decimal.
10675
10676@item o
10677Print as integer in octal.
10678
10679@item t
10680Print as integer in binary. The letter @samp{t} stands for ``two''.
10681@footnote{@samp{b} cannot be used because these format letters are also
10682used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10683see @ref{Memory,,Examining Memory}.}
c906108c
SS
10684
10685@item a
10686@cindex unknown address, locating
3d67e040 10687@cindex locate address
c906108c
SS
10688Print as an address, both absolute in hexadecimal and as an offset from
10689the nearest preceding symbol. You can use this format used to discover
10690where (in what function) an unknown address is located:
10691
474c8240 10692@smallexample
c906108c
SS
10693(@value{GDBP}) p/a 0x54320
10694$3 = 0x54320 <_initialize_vx+396>
474c8240 10695@end smallexample
c906108c 10696
3d67e040
EZ
10697@noindent
10698The command @code{info symbol 0x54320} yields similar results.
10699@xref{Symbols, info symbol}.
10700
c906108c 10701@item c
51274035
EZ
10702Regard as an integer and print it as a character constant. This
10703prints both the numerical value and its character representation. The
10704character representation is replaced with the octal escape @samp{\nnn}
10705for characters outside the 7-bit @sc{ascii} range.
c906108c 10706
ea37ba09
DJ
10707Without this format, @value{GDBN} displays @code{char},
10708@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10709constants. Single-byte members of vectors are displayed as integer
10710data.
10711
c906108c
SS
10712@item f
10713Regard the bits of the value as a floating point number and print
10714using typical floating point syntax.
ea37ba09
DJ
10715
10716@item s
10717@cindex printing strings
10718@cindex printing byte arrays
10719Regard as a string, if possible. With this format, pointers to single-byte
10720data are displayed as null-terminated strings and arrays of single-byte data
10721are displayed as fixed-length strings. Other values are displayed in their
10722natural types.
10723
10724Without this format, @value{GDBN} displays pointers to and arrays of
10725@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10726strings. Single-byte members of a vector are displayed as an integer
10727array.
a6bac58e 10728
6fbe845e
AB
10729@item z
10730Like @samp{x} formatting, the value is treated as an integer and
10731printed as hexadecimal, but leading zeros are printed to pad the value
10732to the size of the integer type.
10733
a6bac58e
TT
10734@item r
10735@cindex raw printing
10736Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10737use a Python-based pretty-printer, if one is available (@pxref{Pretty
10738Printing}). This typically results in a higher-level display of the
10739value's contents. The @samp{r} format bypasses any Python
10740pretty-printer which might exist.
c906108c
SS
10741@end table
10742
10743For example, to print the program counter in hex (@pxref{Registers}), type
10744
474c8240 10745@smallexample
c906108c 10746p/x $pc
474c8240 10747@end smallexample
c906108c
SS
10748
10749@noindent
10750Note that no space is required before the slash; this is because command
10751names in @value{GDBN} cannot contain a slash.
10752
10753To reprint the last value in the value history with a different format,
10754you can use the @code{print} command with just a format and no
10755expression. For example, @samp{p/x} reprints the last value in hex.
10756
6d2ebf8b 10757@node Memory
79a6e687 10758@section Examining Memory
c906108c
SS
10759
10760You can use the command @code{x} (for ``examine'') to examine memory in
10761any of several formats, independently of your program's data types.
10762
10763@cindex examining memory
10764@table @code
41afff9a 10765@kindex x @r{(examine memory)}
c906108c
SS
10766@item x/@var{nfu} @var{addr}
10767@itemx x @var{addr}
10768@itemx x
10769Use the @code{x} command to examine memory.
10770@end table
10771
10772@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10773much memory to display and how to format it; @var{addr} is an
10774expression giving the address where you want to start displaying memory.
10775If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10776Several commands set convenient defaults for @var{addr}.
10777
10778@table @r
10779@item @var{n}, the repeat count
10780The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10781how much memory (counting by units @var{u}) to display. If a negative
10782number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10783@c This really is **decimal**; unaffected by 'set radix' as of GDB
10784@c 4.1.2.
10785
10786@item @var{f}, the display format
51274035
EZ
10787The display format is one of the formats used by @code{print}
10788(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10789@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10790The default is @samp{x} (hexadecimal) initially. The default changes
10791each time you use either @code{x} or @code{print}.
c906108c
SS
10792
10793@item @var{u}, the unit size
10794The unit size is any of
10795
10796@table @code
10797@item b
10798Bytes.
10799@item h
10800Halfwords (two bytes).
10801@item w
10802Words (four bytes). This is the initial default.
10803@item g
10804Giant words (eight bytes).
10805@end table
10806
10807Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10808default unit the next time you use @code{x}. For the @samp{i} format,
10809the unit size is ignored and is normally not written. For the @samp{s} format,
10810the unit size defaults to @samp{b}, unless it is explicitly given.
10811Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1081232-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10813Note that the results depend on the programming language of the
10814current compilation unit. If the language is C, the @samp{s}
10815modifier will use the UTF-16 encoding while @samp{w} will use
10816UTF-32. The encoding is set by the programming language and cannot
10817be altered.
c906108c
SS
10818
10819@item @var{addr}, starting display address
10820@var{addr} is the address where you want @value{GDBN} to begin displaying
10821memory. The expression need not have a pointer value (though it may);
10822it is always interpreted as an integer address of a byte of memory.
10823@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10824@var{addr} is usually just after the last address examined---but several
10825other commands also set the default address: @code{info breakpoints} (to
10826the address of the last breakpoint listed), @code{info line} (to the
10827starting address of a line), and @code{print} (if you use it to display
10828a value from memory).
10829@end table
10830
10831For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10832(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10833starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10834words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10835@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10836
bb556f1f
TK
10837You can also specify a negative repeat count to examine memory backward
10838from the given address. For example, @samp{x/-3uh 0x54320} prints three
10839halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10840
c906108c
SS
10841Since the letters indicating unit sizes are all distinct from the
10842letters specifying output formats, you do not have to remember whether
10843unit size or format comes first; either order works. The output
10844specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10845(However, the count @var{n} must come first; @samp{wx4} does not work.)
10846
10847Even though the unit size @var{u} is ignored for the formats @samp{s}
10848and @samp{i}, you might still want to use a count @var{n}; for example,
10849@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10850including any operands. For convenience, especially when used with
10851the @code{display} command, the @samp{i} format also prints branch delay
10852slot instructions, if any, beyond the count specified, which immediately
10853follow the last instruction that is within the count. The command
10854@code{disassemble} gives an alternative way of inspecting machine
10855instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10856
bb556f1f
TK
10857If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10858the command displays null-terminated strings or instructions before the given
10859address as many as the absolute value of the given number. For the @samp{i}
10860format, we use line number information in the debug info to accurately locate
10861instruction boundaries while disassembling backward. If line info is not
10862available, the command stops examining memory with an error message.
10863
c906108c
SS
10864All the defaults for the arguments to @code{x} are designed to make it
10865easy to continue scanning memory with minimal specifications each time
10866you use @code{x}. For example, after you have inspected three machine
10867instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10868with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10869the repeat count @var{n} is used again; the other arguments default as
10870for successive uses of @code{x}.
10871
2b28d209
PP
10872When examining machine instructions, the instruction at current program
10873counter is shown with a @code{=>} marker. For example:
10874
10875@smallexample
10876(@value{GDBP}) x/5i $pc-6
10877 0x804837f <main+11>: mov %esp,%ebp
10878 0x8048381 <main+13>: push %ecx
10879 0x8048382 <main+14>: sub $0x4,%esp
10880=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10881 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10882@end smallexample
10883
c906108c
SS
10884@cindex @code{$_}, @code{$__}, and value history
10885The addresses and contents printed by the @code{x} command are not saved
10886in the value history because there is often too much of them and they
10887would get in the way. Instead, @value{GDBN} makes these values available for
10888subsequent use in expressions as values of the convenience variables
10889@code{$_} and @code{$__}. After an @code{x} command, the last address
10890examined is available for use in expressions in the convenience variable
10891@code{$_}. The contents of that address, as examined, are available in
10892the convenience variable @code{$__}.
10893
10894If the @code{x} command has a repeat count, the address and contents saved
10895are from the last memory unit printed; this is not the same as the last
10896address printed if several units were printed on the last line of output.
10897
a86c90e6
SM
10898@anchor{addressable memory unit}
10899@cindex addressable memory unit
10900Most targets have an addressable memory unit size of 8 bits. This means
10901that to each memory address are associated 8 bits of data. Some
10902targets, however, have other addressable memory unit sizes.
10903Within @value{GDBN} and this document, the term
10904@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10905when explicitly referring to a chunk of data of that size. The word
10906@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10907the addressable memory unit size of the target. For most systems,
10908addressable memory unit is a synonym of byte.
10909
09d4efe1 10910@cindex remote memory comparison
936d2992 10911@cindex target memory comparison
09d4efe1 10912@cindex verify remote memory image
936d2992 10913@cindex verify target memory image
09d4efe1 10914When you are debugging a program running on a remote target machine
936d2992
PA
10915(@pxref{Remote Debugging}), you may wish to verify the program's image
10916in the remote machine's memory against the executable file you
10917downloaded to the target. Or, on any target, you may want to check
10918whether the program has corrupted its own read-only sections. The
10919@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10920
10921@table @code
10922@kindex compare-sections
95cf3b38 10923@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10924Compare the data of a loadable section @var{section-name} in the
10925executable file of the program being debugged with the same section in
936d2992 10926the target machine's memory, and report any mismatches. With no
95cf3b38 10927arguments, compares all loadable sections. With an argument of
936d2992
PA
10928@code{-r}, compares all loadable read-only sections.
10929
10930Note: for remote targets, this command can be accelerated if the
10931target supports computing the CRC checksum of a block of memory
10932(@pxref{qCRC packet}).
09d4efe1
EZ
10933@end table
10934
6d2ebf8b 10935@node Auto Display
79a6e687 10936@section Automatic Display
c906108c
SS
10937@cindex automatic display
10938@cindex display of expressions
10939
10940If you find that you want to print the value of an expression frequently
10941(to see how it changes), you might want to add it to the @dfn{automatic
10942display list} so that @value{GDBN} prints its value each time your program stops.
10943Each expression added to the list is given a number to identify it;
10944to remove an expression from the list, you specify that number.
10945The automatic display looks like this:
10946
474c8240 10947@smallexample
c906108c
SS
109482: foo = 38
109493: bar[5] = (struct hack *) 0x3804
474c8240 10950@end smallexample
c906108c
SS
10951
10952@noindent
10953This display shows item numbers, expressions and their current values. As with
10954displays you request manually using @code{x} or @code{print}, you can
10955specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10956whether to use @code{print} or @code{x} depending your format
10957specification---it uses @code{x} if you specify either the @samp{i}
10958or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10959
10960@table @code
10961@kindex display
d4f3574e
SS
10962@item display @var{expr}
10963Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10964each time your program stops. @xref{Expressions, ,Expressions}.
10965
10966@code{display} does not repeat if you press @key{RET} again after using it.
10967
d4f3574e 10968@item display/@var{fmt} @var{expr}
c906108c 10969For @var{fmt} specifying only a display format and not a size or
d4f3574e 10970count, add the expression @var{expr} to the auto-display list but
c906108c 10971arrange to display it each time in the specified format @var{fmt}.
79a6e687 10972@xref{Output Formats,,Output Formats}.
c906108c
SS
10973
10974@item display/@var{fmt} @var{addr}
10975For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10976number of units, add the expression @var{addr} as a memory address to
10977be examined each time your program stops. Examining means in effect
79a6e687 10978doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10979@end table
10980
10981For example, @samp{display/i $pc} can be helpful, to see the machine
10982instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10983is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10984
10985@table @code
10986@kindex delete display
10987@kindex undisplay
10988@item undisplay @var{dnums}@dots{}
10989@itemx delete display @var{dnums}@dots{}
c9174737
PA
10990Remove items from the list of expressions to display. Specify the
10991numbers of the displays that you want affected with the command
10992argument @var{dnums}. It can be a single display number, one of the
10993numbers shown in the first field of the @samp{info display} display;
10994or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10995
10996@code{undisplay} does not repeat if you press @key{RET} after using it.
10997(Otherwise you would just get the error @samp{No display number @dots{}}.)
10998
10999@kindex disable display
11000@item disable display @var{dnums}@dots{}
11001Disable the display of item numbers @var{dnums}. A disabled display
11002item is not printed automatically, but is not forgotten. It may be
c9174737
PA
11003enabled again later. Specify the numbers of the displays that you
11004want affected with the command argument @var{dnums}. It can be a
11005single display number, one of the numbers shown in the first field of
11006the @samp{info display} display; or it could be a range of display
11007numbers, as in @code{2-4}.
c906108c
SS
11008
11009@kindex enable display
11010@item enable display @var{dnums}@dots{}
11011Enable display of item numbers @var{dnums}. It becomes effective once
11012again in auto display of its expression, until you specify otherwise.
c9174737
PA
11013Specify the numbers of the displays that you want affected with the
11014command argument @var{dnums}. It can be a single display number, one
11015of the numbers shown in the first field of the @samp{info display}
11016display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
11017
11018@item display
11019Display the current values of the expressions on the list, just as is
11020done when your program stops.
11021
11022@kindex info display
11023@item info display
11024Print the list of expressions previously set up to display
11025automatically, each one with its item number, but without showing the
11026values. This includes disabled expressions, which are marked as such.
11027It also includes expressions which would not be displayed right now
11028because they refer to automatic variables not currently available.
11029@end table
11030
15387254 11031@cindex display disabled out of scope
c906108c
SS
11032If a display expression refers to local variables, then it does not make
11033sense outside the lexical context for which it was set up. Such an
11034expression is disabled when execution enters a context where one of its
11035variables is not defined. For example, if you give the command
11036@code{display last_char} while inside a function with an argument
11037@code{last_char}, @value{GDBN} displays this argument while your program
11038continues to stop inside that function. When it stops elsewhere---where
11039there is no variable @code{last_char}---the display is disabled
11040automatically. The next time your program stops where @code{last_char}
11041is meaningful, you can enable the display expression once again.
11042
6d2ebf8b 11043@node Print Settings
79a6e687 11044@section Print Settings
c906108c
SS
11045
11046@cindex format options
11047@cindex print settings
11048@value{GDBN} provides the following ways to control how arrays, structures,
11049and symbols are printed.
11050
11051@noindent
11052These settings are useful for debugging programs in any language:
11053
11054@table @code
4644b6e3 11055@kindex set print
3345721a 11056@anchor{set print address}
c906108c
SS
11057@item set print address
11058@itemx set print address on
4644b6e3 11059@cindex print/don't print memory addresses
c906108c
SS
11060@value{GDBN} prints memory addresses showing the location of stack
11061traces, structure values, pointer values, breakpoints, and so forth,
11062even when it also displays the contents of those addresses. The default
11063is @code{on}. For example, this is what a stack frame display looks like with
11064@code{set print address on}:
11065
11066@smallexample
11067@group
11068(@value{GDBP}) f
11069#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11070 at input.c:530
11071530 if (lquote != def_lquote)
11072@end group
11073@end smallexample
11074
11075@item set print address off
11076Do not print addresses when displaying their contents. For example,
11077this is the same stack frame displayed with @code{set print address off}:
11078
11079@smallexample
11080@group
11081(@value{GDBP}) set print addr off
11082(@value{GDBP}) f
11083#0 set_quotes (lq="<<", rq=">>") at input.c:530
11084530 if (lquote != def_lquote)
11085@end group
11086@end smallexample
11087
11088You can use @samp{set print address off} to eliminate all machine
11089dependent displays from the @value{GDBN} interface. For example, with
11090@code{print address off}, you should get the same text for backtraces on
11091all machines---whether or not they involve pointer arguments.
11092
4644b6e3 11093@kindex show print
c906108c
SS
11094@item show print address
11095Show whether or not addresses are to be printed.
11096@end table
11097
11098When @value{GDBN} prints a symbolic address, it normally prints the
11099closest earlier symbol plus an offset. If that symbol does not uniquely
11100identify the address (for example, it is a name whose scope is a single
11101source file), you may need to clarify. One way to do this is with
11102@code{info line}, for example @samp{info line *0x4537}. Alternately,
11103you can set @value{GDBN} to print the source file and line number when
11104it prints a symbolic address:
11105
11106@table @code
c906108c 11107@item set print symbol-filename on
9c16f35a
EZ
11108@cindex source file and line of a symbol
11109@cindex symbol, source file and line
c906108c
SS
11110Tell @value{GDBN} to print the source file name and line number of a
11111symbol in the symbolic form of an address.
11112
11113@item set print symbol-filename off
11114Do not print source file name and line number of a symbol. This is the
11115default.
11116
c906108c
SS
11117@item show print symbol-filename
11118Show whether or not @value{GDBN} will print the source file name and
11119line number of a symbol in the symbolic form of an address.
11120@end table
11121
11122Another situation where it is helpful to show symbol filenames and line
11123numbers is when disassembling code; @value{GDBN} shows you the line
11124number and source file that corresponds to each instruction.
11125
11126Also, you may wish to see the symbolic form only if the address being
11127printed is reasonably close to the closest earlier symbol:
11128
11129@table @code
c906108c 11130@item set print max-symbolic-offset @var{max-offset}
f81d1120 11131@itemx set print max-symbolic-offset unlimited
4644b6e3 11132@cindex maximum value for offset of closest symbol
c906108c
SS
11133Tell @value{GDBN} to only display the symbolic form of an address if the
11134offset between the closest earlier symbol and the address is less than
f81d1120
PA
11135@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11136to always print the symbolic form of an address if any symbol precedes
11137it. Zero is equivalent to @code{unlimited}.
c906108c 11138
c906108c
SS
11139@item show print max-symbolic-offset
11140Ask how large the maximum offset is that @value{GDBN} prints in a
11141symbolic address.
11142@end table
11143
11144@cindex wild pointer, interpreting
11145@cindex pointer, finding referent
11146If you have a pointer and you are not sure where it points, try
11147@samp{set print symbol-filename on}. Then you can determine the name
11148and source file location of the variable where it points, using
11149@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11150For example, here @value{GDBN} shows that a variable @code{ptt} points
11151at another variable @code{t}, defined in @file{hi2.c}:
11152
474c8240 11153@smallexample
c906108c
SS
11154(@value{GDBP}) set print symbol-filename on
11155(@value{GDBP}) p/a ptt
11156$4 = 0xe008 <t in hi2.c>
474c8240 11157@end smallexample
c906108c
SS
11158
11159@quotation
11160@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11161does not show the symbol name and filename of the referent, even with
11162the appropriate @code{set print} options turned on.
11163@end quotation
11164
9cb709b6
TT
11165You can also enable @samp{/a}-like formatting all the time using
11166@samp{set print symbol on}:
11167
3345721a 11168@anchor{set print symbol}
9cb709b6
TT
11169@table @code
11170@item set print symbol on
11171Tell @value{GDBN} to print the symbol corresponding to an address, if
11172one exists.
11173
11174@item set print symbol off
11175Tell @value{GDBN} not to print the symbol corresponding to an
11176address. In this mode, @value{GDBN} will still print the symbol
11177corresponding to pointers to functions. This is the default.
11178
11179@item show print symbol
11180Show whether @value{GDBN} will display the symbol corresponding to an
11181address.
11182@end table
11183
c906108c
SS
11184Other settings control how different kinds of objects are printed:
11185
11186@table @code
3345721a 11187@anchor{set print array}
c906108c
SS
11188@item set print array
11189@itemx set print array on
4644b6e3 11190@cindex pretty print arrays
c906108c
SS
11191Pretty print arrays. This format is more convenient to read,
11192but uses more space. The default is off.
11193
11194@item set print array off
11195Return to compressed format for arrays.
11196
c906108c
SS
11197@item show print array
11198Show whether compressed or pretty format is selected for displaying
11199arrays.
11200
3c9c013a 11201@cindex print array indexes
3345721a 11202@anchor{set print array-indexes}
3c9c013a
JB
11203@item set print array-indexes
11204@itemx set print array-indexes on
11205Print the index of each element when displaying arrays. May be more
11206convenient to locate a given element in the array or quickly find the
11207index of a given element in that printed array. The default is off.
11208
11209@item set print array-indexes off
11210Stop printing element indexes when displaying arrays.
11211
11212@item show print array-indexes
11213Show whether the index of each element is printed when displaying
11214arrays.
11215
3345721a 11216@anchor{set print elements}
c906108c 11217@item set print elements @var{number-of-elements}
f81d1120 11218@itemx set print elements unlimited
4644b6e3 11219@cindex number of array elements to print
9c16f35a 11220@cindex limit on number of printed array elements
c906108c
SS
11221Set a limit on how many elements of an array @value{GDBN} will print.
11222If @value{GDBN} is printing a large array, it stops printing after it has
11223printed the number of elements set by the @code{set print elements} command.
11224This limit also applies to the display of strings.
d4f3574e 11225When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
11226Setting @var{number-of-elements} to @code{unlimited} or zero means
11227that the number of elements to print is unlimited.
c906108c 11228
c906108c
SS
11229@item show print elements
11230Display the number of elements of a large array that @value{GDBN} will print.
11231If the number is 0, then the printing is unlimited.
11232
3345721a 11233@anchor{set print frame-arguments}
b4740add 11234@item set print frame-arguments @var{value}
a0381d3a 11235@kindex set print frame-arguments
b4740add
JB
11236@cindex printing frame argument values
11237@cindex print all frame argument values
11238@cindex print frame argument values for scalars only
bc4268a5 11239@cindex do not print frame arguments
b4740add
JB
11240This command allows to control how the values of arguments are printed
11241when the debugger prints a frame (@pxref{Frames}). The possible
11242values are:
11243
11244@table @code
11245@item all
4f5376b2 11246The values of all arguments are printed.
b4740add
JB
11247
11248@item scalars
11249Print the value of an argument only if it is a scalar. The value of more
11250complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11251by @code{@dots{}}. This is the default. Here is an example where
11252only scalar arguments are shown:
b4740add
JB
11253
11254@smallexample
11255#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11256 at frame-args.c:23
11257@end smallexample
11258
11259@item none
11260None of the argument values are printed. Instead, the value of each argument
11261is replaced by @code{@dots{}}. In this case, the example above now becomes:
11262
11263@smallexample
11264#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11265 at frame-args.c:23
11266@end smallexample
bc4268a5
PW
11267
11268@item presence
11269Only the presence of arguments is indicated by @code{@dots{}}.
11270The @code{@dots{}} are not printed for function without any arguments.
11271None of the argument names and values are printed.
11272In this case, the example above now becomes:
11273
11274@smallexample
11275#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11276@end smallexample
11277
b4740add
JB
11278@end table
11279
4f5376b2
JB
11280By default, only scalar arguments are printed. This command can be used
11281to configure the debugger to print the value of all arguments, regardless
11282of their type. However, it is often advantageous to not print the value
11283of more complex parameters. For instance, it reduces the amount of
11284information printed in each frame, making the backtrace more readable.
11285Also, it improves performance when displaying Ada frames, because
11286the computation of large arguments can sometimes be CPU-intensive,
11287especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11288to @code{scalars} (the default), @code{none} or @code{presence} avoids
11289this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11290
11291@item show print frame-arguments
11292Show how the value of arguments should be displayed when printing a frame.
11293
3345721a 11294@anchor{set print raw-frame-arguments}
2daf894e 11295@item set print raw-frame-arguments on
e7045703
DE
11296Print frame arguments in raw, non pretty-printed, form.
11297
2daf894e 11298@item set print raw-frame-arguments off
e7045703
DE
11299Print frame arguments in pretty-printed form, if there is a pretty-printer
11300for the value (@pxref{Pretty Printing}),
11301otherwise print the value in raw form.
11302This is the default.
11303
2daf894e 11304@item show print raw-frame-arguments
e7045703
DE
11305Show whether to print frame arguments in raw form.
11306
36b11add 11307@anchor{set print entry-values}
e18b2753
JK
11308@item set print entry-values @var{value}
11309@kindex set print entry-values
11310Set printing of frame argument values at function entry. In some cases
11311@value{GDBN} can determine the value of function argument which was passed by
11312the function caller, even if the value was modified inside the called function
11313and therefore is different. With optimized code, the current value could be
11314unavailable, but the entry value may still be known.
11315
11316The default value is @code{default} (see below for its description). Older
11317@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11318this feature will behave in the @code{default} setting the same way as with the
11319@code{no} setting.
11320
11321This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11322the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11323@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11324this information.
11325
11326The @var{value} parameter can be one of the following:
11327
11328@table @code
11329@item no
11330Print only actual parameter values, never print values from function entry
11331point.
11332@smallexample
11333#0 equal (val=5)
11334#0 different (val=6)
11335#0 lost (val=<optimized out>)
11336#0 born (val=10)
11337#0 invalid (val=<optimized out>)
11338@end smallexample
11339
11340@item only
11341Print only parameter values from function entry point. The actual parameter
11342values are never printed.
11343@smallexample
11344#0 equal (val@@entry=5)
11345#0 different (val@@entry=5)
11346#0 lost (val@@entry=5)
11347#0 born (val@@entry=<optimized out>)
11348#0 invalid (val@@entry=<optimized out>)
11349@end smallexample
11350
11351@item preferred
11352Print only parameter values from function entry point. If value from function
11353entry point is not known while the actual value is known, print the actual
11354value for such parameter.
11355@smallexample
11356#0 equal (val@@entry=5)
11357#0 different (val@@entry=5)
11358#0 lost (val@@entry=5)
11359#0 born (val=10)
11360#0 invalid (val@@entry=<optimized out>)
11361@end smallexample
11362
11363@item if-needed
11364Print actual parameter values. If actual parameter value is not known while
11365value from function entry point is known, print the entry point value for such
11366parameter.
11367@smallexample
11368#0 equal (val=5)
11369#0 different (val=6)
11370#0 lost (val@@entry=5)
11371#0 born (val=10)
11372#0 invalid (val=<optimized out>)
11373@end smallexample
11374
11375@item both
11376Always print both the actual parameter value and its value from function entry
11377point, even if values of one or both are not available due to compiler
11378optimizations.
11379@smallexample
11380#0 equal (val=5, val@@entry=5)
11381#0 different (val=6, val@@entry=5)
11382#0 lost (val=<optimized out>, val@@entry=5)
11383#0 born (val=10, val@@entry=<optimized out>)
11384#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11385@end smallexample
11386
11387@item compact
11388Print the actual parameter value if it is known and also its value from
11389function entry point if it is known. If neither is known, print for the actual
11390value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11391values are known and identical, print the shortened
11392@code{param=param@@entry=VALUE} notation.
11393@smallexample
11394#0 equal (val=val@@entry=5)
11395#0 different (val=6, val@@entry=5)
11396#0 lost (val@@entry=5)
11397#0 born (val=10)
11398#0 invalid (val=<optimized out>)
11399@end smallexample
11400
11401@item default
11402Always print the actual parameter value. Print also its value from function
11403entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11404if both values are known and identical, print the shortened
11405@code{param=param@@entry=VALUE} notation.
11406@smallexample
11407#0 equal (val=val@@entry=5)
11408#0 different (val=6, val@@entry=5)
11409#0 lost (val=<optimized out>, val@@entry=5)
11410#0 born (val=10)
11411#0 invalid (val=<optimized out>)
11412@end smallexample
11413@end table
11414
11415For analysis messages on possible failures of frame argument values at function
11416entry resolution see @ref{set debug entry-values}.
11417
11418@item show print entry-values
11419Show the method being used for printing of frame argument values at function
11420entry.
11421
bc4268a5
PW
11422@anchor{set print frame-info}
11423@item set print frame-info @var{value}
11424@kindex set print frame-info
11425@cindex printing frame information
11426@cindex frame information, printing
11427This command allows to control the information printed when
11428the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11429for a general explanation about frames and frame information.
11430Note that some other settings (such as @code{set print frame-arguments}
11431and @code{set print address}) are also influencing if and how some frame
11432information is displayed. In particular, the frame program counter is never
11433printed if @code{set print address} is off.
11434
11435The possible values for @code{set print frame-info} are:
11436@table @code
11437@item short-location
11438Print the frame level, the program counter (if not at the
11439beginning of the location source line), the function, the function
11440arguments.
11441@item location
11442Same as @code{short-location} but also print the source file and source line
11443number.
11444@item location-and-address
11445Same as @code{location} but print the program counter even if located at the
11446beginning of the location source line.
11447@item source-line
11448Print the program counter (if not at the beginning of the location
11449source line), the line number and the source line.
11450@item source-and-location
11451Print what @code{location} and @code{source-line} are printing.
11452@item auto
11453The information printed for a frame is decided automatically
11454by the @value{GDBN} command that prints a frame.
11455For example, @code{frame} prints the information printed by
11456@code{source-and-location} while @code{stepi} will switch between
11457@code{source-line} and @code{source-and-location} depending on the program
11458counter.
11459The default value is @code{auto}.
11460@end table
11461
3345721a 11462@anchor{set print repeats}
f81d1120
PA
11463@item set print repeats @var{number-of-repeats}
11464@itemx set print repeats unlimited
9c16f35a
EZ
11465@cindex repeated array elements
11466Set the threshold for suppressing display of repeated array
d3e8051b 11467elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11468array exceeds the threshold, @value{GDBN} prints the string
11469@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11470identical repetitions, instead of displaying the identical elements
f81d1120
PA
11471themselves. Setting the threshold to @code{unlimited} or zero will
11472cause all elements to be individually printed. The default threshold
11473is 10.
9c16f35a
EZ
11474
11475@item show print repeats
11476Display the current threshold for printing repeated identical
11477elements.
11478
3345721a 11479@anchor{set print max-depth}
2e62ab40
AB
11480@item set print max-depth @var{depth}
11481@item set print max-depth unlimited
11482@cindex printing nested structures
11483Set the threshold after which nested structures are replaced with
11484ellipsis, this can make visualising deeply nested structures easier.
11485
11486For example, given this C code
11487
11488@smallexample
11489typedef struct s1 @{ int a; @} s1;
11490typedef struct s2 @{ s1 b; @} s2;
11491typedef struct s3 @{ s2 c; @} s3;
11492typedef struct s4 @{ s3 d; @} s4;
11493
11494s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11495@end smallexample
11496
11497The following table shows how different values of @var{depth} will
11498effect how @code{var} is printed by @value{GDBN}:
11499
11500@multitable @columnfractions .3 .7
11501@headitem @var{depth} setting @tab Result of @samp{p var}
11502@item unlimited
11503@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11504@item @code{0}
11505@tab @code{$1 = @{...@}}
11506@item @code{1}
11507@tab @code{$1 = @{d = @{...@}@}}
11508@item @code{2}
11509@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11510@item @code{3}
11511@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11512@item @code{4}
11513@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11514@end multitable
11515
11516To see the contents of structures that have been hidden the user can
11517either increase the print max-depth, or they can print the elements of
11518the structure that are visible, for example
11519
11520@smallexample
11521(gdb) set print max-depth 2
11522(gdb) p var
11523$1 = @{d = @{c = @{...@}@}@}
11524(gdb) p var.d
11525$2 = @{c = @{b = @{...@}@}@}
11526(gdb) p var.d.c
11527$3 = @{b = @{a = 3@}@}
11528@end smallexample
11529
11530The pattern used to replace nested structures varies based on
11531language, for most languages @code{@{...@}} is used, but Fortran uses
11532@code{(...)}.
11533
11534@item show print max-depth
11535Display the current threshold after which nested structures are
11536replaces with ellipsis.
11537
3345721a 11538@anchor{set print null-stop}
c906108c 11539@item set print null-stop
4644b6e3 11540@cindex @sc{null} elements in arrays
c906108c 11541Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11542@sc{null} is encountered. This is useful when large arrays actually
c906108c 11543contain only short strings.
d4f3574e 11544The default is off.
c906108c 11545
9c16f35a
EZ
11546@item show print null-stop
11547Show whether @value{GDBN} stops printing an array on the first
11548@sc{null} character.
11549
3345721a 11550@anchor{set print pretty}
c906108c 11551@item set print pretty on
9c16f35a
EZ
11552@cindex print structures in indented form
11553@cindex indentation in structure display
5d161b24 11554Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11555per line, like this:
11556
11557@smallexample
11558@group
11559$1 = @{
11560 next = 0x0,
11561 flags = @{
11562 sweet = 1,
11563 sour = 1
11564 @},
11565 meat = 0x54 "Pork"
11566@}
11567@end group
11568@end smallexample
11569
11570@item set print pretty off
11571Cause @value{GDBN} to print structures in a compact format, like this:
11572
11573@smallexample
11574@group
11575$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11576meat = 0x54 "Pork"@}
11577@end group
11578@end smallexample
11579
11580@noindent
11581This is the default format.
11582
c906108c
SS
11583@item show print pretty
11584Show which format @value{GDBN} is using to print structures.
11585
d8edc8b7
PW
11586@anchor{set print raw-values}
11587@item set print raw-values on
11588Print values in raw form, without applying the pretty
11589printers for the value.
11590
11591@item set print raw-values off
11592Print values in pretty-printed form, if there is a pretty-printer
11593for the value (@pxref{Pretty Printing}),
11594otherwise print the value in raw form.
11595
11596The default setting is ``off''.
11597
11598@item show print raw-values
11599Show whether to print values in raw form.
11600
c906108c 11601@item set print sevenbit-strings on
4644b6e3
EZ
11602@cindex eight-bit characters in strings
11603@cindex octal escapes in strings
c906108c
SS
11604Print using only seven-bit characters; if this option is set,
11605@value{GDBN} displays any eight-bit characters (in strings or
11606character values) using the notation @code{\}@var{nnn}. This setting is
11607best if you are working in English (@sc{ascii}) and you use the
11608high-order bit of characters as a marker or ``meta'' bit.
11609
11610@item set print sevenbit-strings off
11611Print full eight-bit characters. This allows the use of more
11612international character sets, and is the default.
11613
c906108c
SS
11614@item show print sevenbit-strings
11615Show whether or not @value{GDBN} is printing only seven-bit characters.
11616
3345721a 11617@anchor{set print union}
c906108c 11618@item set print union on
4644b6e3 11619@cindex unions in structures, printing
9c16f35a
EZ
11620Tell @value{GDBN} to print unions which are contained in structures
11621and other unions. This is the default setting.
c906108c
SS
11622
11623@item set print union off
9c16f35a
EZ
11624Tell @value{GDBN} not to print unions which are contained in
11625structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11626instead.
c906108c 11627
c906108c
SS
11628@item show print union
11629Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11630structures and other unions.
c906108c
SS
11631
11632For example, given the declarations
11633
11634@smallexample
11635typedef enum @{Tree, Bug@} Species;
11636typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11637typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11638 Bug_forms;
11639
11640struct thing @{
11641 Species it;
11642 union @{
11643 Tree_forms tree;
11644 Bug_forms bug;
11645 @} form;
11646@};
11647
11648struct thing foo = @{Tree, @{Acorn@}@};
11649@end smallexample
11650
11651@noindent
11652with @code{set print union on} in effect @samp{p foo} would print
11653
11654@smallexample
11655$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11656@end smallexample
11657
11658@noindent
11659and with @code{set print union off} in effect it would print
11660
11661@smallexample
11662$1 = @{it = Tree, form = @{...@}@}
11663@end smallexample
9c16f35a
EZ
11664
11665@noindent
11666@code{set print union} affects programs written in C-like languages
11667and in Pascal.
c906108c
SS
11668@end table
11669
c906108c
SS
11670@need 1000
11671@noindent
b37052ae 11672These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11673
11674@table @code
4644b6e3 11675@cindex demangling C@t{++} names
c906108c
SS
11676@item set print demangle
11677@itemx set print demangle on
b37052ae 11678Print C@t{++} names in their source form rather than in the encoded
c906108c 11679(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11680linkage. The default is on.
c906108c 11681
c906108c 11682@item show print demangle
b37052ae 11683Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11684
c906108c
SS
11685@item set print asm-demangle
11686@itemx set print asm-demangle on
b37052ae 11687Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11688in assembler code printouts such as instruction disassemblies.
11689The default is off.
11690
c906108c 11691@item show print asm-demangle
b37052ae 11692Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11693or demangled form.
11694
b37052ae
EZ
11695@cindex C@t{++} symbol decoding style
11696@cindex symbol decoding style, C@t{++}
a8f24a35 11697@kindex set demangle-style
c906108c 11698@item set demangle-style @var{style}
041be526
SM
11699Choose among several encoding schemes used by different compilers to represent
11700C@t{++} names. If you omit @var{style}, you will see a list of possible
11701formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11702decoding style by inspecting your program.
c906108c 11703
c906108c 11704@item show demangle-style
b37052ae 11705Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11706
3345721a 11707@anchor{set print object}
c906108c
SS
11708@item set print object
11709@itemx set print object on
4644b6e3 11710@cindex derived type of an object, printing
9c16f35a 11711@cindex display derived types
c906108c
SS
11712When displaying a pointer to an object, identify the @emph{actual}
11713(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11714the virtual function table. Note that the virtual function table is
11715required---this feature can only work for objects that have run-time
11716type identification; a single virtual method in the object's declared
8264ba82
AG
11717type is sufficient. Note that this setting is also taken into account when
11718working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11719
11720@item set print object off
11721Display only the declared type of objects, without reference to the
11722virtual function table. This is the default setting.
11723
c906108c
SS
11724@item show print object
11725Show whether actual, or declared, object types are displayed.
11726
3345721a 11727@anchor{set print static-members}
c906108c
SS
11728@item set print static-members
11729@itemx set print static-members on
4644b6e3 11730@cindex static members of C@t{++} objects
b37052ae 11731Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11732
11733@item set print static-members off
b37052ae 11734Do not print static members when displaying a C@t{++} object.
c906108c 11735
c906108c 11736@item show print static-members
9c16f35a
EZ
11737Show whether C@t{++} static members are printed or not.
11738
11739@item set print pascal_static-members
11740@itemx set print pascal_static-members on
d3e8051b
EZ
11741@cindex static members of Pascal objects
11742@cindex Pascal objects, static members display
9c16f35a
EZ
11743Print static members when displaying a Pascal object. The default is on.
11744
11745@item set print pascal_static-members off
11746Do not print static members when displaying a Pascal object.
11747
11748@item show print pascal_static-members
11749Show whether Pascal static members are printed or not.
c906108c
SS
11750
11751@c These don't work with HP ANSI C++ yet.
3345721a 11752@anchor{set print vtbl}
c906108c
SS
11753@item set print vtbl
11754@itemx set print vtbl on
4644b6e3 11755@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11756@cindex virtual functions (C@t{++}) display
11757@cindex VTBL display
b37052ae 11758Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11759(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11760ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11761
11762@item set print vtbl off
b37052ae 11763Do not pretty print C@t{++} virtual function tables.
c906108c 11764
c906108c 11765@item show print vtbl
b37052ae 11766Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11767@end table
c906108c 11768
4c374409
JK
11769@node Pretty Printing
11770@section Pretty Printing
11771
11772@value{GDBN} provides a mechanism to allow pretty-printing of values using
11773Python code. It greatly simplifies the display of complex objects. This
11774mechanism works for both MI and the CLI.
11775
7b51bc51
DE
11776@menu
11777* Pretty-Printer Introduction:: Introduction to pretty-printers
11778* Pretty-Printer Example:: An example pretty-printer
11779* Pretty-Printer Commands:: Pretty-printer commands
11780@end menu
11781
11782@node Pretty-Printer Introduction
11783@subsection Pretty-Printer Introduction
11784
11785When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11786registered for the value. If there is then @value{GDBN} invokes the
11787pretty-printer to print the value. Otherwise the value is printed normally.
11788
11789Pretty-printers are normally named. This makes them easy to manage.
11790The @samp{info pretty-printer} command will list all the installed
11791pretty-printers with their names.
11792If a pretty-printer can handle multiple data types, then its
11793@dfn{subprinters} are the printers for the individual data types.
11794Each such subprinter has its own name.
4e04c971 11795The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11796
11797Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11798Typically they are automatically loaded and registered when the corresponding
11799debug information is loaded, thus making them available without having to
11800do anything special.
11801
11802There are three places where a pretty-printer can be registered.
11803
11804@itemize @bullet
11805@item
11806Pretty-printers registered globally are available when debugging
11807all inferiors.
11808
11809@item
11810Pretty-printers registered with a program space are available only
11811when debugging that program.
11812@xref{Progspaces In Python}, for more details on program spaces in Python.
11813
11814@item
11815Pretty-printers registered with an objfile are loaded and unloaded
11816with the corresponding objfile (e.g., shared library).
11817@xref{Objfiles In Python}, for more details on objfiles in Python.
11818@end itemize
11819
11820@xref{Selecting Pretty-Printers}, for further information on how
11821pretty-printers are selected,
11822
11823@xref{Writing a Pretty-Printer}, for implementing pretty printers
11824for new types.
11825
11826@node Pretty-Printer Example
11827@subsection Pretty-Printer Example
11828
11829Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11830
11831@smallexample
11832(@value{GDBP}) print s
11833$1 = @{
11834 static npos = 4294967295,
11835 _M_dataplus = @{
11836 <std::allocator<char>> = @{
11837 <__gnu_cxx::new_allocator<char>> = @{
11838 <No data fields>@}, <No data fields>
11839 @},
11840 members of std::basic_string<char, std::char_traits<char>,
11841 std::allocator<char> >::_Alloc_hider:
11842 _M_p = 0x804a014 "abcd"
11843 @}
11844@}
11845@end smallexample
11846
11847With a pretty-printer for @code{std::string} only the contents are printed:
11848
11849@smallexample
11850(@value{GDBP}) print s
11851$2 = "abcd"
11852@end smallexample
11853
7b51bc51
DE
11854@node Pretty-Printer Commands
11855@subsection Pretty-Printer Commands
11856@cindex pretty-printer commands
11857
11858@table @code
11859@kindex info pretty-printer
11860@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11861Print the list of installed pretty-printers.
11862This includes disabled pretty-printers, which are marked as such.
11863
11864@var{object-regexp} is a regular expression matching the objects
11865whose pretty-printers to list.
11866Objects can be @code{global}, the program space's file
11867(@pxref{Progspaces In Python}),
11868and the object files within that program space (@pxref{Objfiles In Python}).
11869@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11870looks up a printer from these three objects.
11871
11872@var{name-regexp} is a regular expression matching the name of the printers
11873to list.
11874
11875@kindex disable pretty-printer
11876@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11877Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11878A disabled pretty-printer is not forgotten, it may be enabled again later.
11879
11880@kindex enable pretty-printer
11881@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11882Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11883@end table
11884
11885Example:
11886
11887Suppose we have three pretty-printers installed: one from library1.so
11888named @code{foo} that prints objects of type @code{foo}, and
11889another from library2.so named @code{bar} that prints two types of objects,
11890@code{bar1} and @code{bar2}.
11891
11892@smallexample
11893(gdb) info pretty-printer
11894library1.so:
11895 foo
11896library2.so:
11897 bar
11898 bar1
11899 bar2
11900(gdb) info pretty-printer library2
11901library2.so:
11902 bar
11903 bar1
11904 bar2
11905(gdb) disable pretty-printer library1
119061 printer disabled
119072 of 3 printers enabled
11908(gdb) info pretty-printer
11909library1.so:
11910 foo [disabled]
11911library2.so:
11912 bar
11913 bar1
11914 bar2
088a96da 11915(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
119161 printer disabled
119171 of 3 printers enabled
11918(gdb) info pretty-printer library2
11919library1.so:
11920 foo [disabled]
11921library2.so:
11922 bar
11923 bar1 [disabled]
11924 bar2
11925(gdb) disable pretty-printer library2 bar
119261 printer disabled
119270 of 3 printers enabled
11928(gdb) info pretty-printer library2
11929library1.so:
11930 foo [disabled]
11931library2.so:
11932 bar [disabled]
11933 bar1 [disabled]
11934 bar2
11935@end smallexample
11936
11937Note that for @code{bar} the entire printer can be disabled,
11938as can each individual subprinter.
4c374409 11939
d8edc8b7
PW
11940Printing values and frame arguments is done by default using
11941the enabled pretty printers.
11942
11943The print option @code{-raw-values} and @value{GDBN} setting
11944@code{set print raw-values} (@pxref{set print raw-values}) can be
11945used to print values without applying the enabled pretty printers.
11946
11947Similarly, the backtrace option @code{-raw-frame-arguments} and
11948@value{GDBN} setting @code{set print raw-frame-arguments}
11949(@pxref{set print raw-frame-arguments}) can be used to ignore the
11950enabled pretty printers when printing frame argument values.
11951
6d2ebf8b 11952@node Value History
79a6e687 11953@section Value History
c906108c
SS
11954
11955@cindex value history
9c16f35a 11956@cindex history of values printed by @value{GDBN}
5d161b24
DB
11957Values printed by the @code{print} command are saved in the @value{GDBN}
11958@dfn{value history}. This allows you to refer to them in other expressions.
11959Values are kept until the symbol table is re-read or discarded
11960(for example with the @code{file} or @code{symbol-file} commands).
11961When the symbol table changes, the value history is discarded,
11962since the values may contain pointers back to the types defined in the
c906108c
SS
11963symbol table.
11964
11965@cindex @code{$}
11966@cindex @code{$$}
11967@cindex history number
11968The values printed are given @dfn{history numbers} by which you can
11969refer to them. These are successive integers starting with one.
11970@code{print} shows you the history number assigned to a value by
11971printing @samp{$@var{num} = } before the value; here @var{num} is the
11972history number.
11973
11974To refer to any previous value, use @samp{$} followed by the value's
11975history number. The way @code{print} labels its output is designed to
11976remind you of this. Just @code{$} refers to the most recent value in
11977the history, and @code{$$} refers to the value before that.
11978@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11979is the value just prior to @code{$$}, @code{$$1} is equivalent to
11980@code{$$}, and @code{$$0} is equivalent to @code{$}.
11981
11982For example, suppose you have just printed a pointer to a structure and
11983want to see the contents of the structure. It suffices to type
11984
474c8240 11985@smallexample
c906108c 11986p *$
474c8240 11987@end smallexample
c906108c
SS
11988
11989If you have a chain of structures where the component @code{next} points
11990to the next one, you can print the contents of the next one with this:
11991
474c8240 11992@smallexample
c906108c 11993p *$.next
474c8240 11994@end smallexample
c906108c
SS
11995
11996@noindent
11997You can print successive links in the chain by repeating this
11998command---which you can do by just typing @key{RET}.
11999
12000Note that the history records values, not expressions. If the value of
12001@code{x} is 4 and you type these commands:
12002
474c8240 12003@smallexample
c906108c
SS
12004print x
12005set x=5
474c8240 12006@end smallexample
c906108c
SS
12007
12008@noindent
12009then the value recorded in the value history by the @code{print} command
12010remains 4 even though the value of @code{x} has changed.
12011
12012@table @code
12013@kindex show values
12014@item show values
12015Print the last ten values in the value history, with their item numbers.
12016This is like @samp{p@ $$9} repeated ten times, except that @code{show
12017values} does not change the history.
12018
12019@item show values @var{n}
12020Print ten history values centered on history item number @var{n}.
12021
12022@item show values +
12023Print ten history values just after the values last printed. If no more
12024values are available, @code{show values +} produces no display.
12025@end table
12026
12027Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12028same effect as @samp{show values +}.
12029
6d2ebf8b 12030@node Convenience Vars
79a6e687 12031@section Convenience Variables
c906108c
SS
12032
12033@cindex convenience variables
9c16f35a 12034@cindex user-defined variables
c906108c
SS
12035@value{GDBN} provides @dfn{convenience variables} that you can use within
12036@value{GDBN} to hold on to a value and refer to it later. These variables
12037exist entirely within @value{GDBN}; they are not part of your program, and
12038setting a convenience variable has no direct effect on further execution
12039of your program. That is why you can use them freely.
12040
12041Convenience variables are prefixed with @samp{$}. Any name preceded by
12042@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 12043the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 12044(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 12045by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
12046
12047You can save a value in a convenience variable with an assignment
12048expression, just as you would set a variable in your program.
12049For example:
12050
474c8240 12051@smallexample
c906108c 12052set $foo = *object_ptr
474c8240 12053@end smallexample
c906108c
SS
12054
12055@noindent
12056would save in @code{$foo} the value contained in the object pointed to by
12057@code{object_ptr}.
12058
12059Using a convenience variable for the first time creates it, but its
12060value is @code{void} until you assign a new value. You can alter the
12061value with another assignment at any time.
12062
12063Convenience variables have no fixed types. You can assign a convenience
12064variable any type of value, including structures and arrays, even if
12065that variable already has a value of a different type. The convenience
12066variable, when used as an expression, has the type of its current value.
12067
12068@table @code
12069@kindex show convenience
f47f77df 12070@cindex show all user variables and functions
c906108c 12071@item show convenience
f47f77df
DE
12072Print a list of convenience variables used so far, and their values,
12073as well as a list of the convenience functions.
d4f3574e 12074Abbreviated @code{show conv}.
53e5f3cf
AS
12075
12076@kindex init-if-undefined
12077@cindex convenience variables, initializing
12078@item init-if-undefined $@var{variable} = @var{expression}
12079Set a convenience variable if it has not already been set. This is useful
12080for user-defined commands that keep some state. It is similar, in concept,
12081to using local static variables with initializers in C (except that
12082convenience variables are global). It can also be used to allow users to
12083override default values used in a command script.
12084
12085If the variable is already defined then the expression is not evaluated so
12086any side-effects do not occur.
c906108c
SS
12087@end table
12088
12089One of the ways to use a convenience variable is as a counter to be
12090incremented or a pointer to be advanced. For example, to print
12091a field from successive elements of an array of structures:
12092
474c8240 12093@smallexample
c906108c
SS
12094set $i = 0
12095print bar[$i++]->contents
474c8240 12096@end smallexample
c906108c 12097
d4f3574e
SS
12098@noindent
12099Repeat that command by typing @key{RET}.
c906108c
SS
12100
12101Some convenience variables are created automatically by @value{GDBN} and given
12102values likely to be useful.
12103
12104@table @code
41afff9a 12105@vindex $_@r{, convenience variable}
c906108c
SS
12106@item $_
12107The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 12108the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
12109commands which provide a default address for @code{x} to examine also
12110set @code{$_} to that address; these commands include @code{info line}
12111and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12112except when set by the @code{x} command, in which case it is a pointer
12113to the type of @code{$__}.
12114
41afff9a 12115@vindex $__@r{, convenience variable}
c906108c
SS
12116@item $__
12117The variable @code{$__} is automatically set by the @code{x} command
12118to the value found in the last address examined. Its type is chosen
12119to match the format in which the data was printed.
12120
12121@item $_exitcode
41afff9a 12122@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
12123When the program being debugged terminates normally, @value{GDBN}
12124automatically sets this variable to the exit code of the program, and
12125resets @code{$_exitsignal} to @code{void}.
12126
12127@item $_exitsignal
12128@vindex $_exitsignal@r{, convenience variable}
12129When the program being debugged dies due to an uncaught signal,
12130@value{GDBN} automatically sets this variable to that signal's number,
12131and resets @code{$_exitcode} to @code{void}.
12132
12133To distinguish between whether the program being debugged has exited
12134(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12135@code{$_exitsignal} is not @code{void}), the convenience function
12136@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12137Functions}). For example, considering the following source code:
12138
12139@smallexample
12140#include <signal.h>
12141
12142int
12143main (int argc, char *argv[])
12144@{
12145 raise (SIGALRM);
12146 return 0;
12147@}
12148@end smallexample
12149
12150A valid way of telling whether the program being debugged has exited
12151or signalled would be:
12152
12153@smallexample
12154(@value{GDBP}) define has_exited_or_signalled
12155Type commands for definition of ``has_exited_or_signalled''.
12156End with a line saying just ``end''.
12157>if $_isvoid ($_exitsignal)
12158 >echo The program has exited\n
12159 >else
12160 >echo The program has signalled\n
12161 >end
12162>end
12163(@value{GDBP}) run
12164Starting program:
12165
12166Program terminated with signal SIGALRM, Alarm clock.
12167The program no longer exists.
12168(@value{GDBP}) has_exited_or_signalled
12169The program has signalled
12170@end smallexample
12171
12172As can be seen, @value{GDBN} correctly informs that the program being
12173debugged has signalled, since it calls @code{raise} and raises a
12174@code{SIGALRM} signal. If the program being debugged had not called
12175@code{raise}, then @value{GDBN} would report a normal exit:
12176
12177@smallexample
12178(@value{GDBP}) has_exited_or_signalled
12179The program has exited
12180@end smallexample
4aa995e1 12181
72f1fe8a
TT
12182@item $_exception
12183The variable @code{$_exception} is set to the exception object being
12184thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12185
37f6a7f4
TT
12186@item $_ada_exception
12187The variable @code{$_ada_exception} is set to the address of the
12188exception being caught or thrown at an Ada exception-related
12189catchpoint. @xref{Set Catchpoints}.
12190
62e5f89c
SDJ
12191@item $_probe_argc
12192@itemx $_probe_arg0@dots{}$_probe_arg11
12193Arguments to a static probe. @xref{Static Probe Points}.
12194
0fb4aa4b
PA
12195@item $_sdata
12196@vindex $_sdata@r{, inspect, convenience variable}
12197The variable @code{$_sdata} contains extra collected static tracepoint
12198data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12199@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12200if extra static tracepoint data has not been collected.
12201
4aa995e1
PA
12202@item $_siginfo
12203@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
12204The variable @code{$_siginfo} contains extra signal information
12205(@pxref{extra signal information}). Note that @code{$_siginfo}
12206could be empty, if the application has not yet received any signals.
12207For example, it will be empty before you execute the @code{run} command.
711e434b
PM
12208
12209@item $_tlb
12210@vindex $_tlb@r{, convenience variable}
12211The variable @code{$_tlb} is automatically set when debugging
12212applications running on MS-Windows in native mode or connected to
7734102d 12213gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
12214@xref{General Query Packets}.
12215This variable contains the address of the thread information block.
12216
e3940304 12217@item $_inferior
65c574f6
PA
12218The number of the current inferior. @xref{Inferiors Connections and
12219Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 12220
5d5658a1
PA
12221@item $_thread
12222The thread number of the current thread. @xref{thread numbers}.
12223
663f6d42
PA
12224@item $_gthread
12225The global number of the current thread. @xref{global thread numbers}.
12226
7734102d
EZ
12227@item $_gdb_major
12228@itemx $_gdb_minor
12229@vindex $_gdb_major@r{, convenience variable}
12230@vindex $_gdb_minor@r{, convenience variable}
12231The major and minor version numbers of the running @value{GDBN}.
12232Development snapshots and pretest versions have their minor version
12233incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12234the value 12 for @code{$_gdb_minor}. These variables allow you to
12235write scripts that work with different versions of @value{GDBN}
12236without errors caused by features unavailable in some of those
12237versions.
e2c52041
PW
12238
12239@item $_shell_exitcode
12240@itemx $_shell_exitsignal
12241@vindex $_shell_exitcode@r{, convenience variable}
12242@vindex $_shell_exitsignal@r{, convenience variable}
12243@cindex shell command, exit code
12244@cindex shell command, exit signal
12245@cindex exit status of shell commands
12246@value{GDBN} commands such as @code{shell} and @code{|} are launching
12247shell commands. When a launched command terminates, @value{GDBN}
12248automatically maintains the variables @code{$_shell_exitcode}
12249and @code{$_shell_exitsignal} according to the exit status of the last
12250launched command. These variables are set and used similarly to
12251the variables @code{$_exitcode} and @code{$_exitsignal}.
12252
c906108c
SS
12253@end table
12254
a72c3253
DE
12255@node Convenience Funs
12256@section Convenience Functions
12257
bc3b79fd
TJB
12258@cindex convenience functions
12259@value{GDBN} also supplies some @dfn{convenience functions}. These
12260have a syntax similar to convenience variables. A convenience
12261function can be used in an expression just like an ordinary function;
12262however, a convenience function is implemented internally to
12263@value{GDBN}.
12264
a280dbd1
SDJ
12265These functions do not require @value{GDBN} to be configured with
12266@code{Python} support, which means that they are always available.
12267
12268@table @code
12269
12270@item $_isvoid (@var{expr})
12271@findex $_isvoid@r{, convenience function}
12272Return one if the expression @var{expr} is @code{void}. Otherwise it
12273returns zero.
12274
12275A @code{void} expression is an expression where the type of the result
12276is @code{void}. For example, you can examine a convenience variable
12277(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12278it is @code{void}:
12279
12280@smallexample
12281(@value{GDBP}) print $_exitcode
12282$1 = void
12283(@value{GDBP}) print $_isvoid ($_exitcode)
12284$2 = 1
12285(@value{GDBP}) run
12286Starting program: ./a.out
12287[Inferior 1 (process 29572) exited normally]
12288(@value{GDBP}) print $_exitcode
12289$3 = 0
12290(@value{GDBP}) print $_isvoid ($_exitcode)
12291$4 = 0
12292@end smallexample
12293
12294In the example above, we used @code{$_isvoid} to check whether
12295@code{$_exitcode} is @code{void} before and after the execution of the
12296program being debugged. Before the execution there is no exit code to
12297be examined, therefore @code{$_exitcode} is @code{void}. After the
12298execution the program being debugged returned zero, therefore
12299@code{$_exitcode} is zero, which means that it is not @code{void}
12300anymore.
12301
12302The @code{void} expression can also be a call of a function from the
12303program being debugged. For example, given the following function:
12304
12305@smallexample
12306void
12307foo (void)
12308@{
12309@}
12310@end smallexample
12311
12312The result of calling it inside @value{GDBN} is @code{void}:
12313
12314@smallexample
12315(@value{GDBP}) print foo ()
12316$1 = void
12317(@value{GDBP}) print $_isvoid (foo ())
12318$2 = 1
12319(@value{GDBP}) set $v = foo ()
12320(@value{GDBP}) print $v
12321$3 = void
12322(@value{GDBP}) print $_isvoid ($v)
12323$4 = 1
12324@end smallexample
12325
aed61d02
PW
12326@item $_gdb_setting_str (@var{setting})
12327@findex $_gdb_setting_str@r{, convenience function}
12328Return the value of the @value{GDBN} @var{setting} as a string.
12329@var{setting} is any setting that can be used in a @code{set} or
12330@code{show} command (@pxref{Controlling GDB}).
12331
12332@smallexample
12333(@value{GDBP}) show print frame-arguments
12334Printing of non-scalar frame arguments is "scalars".
12335(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12336$1 = "scalars"
12337(@value{GDBP}) p $_gdb_setting_str("height")
12338$2 = "30"
12339(@value{GDBP})
12340@end smallexample
12341
12342@item $_gdb_setting (@var{setting})
12343@findex $_gdb_setting@r{, convenience function}
12344Return the value of the @value{GDBN} @var{setting}.
12345The type of the returned value depends on the setting.
12346
12347The value type for boolean and auto boolean settings is @code{int}.
12348The boolean values @code{off} and @code{on} are converted to
12349the integer values @code{0} and @code{1}. The value @code{auto} is
12350converted to the value @code{-1}.
12351
12352The value type for integer settings is either @code{unsigned int}
12353or @code{int}, depending on the setting.
12354
12355Some integer settings accept an @code{unlimited} value.
12356Depending on the setting, the @code{set} command also accepts
12357the value @code{0} or the value @code{@minus{}1} as a synonym for
12358@code{unlimited}.
12359For example, @code{set height unlimited} is equivalent to
12360@code{set height 0}.
12361
12362Some other settings that accept the @code{unlimited} value
12363use the value @code{0} to literally mean zero.
12364For example, @code{set history size 0} indicates to not
12365record any @value{GDBN} commands in the command history.
12366For such settings, @code{@minus{}1} is the synonym
12367for @code{unlimited}.
12368
12369See the documentation of the corresponding @code{set} command for
12370the numerical value equivalent to @code{unlimited}.
12371
12372The @code{$_gdb_setting} function converts the unlimited value
12373to a @code{0} or a @code{@minus{}1} value according to what the
12374@code{set} command uses.
12375
12376@smallexample
12377@group
12378(@value{GDBP}) p $_gdb_setting_str("height")
12379$1 = "30"
12380(@value{GDBP}) p $_gdb_setting("height")
12381$2 = 30
12382(@value{GDBP}) set height unlimited
12383(@value{GDBP}) p $_gdb_setting_str("height")
12384$3 = "unlimited"
12385(@value{GDBP}) p $_gdb_setting("height")
12386$4 = 0
12387@end group
12388@group
12389(@value{GDBP}) p $_gdb_setting_str("history size")
12390$5 = "unlimited"
12391(@value{GDBP}) p $_gdb_setting("history size")
12392$6 = -1
12393(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12394$7 = "auto"
12395(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12396$8 = -1
12397(@value{GDBP})
12398@end group
12399@end smallexample
12400
12401Other setting types (enum, filename, optional filename, string, string noescape)
12402are returned as string values.
12403
12404
12405@item $_gdb_maint_setting_str (@var{setting})
12406@findex $_gdb_maint_setting_str@r{, convenience function}
12407Like the @code{$_gdb_setting_str} function, but works with
12408@code{maintenance set} variables.
12409
12410@item $_gdb_maint_setting (@var{setting})
12411@findex $_gdb_maint_setting@r{, convenience function}
12412Like the @code{$_gdb_setting} function, but works with
12413@code{maintenance set} variables.
12414
a280dbd1
SDJ
12415@end table
12416
aed61d02 12417The following functions require @value{GDBN} to be configured with
a72c3253
DE
12418@code{Python} support.
12419
12420@table @code
12421
12422@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12423@findex $_memeq@r{, convenience function}
12424Returns one if the @var{length} bytes at the addresses given by
12425@var{buf1} and @var{buf2} are equal.
12426Otherwise it returns zero.
12427
12428@item $_regex(@var{str}, @var{regex})
12429@findex $_regex@r{, convenience function}
12430Returns one if the string @var{str} matches the regular expression
12431@var{regex}. Otherwise it returns zero.
12432The syntax of the regular expression is that specified by @code{Python}'s
12433regular expression support.
12434
12435@item $_streq(@var{str1}, @var{str2})
12436@findex $_streq@r{, convenience function}
12437Returns one if the strings @var{str1} and @var{str2} are equal.
12438Otherwise it returns zero.
12439
12440@item $_strlen(@var{str})
12441@findex $_strlen@r{, convenience function}
12442Returns the length of string @var{str}.
12443
faa42425
DE
12444@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12445@findex $_caller_is@r{, convenience function}
12446Returns one if the calling function's name is equal to @var{name}.
12447Otherwise it returns zero.
12448
12449If the optional argument @var{number_of_frames} is provided,
12450it is the number of frames up in the stack to look.
12451The default is 1.
12452
12453Example:
12454
12455@smallexample
12456(gdb) backtrace
12457#0 bottom_func ()
12458 at testsuite/gdb.python/py-caller-is.c:21
12459#1 0x00000000004005a0 in middle_func ()
12460 at testsuite/gdb.python/py-caller-is.c:27
12461#2 0x00000000004005ab in top_func ()
12462 at testsuite/gdb.python/py-caller-is.c:33
12463#3 0x00000000004005b6 in main ()
12464 at testsuite/gdb.python/py-caller-is.c:39
12465(gdb) print $_caller_is ("middle_func")
12466$1 = 1
12467(gdb) print $_caller_is ("top_func", 2)
12468$1 = 1
12469@end smallexample
12470
12471@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12472@findex $_caller_matches@r{, convenience function}
12473Returns one if the calling function's name matches the regular expression
12474@var{regexp}. Otherwise it returns zero.
12475
12476If the optional argument @var{number_of_frames} is provided,
12477it is the number of frames up in the stack to look.
12478The default is 1.
12479
12480@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12481@findex $_any_caller_is@r{, convenience function}
12482Returns one if any calling function's name is equal to @var{name}.
12483Otherwise it returns zero.
12484
12485If the optional argument @var{number_of_frames} is provided,
12486it is the number of frames up in the stack to look.
12487The default is 1.
12488
12489This function differs from @code{$_caller_is} in that this function
12490checks all stack frames from the immediate caller to the frame specified
12491by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12492frame specified by @var{number_of_frames}.
12493
12494@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12495@findex $_any_caller_matches@r{, convenience function}
12496Returns one if any calling function's name matches the regular expression
12497@var{regexp}. Otherwise it returns zero.
12498
12499If the optional argument @var{number_of_frames} is provided,
12500it is the number of frames up in the stack to look.
12501The default is 1.
12502
12503This function differs from @code{$_caller_matches} in that this function
12504checks all stack frames from the immediate caller to the frame specified
12505by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12506frame specified by @var{number_of_frames}.
12507
f2f3ccb9
SM
12508@item $_as_string(@var{value})
12509@findex $_as_string@r{, convenience function}
12510Return the string representation of @var{value}.
12511
12512This function is useful to obtain the textual label (enumerator) of an
12513enumeration value. For example, assuming the variable @var{node} is of
12514an enumerated type:
12515
12516@smallexample
12517(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12518Visiting node of type NODE_INTEGER
12519@end smallexample
12520
8bdc1658
AB
12521@item $_cimag(@var{value})
12522@itemx $_creal(@var{value})
12523@findex $_cimag@r{, convenience function}
12524@findex $_creal@r{, convenience function}
12525Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12526the complex number @var{value}.
12527
12528The type of the imaginary or real part depends on the type of the
12529complex number, e.g., using @code{$_cimag} on a @code{float complex}
12530will return an imaginary part of type @code{float}.
12531
a72c3253
DE
12532@end table
12533
12534@value{GDBN} provides the ability to list and get help on
12535convenience functions.
12536
bc3b79fd
TJB
12537@table @code
12538@item help function
12539@kindex help function
12540@cindex show all convenience functions
12541Print a list of all convenience functions.
12542@end table
12543
6d2ebf8b 12544@node Registers
c906108c
SS
12545@section Registers
12546
12547@cindex registers
12548You can refer to machine register contents, in expressions, as variables
12549with names starting with @samp{$}. The names of registers are different
12550for each machine; use @code{info registers} to see the names used on
12551your machine.
12552
12553@table @code
12554@kindex info registers
12555@item info registers
12556Print the names and values of all registers except floating-point
c85508ee 12557and vector registers (in the selected stack frame).
c906108c
SS
12558
12559@kindex info all-registers
12560@cindex floating point registers
12561@item info all-registers
12562Print the names and values of all registers, including floating-point
c85508ee 12563and vector registers (in the selected stack frame).
c906108c 12564
64cb3757 12565@anchor{info_registers_reggroup}
b67d92b0
SH
12566@item info registers @var{reggroup} @dots{}
12567Print the name and value of the registers in each of the specified
6b92c0d3 12568@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12569@code{maint print reggroups} (@pxref{Maintenance Commands}).
12570
c906108c
SS
12571@item info registers @var{regname} @dots{}
12572Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12573As discussed in detail below, register values are normally relative to
697aa1b7 12574the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12575the machine you are using, with or without the initial @samp{$}.
12576@end table
12577
f5b95c01 12578@anchor{standard registers}
e09f16f9
EZ
12579@cindex stack pointer register
12580@cindex program counter register
12581@cindex process status register
12582@cindex frame pointer register
12583@cindex standard registers
c906108c
SS
12584@value{GDBN} has four ``standard'' register names that are available (in
12585expressions) on most machines---whenever they do not conflict with an
12586architecture's canonical mnemonics for registers. The register names
12587@code{$pc} and @code{$sp} are used for the program counter register and
12588the stack pointer. @code{$fp} is used for a register that contains a
12589pointer to the current stack frame, and @code{$ps} is used for a
12590register that contains the processor status. For example,
12591you could print the program counter in hex with
12592
474c8240 12593@smallexample
c906108c 12594p/x $pc
474c8240 12595@end smallexample
c906108c
SS
12596
12597@noindent
12598or print the instruction to be executed next with
12599
474c8240 12600@smallexample
c906108c 12601x/i $pc
474c8240 12602@end smallexample
c906108c
SS
12603
12604@noindent
12605or add four to the stack pointer@footnote{This is a way of removing
12606one word from the stack, on machines where stacks grow downward in
12607memory (most machines, nowadays). This assumes that the innermost
12608stack frame is selected; setting @code{$sp} is not allowed when other
12609stack frames are selected. To pop entire frames off the stack,
12610regardless of machine architecture, use @code{return};
79a6e687 12611see @ref{Returning, ,Returning from a Function}.} with
c906108c 12612
474c8240 12613@smallexample
c906108c 12614set $sp += 4
474c8240 12615@end smallexample
c906108c
SS
12616
12617Whenever possible, these four standard register names are available on
12618your machine even though the machine has different canonical mnemonics,
12619so long as there is no conflict. The @code{info registers} command
12620shows the canonical names. For example, on the SPARC, @code{info
12621registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12622can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12623is an alias for the @sc{eflags} register.
c906108c
SS
12624
12625@value{GDBN} always considers the contents of an ordinary register as an
12626integer when the register is examined in this way. Some machines have
12627special registers which can hold nothing but floating point; these
12628registers are considered to have floating point values. There is no way
12629to refer to the contents of an ordinary register as floating point value
12630(although you can @emph{print} it as a floating point value with
12631@samp{print/f $@var{regname}}).
12632
12633Some registers have distinct ``raw'' and ``virtual'' data formats. This
12634means that the data format in which the register contents are saved by
12635the operating system is not the same one that your program normally
12636sees. For example, the registers of the 68881 floating point
12637coprocessor are always saved in ``extended'' (raw) format, but all C
12638programs expect to work with ``double'' (virtual) format. In such
5d161b24 12639cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12640that makes sense for your program), but the @code{info registers} command
12641prints the data in both formats.
12642
36b80e65
EZ
12643@cindex SSE registers (x86)
12644@cindex MMX registers (x86)
12645Some machines have special registers whose contents can be interpreted
12646in several different ways. For example, modern x86-based machines
12647have SSE and MMX registers that can hold several values packed
12648together in several different formats. @value{GDBN} refers to such
12649registers in @code{struct} notation:
12650
12651@smallexample
12652(@value{GDBP}) print $xmm1
12653$1 = @{
12654 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12655 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12656 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12657 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12658 v4_int32 = @{0, 20657912, 11, 13@},
12659 v2_int64 = @{88725056443645952, 55834574859@},
12660 uint128 = 0x0000000d0000000b013b36f800000000
12661@}
12662@end smallexample
12663
12664@noindent
12665To set values of such registers, you need to tell @value{GDBN} which
12666view of the register you wish to change, as if you were assigning
12667value to a @code{struct} member:
12668
12669@smallexample
12670 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12671@end smallexample
12672
c906108c 12673Normally, register values are relative to the selected stack frame
79a6e687 12674(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12675value that the register would contain if all stack frames farther in
12676were exited and their saved registers restored. In order to see the
12677true contents of hardware registers, you must select the innermost
12678frame (with @samp{frame 0}).
12679
901461f8
PA
12680@cindex caller-saved registers
12681@cindex call-clobbered registers
12682@cindex volatile registers
12683@cindex <not saved> values
12684Usually ABIs reserve some registers as not needed to be saved by the
12685callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12686registers). It may therefore not be possible for @value{GDBN} to know
12687the value a register had before the call (in other words, in the outer
12688frame), if the register value has since been changed by the callee.
12689@value{GDBN} tries to deduce where the inner frame saved
12690(``callee-saved'') registers, from the debug info, unwind info, or the
12691machine code generated by your compiler. If some register is not
12692saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12693its own knowledge of the ABI, or because the debug/unwind info
12694explicitly says the register's value is undefined), @value{GDBN}
12695displays @w{@samp{<not saved>}} as the register's value. With targets
12696that @value{GDBN} has no knowledge of the register saving convention,
12697if a register was not saved by the callee, then its value and location
12698in the outer frame are assumed to be the same of the inner frame.
12699This is usually harmless, because if the register is call-clobbered,
12700the caller either does not care what is in the register after the
12701call, or has code to restore the value that it does care about. Note,
12702however, that if you change such a register in the outer frame, you
12703may also be affecting the inner frame. Also, the more ``outer'' the
12704frame is you're looking at, the more likely a call-clobbered
12705register's value is to be wrong, in the sense that it doesn't actually
12706represent the value the register had just before the call.
c906108c 12707
6d2ebf8b 12708@node Floating Point Hardware
79a6e687 12709@section Floating Point Hardware
c906108c
SS
12710@cindex floating point
12711
12712Depending on the configuration, @value{GDBN} may be able to give
12713you more information about the status of the floating point hardware.
12714
12715@table @code
12716@kindex info float
12717@item info float
12718Display hardware-dependent information about the floating
12719point unit. The exact contents and layout vary depending on the
12720floating point chip. Currently, @samp{info float} is supported on
12721the ARM and x86 machines.
12722@end table
c906108c 12723
e76f1f2e
AC
12724@node Vector Unit
12725@section Vector Unit
12726@cindex vector unit
12727
12728Depending on the configuration, @value{GDBN} may be able to give you
12729more information about the status of the vector unit.
12730
12731@table @code
12732@kindex info vector
12733@item info vector
12734Display information about the vector unit. The exact contents and
12735layout vary depending on the hardware.
12736@end table
12737
721c2651 12738@node OS Information
79a6e687 12739@section Operating System Auxiliary Information
721c2651
EZ
12740@cindex OS information
12741
12742@value{GDBN} provides interfaces to useful OS facilities that can help
12743you debug your program.
12744
b383017d
RM
12745@cindex auxiliary vector
12746@cindex vector, auxiliary
b383017d
RM
12747Some operating systems supply an @dfn{auxiliary vector} to programs at
12748startup. This is akin to the arguments and environment that you
12749specify for a program, but contains a system-dependent variety of
12750binary values that tell system libraries important details about the
12751hardware, operating system, and process. Each value's purpose is
12752identified by an integer tag; the meanings are well-known but system-specific.
12753Depending on the configuration and operating system facilities,
9c16f35a
EZ
12754@value{GDBN} may be able to show you this information. For remote
12755targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12756support of the @samp{qXfer:auxv:read} packet, see
12757@ref{qXfer auxiliary vector read}.
b383017d
RM
12758
12759@table @code
12760@kindex info auxv
12761@item info auxv
12762Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12763live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12764numerically, and also shows names and text descriptions for recognized
12765tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12766pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12767most appropriate form for a recognized tag, and in hexadecimal for
12768an unrecognized tag.
12769@end table
12770
85d4a676
SS
12771On some targets, @value{GDBN} can access operating system-specific
12772information and show it to you. The types of information available
12773will differ depending on the type of operating system running on the
12774target. The mechanism used to fetch the data is described in
12775@ref{Operating System Information}. For remote targets, this
12776functionality depends on the remote stub's support of the
07e059b5
VP
12777@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12778
12779@table @code
a61408f8 12780@kindex info os
85d4a676
SS
12781@item info os @var{infotype}
12782
12783Display OS information of the requested type.
a61408f8 12784
85d4a676
SS
12785On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12786
12787@anchor{linux info os infotypes}
12788@table @code
d33279b3
AT
12789@kindex info os cpus
12790@item cpus
12791Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12792the available fields from /proc/cpuinfo. For each supported architecture
12793different fields are available. Two common entries are processor which gives
12794CPU number and bogomips; a system constant that is calculated during
12795kernel initialization.
12796
12797@kindex info os files
12798@item files
12799Display the list of open file descriptors on the target. For each
12800file descriptor, @value{GDBN} prints the identifier of the process
12801owning the descriptor, the command of the owning process, the value
12802of the descriptor, and the target of the descriptor.
12803
12804@kindex info os modules
12805@item modules
12806Display the list of all loaded kernel modules on the target. For each
12807module, @value{GDBN} prints the module name, the size of the module in
12808bytes, the number of times the module is used, the dependencies of the
12809module, the status of the module, and the address of the loaded module
12810in memory.
12811
12812@kindex info os msg
12813@item msg
12814Display the list of all System V message queues on the target. For each
12815message queue, @value{GDBN} prints the message queue key, the message
12816queue identifier, the access permissions, the current number of bytes
12817on the queue, the current number of messages on the queue, the processes
12818that last sent and received a message on the queue, the user and group
12819of the owner and creator of the message queue, the times at which a
12820message was last sent and received on the queue, and the time at which
12821the message queue was last changed.
12822
07e059b5 12823@kindex info os processes
85d4a676 12824@item processes
07e059b5 12825Display the list of processes on the target. For each process,
85d4a676
SS
12826@value{GDBN} prints the process identifier, the name of the user, the
12827command corresponding to the process, and the list of processor cores
12828that the process is currently running on. (To understand what these
12829properties mean, for this and the following info types, please consult
12830the general @sc{gnu}/Linux documentation.)
12831
12832@kindex info os procgroups
12833@item procgroups
12834Display the list of process groups on the target. For each process,
12835@value{GDBN} prints the identifier of the process group that it belongs
12836to, the command corresponding to the process group leader, the process
12837identifier, and the command line of the process. The list is sorted
12838first by the process group identifier, then by the process identifier,
12839so that processes belonging to the same process group are grouped together
12840and the process group leader is listed first.
12841
d33279b3
AT
12842@kindex info os semaphores
12843@item semaphores
12844Display the list of all System V semaphore sets on the target. For each
12845semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12846set identifier, the access permissions, the number of semaphores in the
12847set, the user and group of the owner and creator of the semaphore set,
12848and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12849
12850@kindex info os shm
12851@item shm
12852Display the list of all System V shared-memory regions on the target.
12853For each shared-memory region, @value{GDBN} prints the region key,
12854the shared-memory identifier, the access permissions, the size of the
12855region, the process that created the region, the process that last
12856attached to or detached from the region, the current number of live
12857attaches to the region, and the times at which the region was last
12858attached to, detach from, and changed.
12859
d33279b3
AT
12860@kindex info os sockets
12861@item sockets
12862Display the list of Internet-domain sockets on the target. For each
12863socket, @value{GDBN} prints the address and port of the local and
12864remote endpoints, the current state of the connection, the creator of
12865the socket, the IP address family of the socket, and the type of the
12866connection.
85d4a676 12867
d33279b3
AT
12868@kindex info os threads
12869@item threads
12870Display the list of threads running on the target. For each thread,
12871@value{GDBN} prints the identifier of the process that the thread
12872belongs to, the command of the process, the thread identifier, and the
12873processor core that it is currently running on. The main thread of a
12874process is not listed.
85d4a676
SS
12875@end table
12876
12877@item info os
12878If @var{infotype} is omitted, then list the possible values for
12879@var{infotype} and the kind of OS information available for each
12880@var{infotype}. If the target does not return a list of possible
12881types, this command will report an error.
07e059b5 12882@end table
721c2651 12883
29e57380 12884@node Memory Region Attributes
79a6e687 12885@section Memory Region Attributes
29e57380
C
12886@cindex memory region attributes
12887
b383017d 12888@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12889required by regions of your target's memory. @value{GDBN} uses
12890attributes to determine whether to allow certain types of memory
12891accesses; whether to use specific width accesses; and whether to cache
12892target memory. By default the description of memory regions is
12893fetched from the target (if the current target supports this), but the
12894user can override the fetched regions.
29e57380
C
12895
12896Defined memory regions can be individually enabled and disabled. When a
12897memory region is disabled, @value{GDBN} uses the default attributes when
12898accessing memory in that region. Similarly, if no memory regions have
12899been defined, @value{GDBN} uses the default attributes when accessing
12900all memory.
12901
b383017d 12902When a memory region is defined, it is given a number to identify it;
29e57380
C
12903to enable, disable, or remove a memory region, you specify that number.
12904
12905@table @code
12906@kindex mem
bfac230e 12907@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12908Define a memory region bounded by @var{lower} and @var{upper} with
12909attributes @var{attributes}@dots{}, and add it to the list of regions
12910monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12911case: it is treated as the target's maximum memory address.
bfac230e 12912(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12913
fd79ecee
DJ
12914@item mem auto
12915Discard any user changes to the memory regions and use target-supplied
12916regions, if available, or no regions if the target does not support.
12917
29e57380
C
12918@kindex delete mem
12919@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12920Remove memory regions @var{nums}@dots{} from the list of regions
12921monitored by @value{GDBN}.
29e57380
C
12922
12923@kindex disable mem
12924@item disable mem @var{nums}@dots{}
09d4efe1 12925Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12926A disabled memory region is not forgotten.
29e57380
C
12927It may be enabled again later.
12928
12929@kindex enable mem
12930@item enable mem @var{nums}@dots{}
09d4efe1 12931Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12932
12933@kindex info mem
12934@item info mem
12935Print a table of all defined memory regions, with the following columns
09d4efe1 12936for each region:
29e57380
C
12937
12938@table @emph
12939@item Memory Region Number
12940@item Enabled or Disabled.
b383017d 12941Enabled memory regions are marked with @samp{y}.
29e57380
C
12942Disabled memory regions are marked with @samp{n}.
12943
12944@item Lo Address
12945The address defining the inclusive lower bound of the memory region.
12946
12947@item Hi Address
12948The address defining the exclusive upper bound of the memory region.
12949
12950@item Attributes
12951The list of attributes set for this memory region.
12952@end table
12953@end table
12954
12955
12956@subsection Attributes
12957
b383017d 12958@subsubsection Memory Access Mode
29e57380
C
12959The access mode attributes set whether @value{GDBN} may make read or
12960write accesses to a memory region.
12961
12962While these attributes prevent @value{GDBN} from performing invalid
12963memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12964etc.@: from accessing memory.
29e57380
C
12965
12966@table @code
12967@item ro
12968Memory is read only.
12969@item wo
12970Memory is write only.
12971@item rw
6ca652b0 12972Memory is read/write. This is the default.
29e57380
C
12973@end table
12974
12975@subsubsection Memory Access Size
d3e8051b 12976The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12977accesses in the memory region. Often memory mapped device registers
12978require specific sized accesses. If no access size attribute is
12979specified, @value{GDBN} may use accesses of any size.
12980
12981@table @code
12982@item 8
12983Use 8 bit memory accesses.
12984@item 16
12985Use 16 bit memory accesses.
12986@item 32
12987Use 32 bit memory accesses.
12988@item 64
12989Use 64 bit memory accesses.
12990@end table
12991
12992@c @subsubsection Hardware/Software Breakpoints
12993@c The hardware/software breakpoint attributes set whether @value{GDBN}
12994@c will use hardware or software breakpoints for the internal breakpoints
12995@c used by the step, next, finish, until, etc. commands.
12996@c
12997@c @table @code
12998@c @item hwbreak
b383017d 12999@c Always use hardware breakpoints
29e57380
C
13000@c @item swbreak (default)
13001@c @end table
13002
13003@subsubsection Data Cache
13004The data cache attributes set whether @value{GDBN} will cache target
13005memory. While this generally improves performance by reducing debug
13006protocol overhead, it can lead to incorrect results because @value{GDBN}
13007does not know about volatile variables or memory mapped device
13008registers.
13009
13010@table @code
13011@item cache
b383017d 13012Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
13013@item nocache
13014Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
13015@end table
13016
4b5752d0
VP
13017@subsection Memory Access Checking
13018@value{GDBN} can be instructed to refuse accesses to memory that is
13019not explicitly described. This can be useful if accessing such
13020regions has undesired effects for a specific target, or to provide
13021better error checking. The following commands control this behaviour.
13022
13023@table @code
13024@kindex set mem inaccessible-by-default
13025@item set mem inaccessible-by-default [on|off]
13026If @code{on} is specified, make @value{GDBN} treat memory not
13027explicitly described by the memory ranges as non-existent and refuse accesses
13028to such memory. The checks are only performed if there's at least one
13029memory range defined. If @code{off} is specified, make @value{GDBN}
13030treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 13031The default value is @code{on}.
4b5752d0
VP
13032@kindex show mem inaccessible-by-default
13033@item show mem inaccessible-by-default
13034Show the current handling of accesses to unknown memory.
13035@end table
13036
13037
29e57380 13038@c @subsubsection Memory Write Verification
b383017d 13039@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
13040@c will re-reads data after each write to verify the write was successful.
13041@c
13042@c @table @code
13043@c @item verify
13044@c @item noverify (default)
13045@c @end table
13046
16d9dec6 13047@node Dump/Restore Files
79a6e687 13048@section Copy Between Memory and a File
16d9dec6
MS
13049@cindex dump/restore files
13050@cindex append data to a file
13051@cindex dump data to a file
13052@cindex restore data from a file
16d9dec6 13053
df5215a6
JB
13054You can use the commands @code{dump}, @code{append}, and
13055@code{restore} to copy data between target memory and a file. The
13056@code{dump} and @code{append} commands write data to a file, and the
13057@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
13058memory. Files may be in binary, Motorola S-record, Intel hex,
13059Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13060append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
13061
13062@table @code
13063
13064@kindex dump
13065@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13066@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13067Dump the contents of memory from @var{start_addr} to @var{end_addr},
13068or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 13069
df5215a6 13070The @var{format} parameter may be any one of:
16d9dec6 13071@table @code
df5215a6
JB
13072@item binary
13073Raw binary form.
13074@item ihex
13075Intel hex format.
13076@item srec
13077Motorola S-record format.
13078@item tekhex
13079Tektronix Hex format.
cf75d6c3
AB
13080@item verilog
13081Verilog Hex format.
df5215a6
JB
13082@end table
13083
13084@value{GDBN} uses the same definitions of these formats as the
13085@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13086@var{format} is omitted, @value{GDBN} dumps the data in raw binary
13087form.
13088
13089@kindex append
13090@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13091@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13092Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 13093or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
13094(@value{GDBN} can only append data to files in raw binary form.)
13095
13096@kindex restore
13097@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13098Restore the contents of file @var{filename} into memory. The
13099@code{restore} command can automatically recognize any known @sc{bfd}
13100file format, except for raw binary. To restore a raw binary file you
13101must specify the optional keyword @code{binary} after the filename.
16d9dec6 13102
b383017d 13103If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
13104contained in the file. Binary files always start at address zero, so
13105they will be restored at address @var{bias}. Other bfd files have
13106a built-in location; they will be restored at offset @var{bias}
13107from that location.
13108
13109If @var{start} and/or @var{end} are non-zero, then only data between
13110file offset @var{start} and file offset @var{end} will be restored.
b383017d 13111These offsets are relative to the addresses in the file, before
16d9dec6
MS
13112the @var{bias} argument is applied.
13113
13114@end table
13115
384ee23f
EZ
13116@node Core File Generation
13117@section How to Produce a Core File from Your Program
13118@cindex dump core from inferior
13119
13120A @dfn{core file} or @dfn{core dump} is a file that records the memory
13121image of a running process and its process status (register values
13122etc.). Its primary use is post-mortem debugging of a program that
13123crashed while it ran outside a debugger. A program that crashes
13124automatically produces a core file, unless this feature is disabled by
13125the user. @xref{Files}, for information on invoking @value{GDBN} in
13126the post-mortem debugging mode.
13127
13128Occasionally, you may wish to produce a core file of the program you
13129are debugging in order to preserve a snapshot of its state.
13130@value{GDBN} has a special command for that.
13131
13132@table @code
13133@kindex gcore
13134@kindex generate-core-file
13135@item generate-core-file [@var{file}]
13136@itemx gcore [@var{file}]
13137Produce a core dump of the inferior process. The optional argument
13138@var{file} specifies the file name where to put the core dump. If not
13139specified, the file name defaults to @file{core.@var{pid}}, where
13140@var{pid} is the inferior process ID.
13141
13142Note that this command is implemented only for some systems (as of
05b4bd79 13143this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
13144
13145On @sc{gnu}/Linux, this command can take into account the value of the
13146file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
13147dump (@pxref{set use-coredump-filter}), and by default honors the
13148@code{VM_DONTDUMP} flag for mappings where it is present in the file
13149@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
13150
13151@kindex set use-coredump-filter
13152@anchor{set use-coredump-filter}
13153@item set use-coredump-filter on
13154@itemx set use-coredump-filter off
13155Enable or disable the use of the file
13156@file{/proc/@var{pid}/coredump_filter} when generating core dump
13157files. This file is used by the Linux kernel to decide what types of
13158memory mappings will be dumped or ignored when generating a core dump
13159file. @var{pid} is the process ID of a currently running process.
13160
13161To make use of this feature, you have to write in the
13162@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13163which is a bit mask representing the memory mapping types. If a bit
13164is set in the bit mask, then the memory mappings of the corresponding
13165types will be dumped; otherwise, they will be ignored. This
13166configuration is inherited by child processes. For more information
13167about the bits that can be set in the
13168@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13169manpage of @code{core(5)}.
13170
13171By default, this option is @code{on}. If this option is turned
13172@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13173and instead uses the same default value as the Linux kernel in order
13174to decide which pages will be dumped in the core dump file. This
13175value is currently @code{0x33}, which means that bits @code{0}
13176(anonymous private mappings), @code{1} (anonymous shared mappings),
13177@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13178This will cause these memory mappings to be dumped automatically.
1e52e849
SL
13179
13180@kindex set dump-excluded-mappings
13181@anchor{set dump-excluded-mappings}
13182@item set dump-excluded-mappings on
13183@itemx set dump-excluded-mappings off
13184If @code{on} is specified, @value{GDBN} will dump memory mappings
13185marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13186the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13187
13188The default value is @code{off}.
384ee23f
EZ
13189@end table
13190
a0eb71c5
KB
13191@node Character Sets
13192@section Character Sets
13193@cindex character sets
13194@cindex charset
13195@cindex translating between character sets
13196@cindex host character set
13197@cindex target character set
13198
13199If the program you are debugging uses a different character set to
13200represent characters and strings than the one @value{GDBN} uses itself,
13201@value{GDBN} can automatically translate between the character sets for
13202you. The character set @value{GDBN} uses we call the @dfn{host
13203character set}; the one the inferior program uses we call the
13204@dfn{target character set}.
13205
13206For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13207uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 13208remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
13209running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13210then the host character set is Latin-1, and the target character set is
13211@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 13212target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
13213@sc{ebcdic} and Latin 1 as you print character or string values, or use
13214character and string literals in expressions.
13215
13216@value{GDBN} has no way to automatically recognize which character set
13217the inferior program uses; you must tell it, using the @code{set
13218target-charset} command, described below.
13219
13220Here are the commands for controlling @value{GDBN}'s character set
13221support:
13222
13223@table @code
13224@item set target-charset @var{charset}
13225@kindex set target-charset
10af6951
EZ
13226Set the current target character set to @var{charset}. To display the
13227list of supported target character sets, type
13228@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 13229
a0eb71c5
KB
13230@item set host-charset @var{charset}
13231@kindex set host-charset
13232Set the current host character set to @var{charset}.
13233
13234By default, @value{GDBN} uses a host character set appropriate to the
13235system it is running on; you can override that default using the
732f6a93
TT
13236@code{set host-charset} command. On some systems, @value{GDBN} cannot
13237automatically determine the appropriate host character set. In this
13238case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
13239
13240@value{GDBN} can only use certain character sets as its host character
c1b6b909 13241set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 13242@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
13243
13244@item set charset @var{charset}
13245@kindex set charset
e33d66ec 13246Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13247above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13248@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13249for both host and target.
13250
a0eb71c5 13251@item show charset
a0eb71c5 13252@kindex show charset
10af6951 13253Show the names of the current host and target character sets.
e33d66ec 13254
10af6951 13255@item show host-charset
a0eb71c5 13256@kindex show host-charset
10af6951 13257Show the name of the current host character set.
e33d66ec 13258
10af6951 13259@item show target-charset
a0eb71c5 13260@kindex show target-charset
10af6951 13261Show the name of the current target character set.
a0eb71c5 13262
10af6951
EZ
13263@item set target-wide-charset @var{charset}
13264@kindex set target-wide-charset
13265Set the current target's wide character set to @var{charset}. This is
13266the character set used by the target's @code{wchar_t} type. To
13267display the list of supported wide character sets, type
13268@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13269
13270@item show target-wide-charset
13271@kindex show target-wide-charset
13272Show the name of the current target's wide character set.
a0eb71c5
KB
13273@end table
13274
a0eb71c5
KB
13275Here is an example of @value{GDBN}'s character set support in action.
13276Assume that the following source code has been placed in the file
13277@file{charset-test.c}:
13278
13279@smallexample
13280#include <stdio.h>
13281
13282char ascii_hello[]
13283 = @{72, 101, 108, 108, 111, 44, 32, 119,
13284 111, 114, 108, 100, 33, 10, 0@};
13285char ibm1047_hello[]
13286 = @{200, 133, 147, 147, 150, 107, 64, 166,
13287 150, 153, 147, 132, 90, 37, 0@};
13288
13289main ()
13290@{
13291 printf ("Hello, world!\n");
13292@}
10998722 13293@end smallexample
a0eb71c5
KB
13294
13295In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13296containing the string @samp{Hello, world!} followed by a newline,
13297encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13298
13299We compile the program, and invoke the debugger on it:
13300
13301@smallexample
13302$ gcc -g charset-test.c -o charset-test
13303$ gdb -nw charset-test
13304GNU gdb 2001-12-19-cvs
13305Copyright 2001 Free Software Foundation, Inc.
13306@dots{}
f7dc1244 13307(@value{GDBP})
10998722 13308@end smallexample
a0eb71c5
KB
13309
13310We can use the @code{show charset} command to see what character sets
13311@value{GDBN} is currently using to interpret and display characters and
13312strings:
13313
13314@smallexample
f7dc1244 13315(@value{GDBP}) show charset
e33d66ec 13316The current host and target character set is `ISO-8859-1'.
f7dc1244 13317(@value{GDBP})
10998722 13318@end smallexample
a0eb71c5
KB
13319
13320For the sake of printing this manual, let's use @sc{ascii} as our
13321initial character set:
13322@smallexample
f7dc1244
EZ
13323(@value{GDBP}) set charset ASCII
13324(@value{GDBP}) show charset
e33d66ec 13325The current host and target character set is `ASCII'.
f7dc1244 13326(@value{GDBP})
10998722 13327@end smallexample
a0eb71c5
KB
13328
13329Let's assume that @sc{ascii} is indeed the correct character set for our
13330host system --- in other words, let's assume that if @value{GDBN} prints
13331characters using the @sc{ascii} character set, our terminal will display
13332them properly. Since our current target character set is also
13333@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13334
13335@smallexample
f7dc1244 13336(@value{GDBP}) print ascii_hello
a0eb71c5 13337$1 = 0x401698 "Hello, world!\n"
f7dc1244 13338(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13339$2 = 72 'H'
f7dc1244 13340(@value{GDBP})
10998722 13341@end smallexample
a0eb71c5
KB
13342
13343@value{GDBN} uses the target character set for character and string
13344literals you use in expressions:
13345
13346@smallexample
f7dc1244 13347(@value{GDBP}) print '+'
a0eb71c5 13348$3 = 43 '+'
f7dc1244 13349(@value{GDBP})
10998722 13350@end smallexample
a0eb71c5
KB
13351
13352The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13353character.
13354
13355@value{GDBN} relies on the user to tell it which character set the
13356target program uses. If we print @code{ibm1047_hello} while our target
13357character set is still @sc{ascii}, we get jibberish:
13358
13359@smallexample
f7dc1244 13360(@value{GDBP}) print ibm1047_hello
a0eb71c5 13361$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13362(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13363$5 = 200 '\310'
f7dc1244 13364(@value{GDBP})
10998722 13365@end smallexample
a0eb71c5 13366
e33d66ec 13367If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13368@value{GDBN} tells us the character sets it supports:
13369
13370@smallexample
f7dc1244 13371(@value{GDBP}) set target-charset
b383017d 13372ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13373(@value{GDBP}) set target-charset
10998722 13374@end smallexample
a0eb71c5
KB
13375
13376We can select @sc{ibm1047} as our target character set, and examine the
13377program's strings again. Now the @sc{ascii} string is wrong, but
13378@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13379target character set, @sc{ibm1047}, to the host character set,
13380@sc{ascii}, and they display correctly:
13381
13382@smallexample
f7dc1244
EZ
13383(@value{GDBP}) set target-charset IBM1047
13384(@value{GDBP}) show charset
e33d66ec
EZ
13385The current host character set is `ASCII'.
13386The current target character set is `IBM1047'.
f7dc1244 13387(@value{GDBP}) print ascii_hello
a0eb71c5 13388$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13389(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13390$7 = 72 '\110'
f7dc1244 13391(@value{GDBP}) print ibm1047_hello
a0eb71c5 13392$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13393(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13394$9 = 200 'H'
f7dc1244 13395(@value{GDBP})
10998722 13396@end smallexample
a0eb71c5
KB
13397
13398As above, @value{GDBN} uses the target character set for character and
13399string literals you use in expressions:
13400
13401@smallexample
f7dc1244 13402(@value{GDBP}) print '+'
a0eb71c5 13403$10 = 78 '+'
f7dc1244 13404(@value{GDBP})
10998722 13405@end smallexample
a0eb71c5 13406
e33d66ec 13407The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13408character.
13409
b12039c6
YQ
13410@node Caching Target Data
13411@section Caching Data of Targets
13412@cindex caching data of targets
13413
13414@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13415Each cache is associated with the address space of the inferior.
65c574f6 13416@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13417Such caching generally improves performance in remote debugging
13418(@pxref{Remote Debugging}), because it reduces the overhead of the
13419remote protocol by bundling memory reads and writes into large chunks.
13420Unfortunately, simply caching everything would lead to incorrect results,
13421since @value{GDBN} does not necessarily know anything about volatile
13422values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13423(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13424is executing.
29b090c0
DE
13425Therefore, by default, @value{GDBN} only caches data
13426known to be on the stack@footnote{In non-stop mode, it is moderately
13427rare for a running thread to modify the stack of a stopped thread
13428in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13429stack reads provides a significant speed up of remote backtraces.} or
13430in the code segment.
29b090c0 13431Other regions of memory can be explicitly marked as
27b81af3 13432cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13433
13434@table @code
13435@kindex set remotecache
13436@item set remotecache on
13437@itemx set remotecache off
4e5d721f
DE
13438This option no longer does anything; it exists for compatibility
13439with old scripts.
09d4efe1
EZ
13440
13441@kindex show remotecache
13442@item show remotecache
4e5d721f
DE
13443Show the current state of the obsolete remotecache flag.
13444
13445@kindex set stack-cache
13446@item set stack-cache on
13447@itemx set stack-cache off
6dd315ba
YQ
13448Enable or disable caching of stack accesses. When @code{on}, use
13449caching. By default, this option is @code{on}.
4e5d721f
DE
13450
13451@kindex show stack-cache
13452@item show stack-cache
13453Show the current state of data caching for memory accesses.
09d4efe1 13454
29453a14
YQ
13455@kindex set code-cache
13456@item set code-cache on
13457@itemx set code-cache off
13458Enable or disable caching of code segment accesses. When @code{on},
13459use caching. By default, this option is @code{on}. This improves
13460performance of disassembly in remote debugging.
13461
13462@kindex show code-cache
13463@item show code-cache
13464Show the current state of target memory cache for code segment
13465accesses.
13466
09d4efe1 13467@kindex info dcache
4e5d721f 13468@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13469Print the information about the performance of data cache of the
13470current inferior's address space. The information displayed
13471includes the dcache width and depth, and for each cache line, its
13472number, address, and how many times it was referenced. This
13473command is useful for debugging the data cache operation.
4e5d721f
DE
13474
13475If a line number is specified, the contents of that line will be
13476printed in hex.
1a532630
PP
13477
13478@item set dcache size @var{size}
13479@cindex dcache size
13480@kindex set dcache size
13481Set maximum number of entries in dcache (dcache depth above).
13482
13483@item set dcache line-size @var{line-size}
13484@cindex dcache line-size
13485@kindex set dcache line-size
13486Set number of bytes each dcache entry caches (dcache width above).
13487Must be a power of 2.
13488
13489@item show dcache size
13490@kindex show dcache size
b12039c6 13491Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13492
13493@item show dcache line-size
13494@kindex show dcache line-size
b12039c6 13495Show default size of dcache lines.
1a532630 13496
ee9812a0
AB
13497@item maint flush dcache
13498@cindex dcache, flushing
13499@kindex maint flush dcache
13500Flush the contents (if any) of the dcache. This maintainer command is
13501useful when debugging the dcache implementation.
13502
09d4efe1
EZ
13503@end table
13504
08388c79
DE
13505@node Searching Memory
13506@section Search Memory
13507@cindex searching memory
13508
13509Memory can be searched for a particular sequence of bytes with the
13510@code{find} command.
13511
13512@table @code
13513@kindex find
13514@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13515@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13516Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13517etc. The search begins at address @var{start_addr} and continues for either
13518@var{len} bytes or through to @var{end_addr} inclusive.
13519@end table
13520
13521@var{s} and @var{n} are optional parameters.
13522They may be specified in either order, apart or together.
13523
13524@table @r
13525@item @var{s}, search query size
13526The size of each search query value.
13527
13528@table @code
13529@item b
13530bytes
13531@item h
13532halfwords (two bytes)
13533@item w
13534words (four bytes)
13535@item g
13536giant words (eight bytes)
13537@end table
13538
13539All values are interpreted in the current language.
13540This means, for example, that if the current source language is C/C@t{++}
13541then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13542The null terminator can be removed from searching by using casts,
13543e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13544
13545If the value size is not specified, it is taken from the
13546value's type in the current language.
13547This is useful when one wants to specify the search
13548pattern as a mixture of types.
13549Note that this means, for example, that in the case of C-like languages
13550a search for an untyped 0x42 will search for @samp{(int) 0x42}
13551which is typically four bytes.
13552
13553@item @var{n}, maximum number of finds
13554The maximum number of matches to print. The default is to print all finds.
13555@end table
13556
13557You can use strings as search values. Quote them with double-quotes
13558 (@code{"}).
13559The string value is copied into the search pattern byte by byte,
13560regardless of the endianness of the target and the size specification.
13561
13562The address of each match found is printed as well as a count of the
13563number of matches found.
13564
13565The address of the last value found is stored in convenience variable
13566@samp{$_}.
13567A count of the number of matches is stored in @samp{$numfound}.
13568
13569For example, if stopped at the @code{printf} in this function:
13570
13571@smallexample
13572void
13573hello ()
13574@{
13575 static char hello[] = "hello-hello";
13576 static struct @{ char c; short s; int i; @}
13577 __attribute__ ((packed)) mixed
13578 = @{ 'c', 0x1234, 0x87654321 @};
13579 printf ("%s\n", hello);
13580@}
13581@end smallexample
13582
13583@noindent
13584you get during debugging:
13585
13586@smallexample
13587(gdb) find &hello[0], +sizeof(hello), "hello"
135880x804956d <hello.1620+6>
135891 pattern found
13590(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
135910x8049567 <hello.1620>
135920x804956d <hello.1620+6>
ee9a09e9
DC
135932 patterns found.
13594(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
135950x8049567 <hello.1620>
135960x804956d <hello.1620+6>
135972 patterns found.
08388c79
DE
13598(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
135990x8049567 <hello.1620>
136001 pattern found
13601(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
136020x8049560 <mixed.1625>
136031 pattern found
13604(gdb) print $numfound
13605$1 = 1
13606(gdb) print $_
13607$2 = (void *) 0x8049560
13608@end smallexample
a0eb71c5 13609
5fdf6324
AB
13610@node Value Sizes
13611@section Value Sizes
13612
13613Whenever @value{GDBN} prints a value memory will be allocated within
13614@value{GDBN} to hold the contents of the value. It is possible in
13615some languages with dynamic typing systems, that an invalid program
13616may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13617@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13618
13619@table @code
13620@kindex set max-value-size
713cdcbf 13621@item set max-value-size @var{bytes}
5fdf6324
AB
13622@itemx set max-value-size unlimited
13623Set the maximum size of memory that @value{GDBN} will allocate for the
13624contents of a value to @var{bytes}, trying to display a value that
13625requires more memory than that will result in an error.
13626
13627Setting this variable does not effect values that have already been
13628allocated within @value{GDBN}, only future allocations.
13629
13630There's a minimum size that @code{max-value-size} can be set to in
13631order that @value{GDBN} can still operate correctly, this minimum is
13632currently 16 bytes.
13633
13634The limit applies to the results of some subexpressions as well as to
13635complete expressions. For example, an expression denoting a simple
13636integer component, such as @code{x.y.z}, may fail if the size of
13637@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13638@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13639@var{A} is an array variable with non-constant size, will generally
13640succeed regardless of the bounds on @var{A}, as long as the component
13641size is less than @var{bytes}.
13642
13643The default value of @code{max-value-size} is currently 64k.
13644
13645@kindex show max-value-size
13646@item show max-value-size
13647Show the maximum size of memory, in bytes, that @value{GDBN} will
13648allocate for the contents of a value.
13649@end table
13650
edb3359d
DJ
13651@node Optimized Code
13652@chapter Debugging Optimized Code
13653@cindex optimized code, debugging
13654@cindex debugging optimized code
13655
13656Almost all compilers support optimization. With optimization
13657disabled, the compiler generates assembly code that corresponds
13658directly to your source code, in a simplistic way. As the compiler
13659applies more powerful optimizations, the generated assembly code
13660diverges from your original source code. With help from debugging
13661information generated by the compiler, @value{GDBN} can map from
13662the running program back to constructs from your original source.
13663
13664@value{GDBN} is more accurate with optimization disabled. If you
13665can recompile without optimization, it is easier to follow the
13666progress of your program during debugging. But, there are many cases
13667where you may need to debug an optimized version.
13668
13669When you debug a program compiled with @samp{-g -O}, remember that the
13670optimizer has rearranged your code; the debugger shows you what is
13671really there. Do not be too surprised when the execution path does not
13672exactly match your source file! An extreme example: if you define a
13673variable, but never use it, @value{GDBN} never sees that
13674variable---because the compiler optimizes it out of existence.
13675
13676Some things do not work as well with @samp{-g -O} as with just
13677@samp{-g}, particularly on machines with instruction scheduling. If in
13678doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13679please report it to us as a bug (including a test case!).
13680@xref{Variables}, for more information about debugging optimized code.
13681
13682@menu
13683* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13684* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13685@end menu
13686
13687@node Inline Functions
13688@section Inline Functions
13689@cindex inline functions, debugging
13690
13691@dfn{Inlining} is an optimization that inserts a copy of the function
13692body directly at each call site, instead of jumping to a shared
13693routine. @value{GDBN} displays inlined functions just like
13694non-inlined functions. They appear in backtraces. You can view their
13695arguments and local variables, step into them with @code{step}, skip
13696them with @code{next}, and escape from them with @code{finish}.
13697You can check whether a function was inlined by using the
13698@code{info frame} command.
13699
13700For @value{GDBN} to support inlined functions, the compiler must
13701record information about inlining in the debug information ---
13702@value{NGCC} using the @sc{dwarf 2} format does this, and several
13703other compilers do also. @value{GDBN} only supports inlined functions
13704when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13705do not emit two required attributes (@samp{DW_AT_call_file} and
13706@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13707function calls with earlier versions of @value{NGCC}. It instead
13708displays the arguments and local variables of inlined functions as
13709local variables in the caller.
13710
13711The body of an inlined function is directly included at its call site;
13712unlike a non-inlined function, there are no instructions devoted to
13713the call. @value{GDBN} still pretends that the call site and the
13714start of the inlined function are different instructions. Stepping to
13715the call site shows the call site, and then stepping again shows
13716the first line of the inlined function, even though no additional
13717instructions are executed.
13718
13719This makes source-level debugging much clearer; you can see both the
13720context of the call and then the effect of the call. Only stepping by
13721a single instruction using @code{stepi} or @code{nexti} does not do
13722this; single instruction steps always show the inlined body.
13723
13724There are some ways that @value{GDBN} does not pretend that inlined
13725function calls are the same as normal calls:
13726
13727@itemize @bullet
edb3359d
DJ
13728@item
13729Setting breakpoints at the call site of an inlined function may not
13730work, because the call site does not contain any code. @value{GDBN}
13731may incorrectly move the breakpoint to the next line of the enclosing
13732function, after the call. This limitation will be removed in a future
13733version of @value{GDBN}; until then, set a breakpoint on an earlier line
13734or inside the inlined function instead.
13735
13736@item
13737@value{GDBN} cannot locate the return value of inlined calls after
13738using the @code{finish} command. This is a limitation of compiler-generated
13739debugging information; after @code{finish}, you can step to the next line
13740and print a variable where your program stored the return value.
13741
13742@end itemize
13743
111c6489
JK
13744@node Tail Call Frames
13745@section Tail Call Frames
13746@cindex tail call frames, debugging
13747
13748Function @code{B} can call function @code{C} in its very last statement. In
13749unoptimized compilation the call of @code{C} is immediately followed by return
13750instruction at the end of @code{B} code. Optimizing compiler may replace the
13751call and return in function @code{B} into one jump to function @code{C}
13752instead. Such use of a jump instruction is called @dfn{tail call}.
13753
13754During execution of function @code{C}, there will be no indication in the
13755function call stack frames that it was tail-called from @code{B}. If function
13756@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13757then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13758some cases @value{GDBN} can determine that @code{C} was tail-called from
13759@code{B}, and it will then create fictitious call frame for that, with the
13760return address set up as if @code{B} called @code{C} normally.
13761
13762This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13763the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13764@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13765this information.
13766
13767@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13768kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13769
13770@smallexample
13771(gdb) x/i $pc - 2
13772 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13773(gdb) info frame
13774Stack level 1, frame at 0x7fffffffda30:
13775 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13776 tail call frame, caller of frame at 0x7fffffffda30
13777 source language c++.
13778 Arglist at unknown address.
13779 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13780@end smallexample
13781
13782The detection of all the possible code path executions can find them ambiguous.
13783There is no execution history stored (possible @ref{Reverse Execution} is never
13784used for this purpose) and the last known caller could have reached the known
13785callee by multiple different jump sequences. In such case @value{GDBN} still
13786tries to show at least all the unambiguous top tail callers and all the
13787unambiguous bottom tail calees, if any.
13788
13789@table @code
e18b2753 13790@anchor{set debug entry-values}
111c6489
JK
13791@item set debug entry-values
13792@kindex set debug entry-values
13793When set to on, enables printing of analysis messages for both frame argument
13794values at function entry and tail calls. It will show all the possible valid
13795tail calls code paths it has considered. It will also print the intersection
13796of them with the final unambiguous (possibly partial or even empty) code path
13797result.
13798
13799@item show debug entry-values
13800@kindex show debug entry-values
13801Show the current state of analysis messages printing for both frame argument
13802values at function entry and tail calls.
13803@end table
13804
13805The analysis messages for tail calls can for example show why the virtual tail
13806call frame for function @code{c} has not been recognized (due to the indirect
13807reference by variable @code{x}):
13808
13809@smallexample
13810static void __attribute__((noinline, noclone)) c (void);
13811void (*x) (void) = c;
13812static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13813static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13814int main (void) @{ x (); return 0; @}
13815
216f72a1
JK
13816Breakpoint 1, DW_OP_entry_value resolving cannot find
13817DW_TAG_call_site 0x40039a in main
111c6489
JK
13818a () at t.c:3
138193 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13820(gdb) bt
13821#0 a () at t.c:3
13822#1 0x000000000040039a in main () at t.c:5
13823@end smallexample
13824
13825Another possibility is an ambiguous virtual tail call frames resolution:
13826
13827@smallexample
13828int i;
13829static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13830static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13831static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13832static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13833static void __attribute__((noinline, noclone)) b (void)
13834@{ if (i) c (); else e (); @}
13835static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13836int main (void) @{ a (); return 0; @}
13837
13838tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13839tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13840tailcall: reduced: 0x4004d2(a) |
13841(gdb) bt
13842#0 f () at t.c:2
13843#1 0x00000000004004d2 in a () at t.c:8
13844#2 0x0000000000400395 in main () at t.c:9
13845@end smallexample
13846
5048e516
JK
13847@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13848@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13849
13850@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13851@ifset HAVE_MAKEINFO_CLICK
13852@set ARROW @click{}
13853@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13854@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13855@end ifset
13856@ifclear HAVE_MAKEINFO_CLICK
13857@set ARROW ->
13858@set CALLSEQ1B @value{CALLSEQ1A}
13859@set CALLSEQ2B @value{CALLSEQ2A}
13860@end ifclear
13861
13862Frames #0 and #2 are real, #1 is a virtual tail call frame.
13863The code can have possible execution paths @value{CALLSEQ1B} or
13864@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13865
13866@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13867has found. It then finds another possible calling sequence - that one is
111c6489
JK
13868prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13869printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13870further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13871any non-ambiguous sequence entries.
13872
13873For the frame of function @code{b} in both cases there are different possible
13874@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13875also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13876therefore this one is displayed to the user while the ambiguous frames are
13877omitted.
edb3359d 13878
e18b2753
JK
13879There can be also reasons why printing of frame argument values at function
13880entry may fail:
13881
13882@smallexample
13883int v;
13884static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13885static void __attribute__((noinline, noclone)) a (int i);
13886static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13887static void __attribute__((noinline, noclone)) a (int i)
13888@{ if (i) b (i - 1); else c (0); @}
13889int main (void) @{ a (5); return 0; @}
13890
13891(gdb) bt
13892#0 c (i=i@@entry=0) at t.c:2
216f72a1 13893#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13894function "a" at 0x400420 can call itself via tail calls
13895i=<optimized out>) at t.c:6
13896#2 0x000000000040036e in main () at t.c:7
13897@end smallexample
13898
13899@value{GDBN} cannot find out from the inferior state if and how many times did
13900function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13901tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13902@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13903prints @code{<optimized out>} instead.
13904
e2e0bcd1
JB
13905@node Macros
13906@chapter C Preprocessor Macros
13907
49efadf5 13908Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13909``preprocessor macros'' which expand into strings of tokens.
13910@value{GDBN} can evaluate expressions containing macro invocations, show
13911the result of macro expansion, and show a macro's definition, including
13912where it was defined.
13913
13914You may need to compile your program specially to provide @value{GDBN}
13915with information about preprocessor macros. Most compilers do not
13916include macros in their debugging information, even when you compile
13917with the @option{-g} flag. @xref{Compilation}.
13918
13919A program may define a macro at one point, remove that definition later,
13920and then provide a different definition after that. Thus, at different
13921points in the program, a macro may have different definitions, or have
13922no definition at all. If there is a current stack frame, @value{GDBN}
13923uses the macros in scope at that frame's source code line. Otherwise,
13924@value{GDBN} uses the macros in scope at the current listing location;
13925see @ref{List}.
13926
e2e0bcd1
JB
13927Whenever @value{GDBN} evaluates an expression, it always expands any
13928macro invocations present in the expression. @value{GDBN} also provides
13929the following commands for working with macros explicitly.
13930
13931@table @code
13932
13933@kindex macro expand
13934@cindex macro expansion, showing the results of preprocessor
13935@cindex preprocessor macro expansion, showing the results of
13936@cindex expanding preprocessor macros
13937@item macro expand @var{expression}
13938@itemx macro exp @var{expression}
13939Show the results of expanding all preprocessor macro invocations in
13940@var{expression}. Since @value{GDBN} simply expands macros, but does
13941not parse the result, @var{expression} need not be a valid expression;
13942it can be any string of tokens.
13943
09d4efe1 13944@kindex macro exp1
e2e0bcd1
JB
13945@item macro expand-once @var{expression}
13946@itemx macro exp1 @var{expression}
4644b6e3 13947@cindex expand macro once
e2e0bcd1
JB
13948@i{(This command is not yet implemented.)} Show the results of
13949expanding those preprocessor macro invocations that appear explicitly in
13950@var{expression}. Macro invocations appearing in that expansion are
13951left unchanged. This command allows you to see the effect of a
13952particular macro more clearly, without being confused by further
13953expansions. Since @value{GDBN} simply expands macros, but does not
13954parse the result, @var{expression} need not be a valid expression; it
13955can be any string of tokens.
13956
475b0867 13957@kindex info macro
e2e0bcd1 13958@cindex macro definition, showing
9b158ba0 13959@cindex definition of a macro, showing
13960@cindex macros, from debug info
71eba9c2 13961@item info macro [-a|-all] [--] @var{macro}
13962Show the current definition or all definitions of the named @var{macro},
13963and describe the source location or compiler command-line where that
13964definition was established. The optional double dash is to signify the end of
13965argument processing and the beginning of @var{macro} for non C-like macros where
13966the macro may begin with a hyphen.
e2e0bcd1 13967
9b158ba0 13968@kindex info macros
629500fa 13969@item info macros @var{location}
9b158ba0 13970Show all macro definitions that are in effect at the location specified
629500fa 13971by @var{location}, and describe the source location or compiler
9b158ba0 13972command-line where those definitions were established.
13973
e2e0bcd1
JB
13974@kindex macro define
13975@cindex user-defined macros
13976@cindex defining macros interactively
13977@cindex macros, user-defined
13978@item macro define @var{macro} @var{replacement-list}
13979@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13980Introduce a definition for a preprocessor macro named @var{macro},
13981invocations of which are replaced by the tokens given in
13982@var{replacement-list}. The first form of this command defines an
13983``object-like'' macro, which takes no arguments; the second form
13984defines a ``function-like'' macro, which takes the arguments given in
13985@var{arglist}.
13986
13987A definition introduced by this command is in scope in every
13988expression evaluated in @value{GDBN}, until it is removed with the
13989@code{macro undef} command, described below. The definition overrides
13990all definitions for @var{macro} present in the program being debugged,
13991as well as any previous user-supplied definition.
e2e0bcd1
JB
13992
13993@kindex macro undef
13994@item macro undef @var{macro}
d7d9f01e
TT
13995Remove any user-supplied definition for the macro named @var{macro}.
13996This command only affects definitions provided with the @code{macro
13997define} command, described above; it cannot remove definitions present
13998in the program being debugged.
e2e0bcd1 13999
09d4efe1
EZ
14000@kindex macro list
14001@item macro list
d7d9f01e 14002List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
14003@end table
14004
14005@cindex macros, example of debugging with
14006Here is a transcript showing the above commands in action. First, we
14007show our source files:
14008
14009@smallexample
14010$ cat sample.c
14011#include <stdio.h>
14012#include "sample.h"
14013
14014#define M 42
14015#define ADD(x) (M + x)
14016
14017main ()
14018@{
14019#define N 28
14020 printf ("Hello, world!\n");
14021#undef N
14022 printf ("We're so creative.\n");
14023#define N 1729
14024 printf ("Goodbye, world!\n");
14025@}
14026$ cat sample.h
14027#define Q <
14028$
14029@end smallexample
14030
e0f8f636
TT
14031Now, we compile the program using the @sc{gnu} C compiler,
14032@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14033minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14034and @option{-gdwarf-4}; we recommend always choosing the most recent
14035version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14036includes information about preprocessor macros in the debugging
e2e0bcd1
JB
14037information.
14038
14039@smallexample
14040$ gcc -gdwarf-2 -g3 sample.c -o sample
14041$
14042@end smallexample
14043
14044Now, we start @value{GDBN} on our sample program:
14045
14046@smallexample
14047$ gdb -nw sample
14048GNU gdb 2002-05-06-cvs
14049Copyright 2002 Free Software Foundation, Inc.
14050GDB is free software, @dots{}
f7dc1244 14051(@value{GDBP})
e2e0bcd1
JB
14052@end smallexample
14053
14054We can expand macros and examine their definitions, even when the
14055program is not running. @value{GDBN} uses the current listing position
14056to decide which macro definitions are in scope:
14057
14058@smallexample
f7dc1244 14059(@value{GDBP}) list main
e2e0bcd1
JB
140603
140614 #define M 42
140625 #define ADD(x) (M + x)
140636
140647 main ()
140658 @{
140669 #define N 28
1406710 printf ("Hello, world!\n");
1406811 #undef N
1406912 printf ("We're so creative.\n");
f7dc1244 14070(@value{GDBP}) info macro ADD
e2e0bcd1
JB
14071Defined at /home/jimb/gdb/macros/play/sample.c:5
14072#define ADD(x) (M + x)
f7dc1244 14073(@value{GDBP}) info macro Q
e2e0bcd1
JB
14074Defined at /home/jimb/gdb/macros/play/sample.h:1
14075 included at /home/jimb/gdb/macros/play/sample.c:2
14076#define Q <
f7dc1244 14077(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 14078expands to: (42 + 1)
f7dc1244 14079(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 14080expands to: once (M + 1)
f7dc1244 14081(@value{GDBP})
e2e0bcd1
JB
14082@end smallexample
14083
d7d9f01e 14084In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
14085the macro invocation explicit in the original text --- the invocation of
14086@code{ADD} --- but does not expand the invocation of the macro @code{M},
14087which was introduced by @code{ADD}.
14088
3f94c067
BW
14089Once the program is running, @value{GDBN} uses the macro definitions in
14090force at the source line of the current stack frame:
e2e0bcd1
JB
14091
14092@smallexample
f7dc1244 14093(@value{GDBP}) break main
e2e0bcd1 14094Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 14095(@value{GDBP}) run
b383017d 14096Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
14097
14098Breakpoint 1, main () at sample.c:10
1409910 printf ("Hello, world!\n");
f7dc1244 14100(@value{GDBP})
e2e0bcd1
JB
14101@end smallexample
14102
14103At line 10, the definition of the macro @code{N} at line 9 is in force:
14104
14105@smallexample
f7dc1244 14106(@value{GDBP}) info macro N
e2e0bcd1
JB
14107Defined at /home/jimb/gdb/macros/play/sample.c:9
14108#define N 28
f7dc1244 14109(@value{GDBP}) macro expand N Q M
e2e0bcd1 14110expands to: 28 < 42
f7dc1244 14111(@value{GDBP}) print N Q M
e2e0bcd1 14112$1 = 1
f7dc1244 14113(@value{GDBP})
e2e0bcd1
JB
14114@end smallexample
14115
14116As we step over directives that remove @code{N}'s definition, and then
14117give it a new definition, @value{GDBN} finds the definition (or lack
14118thereof) in force at each point:
14119
14120@smallexample
f7dc1244 14121(@value{GDBP}) next
e2e0bcd1
JB
14122Hello, world!
1412312 printf ("We're so creative.\n");
f7dc1244 14124(@value{GDBP}) info macro N
e2e0bcd1
JB
14125The symbol `N' has no definition as a C/C++ preprocessor macro
14126at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 14127(@value{GDBP}) next
e2e0bcd1
JB
14128We're so creative.
1412914 printf ("Goodbye, world!\n");
f7dc1244 14130(@value{GDBP}) info macro N
e2e0bcd1
JB
14131Defined at /home/jimb/gdb/macros/play/sample.c:13
14132#define N 1729
f7dc1244 14133(@value{GDBP}) macro expand N Q M
e2e0bcd1 14134expands to: 1729 < 42
f7dc1244 14135(@value{GDBP}) print N Q M
e2e0bcd1 14136$2 = 0
f7dc1244 14137(@value{GDBP})
e2e0bcd1
JB
14138@end smallexample
14139
484086b7
JK
14140In addition to source files, macros can be defined on the compilation command
14141line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14142such a way, @value{GDBN} displays the location of their definition as line zero
14143of the source file submitted to the compiler.
14144
14145@smallexample
14146(@value{GDBP}) info macro __STDC__
14147Defined at /home/jimb/gdb/macros/play/sample.c:0
14148-D__STDC__=1
14149(@value{GDBP})
14150@end smallexample
14151
e2e0bcd1 14152
b37052ae
EZ
14153@node Tracepoints
14154@chapter Tracepoints
14155@c This chapter is based on the documentation written by Michael
14156@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14157
14158@cindex tracepoints
14159In some applications, it is not feasible for the debugger to interrupt
14160the program's execution long enough for the developer to learn
14161anything helpful about its behavior. If the program's correctness
14162depends on its real-time behavior, delays introduced by a debugger
14163might cause the program to change its behavior drastically, or perhaps
14164fail, even when the code itself is correct. It is useful to be able
14165to observe the program's behavior without interrupting it.
14166
14167Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14168specify locations in the program, called @dfn{tracepoints}, and
14169arbitrary expressions to evaluate when those tracepoints are reached.
14170Later, using the @code{tfind} command, you can examine the values
14171those expressions had when the program hit the tracepoints. The
14172expressions may also denote objects in memory---structures or arrays,
14173for example---whose values @value{GDBN} should record; while visiting
14174a particular tracepoint, you may inspect those objects as if they were
14175in memory at that moment. However, because @value{GDBN} records these
14176values without interacting with you, it can do so quickly and
14177unobtrusively, hopefully not disturbing the program's behavior.
14178
14179The tracepoint facility is currently available only for remote
9d29849a
JB
14180targets. @xref{Targets}. In addition, your remote target must know
14181how to collect trace data. This functionality is implemented in the
14182remote stub; however, none of the stubs distributed with @value{GDBN}
14183support tracepoints as of this writing. The format of the remote
14184packets used to implement tracepoints are described in @ref{Tracepoint
14185Packets}.
b37052ae 14186
00bf0b85
SS
14187It is also possible to get trace data from a file, in a manner reminiscent
14188of corefiles; you specify the filename, and use @code{tfind} to search
14189through the file. @xref{Trace Files}, for more details.
14190
b37052ae
EZ
14191This chapter describes the tracepoint commands and features.
14192
14193@menu
b383017d
RM
14194* Set Tracepoints::
14195* Analyze Collected Data::
14196* Tracepoint Variables::
00bf0b85 14197* Trace Files::
b37052ae
EZ
14198@end menu
14199
14200@node Set Tracepoints
14201@section Commands to Set Tracepoints
14202
14203Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
14204tracepoints can be set. A tracepoint is actually a special type of
14205breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14206standard breakpoint commands. For instance, as with breakpoints,
14207tracepoint numbers are successive integers starting from one, and many
14208of the commands associated with tracepoints take the tracepoint number
14209as their argument, to identify which tracepoint to work on.
b37052ae
EZ
14210
14211For each tracepoint, you can specify, in advance, some arbitrary set
14212of data that you want the target to collect in the trace buffer when
14213it hits that tracepoint. The collected data can include registers,
14214local variables, or global data. Later, you can use @value{GDBN}
14215commands to examine the values these data had at the time the
14216tracepoint was hit.
14217
7d13fe92
SS
14218Tracepoints do not support every breakpoint feature. Ignore counts on
14219tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14220commands when they are hit. Tracepoints may not be thread-specific
14221either.
1042e4c0 14222
7a697b8d
SS
14223@cindex fast tracepoints
14224Some targets may support @dfn{fast tracepoints}, which are inserted in
14225a different way (such as with a jump instead of a trap), that is
14226faster but possibly restricted in where they may be installed.
14227
0fb4aa4b
PA
14228@cindex static tracepoints
14229@cindex markers, static tracepoints
14230@cindex probing markers, static tracepoints
14231Regular and fast tracepoints are dynamic tracing facilities, meaning
14232that they can be used to insert tracepoints at (almost) any location
14233in the target. Some targets may also support controlling @dfn{static
14234tracepoints} from @value{GDBN}. With static tracing, a set of
14235instrumentation points, also known as @dfn{markers}, are embedded in
14236the target program, and can be activated or deactivated by name or
14237address. These are usually placed at locations which facilitate
14238investigating what the target is actually doing. @value{GDBN}'s
14239support for static tracing includes being able to list instrumentation
14240points, and attach them with @value{GDBN} defined high level
14241tracepoints that expose the whole range of convenience of
8786b2bd 14242@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
14243registers values and values of global or local (to the instrumentation
14244point) variables; tracepoint conditions and trace state variables.
14245The act of installing a @value{GDBN} static tracepoint on an
14246instrumentation point, or marker, is referred to as @dfn{probing} a
14247static tracepoint marker.
14248
fa593d66
PA
14249@code{gdbserver} supports tracepoints on some target systems.
14250@xref{Server,,Tracepoints support in @code{gdbserver}}.
14251
b37052ae
EZ
14252This section describes commands to set tracepoints and associated
14253conditions and actions.
14254
14255@menu
b383017d
RM
14256* Create and Delete Tracepoints::
14257* Enable and Disable Tracepoints::
14258* Tracepoint Passcounts::
782b2b07 14259* Tracepoint Conditions::
f61e138d 14260* Trace State Variables::
b383017d
RM
14261* Tracepoint Actions::
14262* Listing Tracepoints::
0fb4aa4b 14263* Listing Static Tracepoint Markers::
79a6e687 14264* Starting and Stopping Trace Experiments::
c9429232 14265* Tracepoint Restrictions::
b37052ae
EZ
14266@end menu
14267
14268@node Create and Delete Tracepoints
14269@subsection Create and Delete Tracepoints
14270
14271@table @code
14272@cindex set tracepoint
14273@kindex trace
1042e4c0 14274@item trace @var{location}
b37052ae 14275The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14276Its argument @var{location} can be any valid location.
14277@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14278which is a point in the target program where the debugger will briefly stop,
14279collect some data, and then allow the program to continue. Setting a tracepoint
14280or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14281supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14282in tracing}).
14283If remote stub doesn't support the @samp{InstallInTrace} feature, all
14284these changes don't take effect until the next @code{tstart}
1042e4c0 14285command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14286not have any effect until the next trace experiment starts. In addition,
14287@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14288address is not yet resolved. (This is similar to pending breakpoints.)
14289Pending tracepoints are not downloaded to the target and not installed
14290until they are resolved. The resolution of pending tracepoints requires
14291@value{GDBN} support---when debugging with the remote target, and
14292@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14293tracing}), pending tracepoints can not be resolved (and downloaded to
14294the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14295
14296Here are some examples of using the @code{trace} command:
14297
14298@smallexample
14299(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14300
14301(@value{GDBP}) @b{trace +2} // 2 lines forward
14302
14303(@value{GDBP}) @b{trace my_function} // first source line of function
14304
14305(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14306
14307(@value{GDBP}) @b{trace *0x2117c4} // an address
14308@end smallexample
14309
14310@noindent
14311You can abbreviate @code{trace} as @code{tr}.
14312
782b2b07
SS
14313@item trace @var{location} if @var{cond}
14314Set a tracepoint with condition @var{cond}; evaluate the expression
14315@var{cond} each time the tracepoint is reached, and collect data only
14316if the value is nonzero---that is, if @var{cond} evaluates as true.
14317@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14318information on tracepoint conditions.
14319
7a697b8d
SS
14320@item ftrace @var{location} [ if @var{cond} ]
14321@cindex set fast tracepoint
74c761c1 14322@cindex fast tracepoints, setting
7a697b8d
SS
14323@kindex ftrace
14324The @code{ftrace} command sets a fast tracepoint. For targets that
14325support them, fast tracepoints will use a more efficient but possibly
14326less general technique to trigger data collection, such as a jump
14327instruction instead of a trap, or some sort of hardware support. It
14328may not be possible to create a fast tracepoint at the desired
14329location, in which case the command will exit with an explanatory
14330message.
14331
14332@value{GDBN} handles arguments to @code{ftrace} exactly as for
14333@code{trace}.
14334
405f8e94
SS
14335On 32-bit x86-architecture systems, fast tracepoints normally need to
14336be placed at an instruction that is 5 bytes or longer, but can be
14337placed at 4-byte instructions if the low 64K of memory of the target
14338program is available to install trampolines. Some Unix-type systems,
14339such as @sc{gnu}/Linux, exclude low addresses from the program's
14340address space; but for instance with the Linux kernel it is possible
14341to let @value{GDBN} use this area by doing a @command{sysctl} command
14342to set the @code{mmap_min_addr} kernel parameter, as in
14343
14344@example
14345sudo sysctl -w vm.mmap_min_addr=32768
14346@end example
14347
14348@noindent
14349which sets the low address to 32K, which leaves plenty of room for
14350trampolines. The minimum address should be set to a page boundary.
14351
0fb4aa4b 14352@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14353@cindex set static tracepoint
14354@cindex static tracepoints, setting
14355@cindex probe static tracepoint marker
0fb4aa4b
PA
14356@kindex strace
14357The @code{strace} command sets a static tracepoint. For targets that
14358support it, setting a static tracepoint probes a static
14359instrumentation point, or marker, found at @var{location}. It may not
14360be possible to set a static tracepoint at the desired location, in
14361which case the command will exit with an explanatory message.
14362
14363@value{GDBN} handles arguments to @code{strace} exactly as for
14364@code{trace}, with the addition that the user can also specify
14365@code{-m @var{marker}} as @var{location}. This probes the marker
14366identified by the @var{marker} string identifier. This identifier
14367depends on the static tracepoint backend library your program is
14368using. You can find all the marker identifiers in the @samp{ID} field
14369of the @code{info static-tracepoint-markers} command output.
14370@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14371Markers}. For example, in the following small program using the UST
14372tracing engine:
14373
14374@smallexample
14375main ()
14376@{
14377 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14378@}
14379@end smallexample
14380
14381@noindent
14382the marker id is composed of joining the first two arguments to the
14383@code{trace_mark} call with a slash, which translates to:
14384
14385@smallexample
14386(@value{GDBP}) info static-tracepoint-markers
14387Cnt Enb ID Address What
143881 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14389 Data: "str %s"
14390[etc...]
14391@end smallexample
14392
14393@noindent
14394so you may probe the marker above with:
14395
14396@smallexample
14397(@value{GDBP}) strace -m ust/bar33
14398@end smallexample
14399
14400Static tracepoints accept an extra collect action --- @code{collect
14401$_sdata}. This collects arbitrary user data passed in the probe point
14402call to the tracing library. In the UST example above, you'll see
14403that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14404string. The user data is then the result of running that formatting
0fb4aa4b
PA
14405string against the following arguments. Note that @code{info
14406static-tracepoint-markers} command output lists that format string in
14407the @samp{Data:} field.
14408
14409You can inspect this data when analyzing the trace buffer, by printing
14410the $_sdata variable like any other variable available to
14411@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14412
b37052ae
EZ
14413@vindex $tpnum
14414@cindex last tracepoint number
14415@cindex recent tracepoint number
14416@cindex tracepoint number
14417The convenience variable @code{$tpnum} records the tracepoint number
14418of the most recently set tracepoint.
14419
14420@kindex delete tracepoint
14421@cindex tracepoint deletion
14422@item delete tracepoint @r{[}@var{num}@r{]}
14423Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14424default is to delete all tracepoints. Note that the regular
14425@code{delete} command can remove tracepoints also.
b37052ae
EZ
14426
14427Examples:
14428
14429@smallexample
14430(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14431
14432(@value{GDBP}) @b{delete trace} // remove all tracepoints
14433@end smallexample
14434
14435@noindent
14436You can abbreviate this command as @code{del tr}.
14437@end table
14438
14439@node Enable and Disable Tracepoints
14440@subsection Enable and Disable Tracepoints
14441
1042e4c0
SS
14442These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14443
b37052ae
EZ
14444@table @code
14445@kindex disable tracepoint
14446@item disable tracepoint @r{[}@var{num}@r{]}
14447Disable tracepoint @var{num}, or all tracepoints if no argument
14448@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14449a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14450a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14451If the command is issued during a trace experiment and the debug target
14452has support for disabling tracepoints during a trace experiment, then the
14453change will be effective immediately. Otherwise, it will be applied to the
14454next trace experiment.
b37052ae
EZ
14455
14456@kindex enable tracepoint
14457@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14458Enable tracepoint @var{num}, or all tracepoints. If this command is
14459issued during a trace experiment and the debug target supports enabling
14460tracepoints during a trace experiment, then the enabled tracepoints will
14461become effective immediately. Otherwise, they will become effective the
14462next time a trace experiment is run.
b37052ae
EZ
14463@end table
14464
14465@node Tracepoint Passcounts
14466@subsection Tracepoint Passcounts
14467
14468@table @code
14469@kindex passcount
14470@cindex tracepoint pass count
14471@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14472Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14473automatically stop a trace experiment. If a tracepoint's passcount is
14474@var{n}, then the trace experiment will be automatically stopped on
14475the @var{n}'th time that tracepoint is hit. If the tracepoint number
14476@var{num} is not specified, the @code{passcount} command sets the
14477passcount of the most recently defined tracepoint. If no passcount is
14478given, the trace experiment will run until stopped explicitly by the
14479user.
14480
14481Examples:
14482
14483@smallexample
b383017d 14484(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14485@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14486
14487(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14488@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14489(@value{GDBP}) @b{trace foo}
14490(@value{GDBP}) @b{pass 3}
14491(@value{GDBP}) @b{trace bar}
14492(@value{GDBP}) @b{pass 2}
14493(@value{GDBP}) @b{trace baz}
14494(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14495@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14496@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14497@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14498@end smallexample
14499@end table
14500
782b2b07
SS
14501@node Tracepoint Conditions
14502@subsection Tracepoint Conditions
14503@cindex conditional tracepoints
14504@cindex tracepoint conditions
14505
14506The simplest sort of tracepoint collects data every time your program
14507reaches a specified place. You can also specify a @dfn{condition} for
14508a tracepoint. A condition is just a Boolean expression in your
14509programming language (@pxref{Expressions, ,Expressions}). A
14510tracepoint with a condition evaluates the expression each time your
14511program reaches it, and data collection happens only if the condition
14512is true.
14513
14514Tracepoint conditions can be specified when a tracepoint is set, by
14515using @samp{if} in the arguments to the @code{trace} command.
14516@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14517also be set or changed at any time with the @code{condition} command,
14518just as with breakpoints.
14519
14520Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14521the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14522expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14523suitable for execution on the target, independently of @value{GDBN}.
14524Global variables become raw memory locations, locals become stack
14525accesses, and so forth.
14526
14527For instance, suppose you have a function that is usually called
14528frequently, but should not be called after an error has occurred. You
14529could use the following tracepoint command to collect data about calls
14530of that function that happen while the error code is propagating
14531through the program; an unconditional tracepoint could end up
14532collecting thousands of useless trace frames that you would have to
14533search through.
14534
14535@smallexample
14536(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14537@end smallexample
14538
f61e138d
SS
14539@node Trace State Variables
14540@subsection Trace State Variables
14541@cindex trace state variables
14542
14543A @dfn{trace state variable} is a special type of variable that is
14544created and managed by target-side code. The syntax is the same as
14545that for GDB's convenience variables (a string prefixed with ``$''),
14546but they are stored on the target. They must be created explicitly,
14547using a @code{tvariable} command. They are always 64-bit signed
14548integers.
14549
14550Trace state variables are remembered by @value{GDBN}, and downloaded
14551to the target along with tracepoint information when the trace
14552experiment starts. There are no intrinsic limits on the number of
14553trace state variables, beyond memory limitations of the target.
14554
14555@cindex convenience variables, and trace state variables
14556Although trace state variables are managed by the target, you can use
14557them in print commands and expressions as if they were convenience
14558variables; @value{GDBN} will get the current value from the target
14559while the trace experiment is running. Trace state variables share
14560the same namespace as other ``$'' variables, which means that you
14561cannot have trace state variables with names like @code{$23} or
14562@code{$pc}, nor can you have a trace state variable and a convenience
14563variable with the same name.
14564
14565@table @code
14566
14567@item tvariable $@var{name} [ = @var{expression} ]
14568@kindex tvariable
14569The @code{tvariable} command creates a new trace state variable named
14570@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14571@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14572entered; the result will be converted to an integer if possible,
14573otherwise @value{GDBN} will report an error. A subsequent
14574@code{tvariable} command specifying the same name does not create a
14575variable, but instead assigns the supplied initial value to the
14576existing variable of that name, overwriting any previous initial
14577value. The default initial value is 0.
14578
14579@item info tvariables
14580@kindex info tvariables
14581List all the trace state variables along with their initial values.
14582Their current values may also be displayed, if the trace experiment is
14583currently running.
14584
14585@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14586@kindex delete tvariable
14587Delete the given trace state variables, or all of them if no arguments
14588are specified.
14589
14590@end table
14591
b37052ae
EZ
14592@node Tracepoint Actions
14593@subsection Tracepoint Action Lists
14594
14595@table @code
14596@kindex actions
14597@cindex tracepoint actions
14598@item actions @r{[}@var{num}@r{]}
14599This command will prompt for a list of actions to be taken when the
14600tracepoint is hit. If the tracepoint number @var{num} is not
14601specified, this command sets the actions for the one that was most
14602recently defined (so that you can define a tracepoint and then say
14603@code{actions} without bothering about its number). You specify the
14604actions themselves on the following lines, one action at a time, and
14605terminate the actions list with a line containing just @code{end}. So
7d13fe92 14606far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14607@code{while-stepping}.
14608
5a9351ae
SS
14609@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14610Commands, ,Breakpoint Command Lists}), except that only the defined
14611actions are allowed; any other @value{GDBN} command is rejected.
14612
b37052ae
EZ
14613@cindex remove actions from a tracepoint
14614To remove all actions from a tracepoint, type @samp{actions @var{num}}
14615and follow it immediately with @samp{end}.
14616
14617@smallexample
14618(@value{GDBP}) @b{collect @var{data}} // collect some data
14619
6826cf00 14620(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14621
6826cf00 14622(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14623@end smallexample
14624
14625In the following example, the action list begins with @code{collect}
14626commands indicating the things to be collected when the tracepoint is
14627hit. Then, in order to single-step and collect additional data
14628following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14629followed by the list of things to be collected after each step in a
14630sequence of single steps. The @code{while-stepping} command is
14631terminated by its own separate @code{end} command. Lastly, the action
14632list is terminated by an @code{end} command.
b37052ae
EZ
14633
14634@smallexample
14635(@value{GDBP}) @b{trace foo}
14636(@value{GDBP}) @b{actions}
14637Enter actions for tracepoint 1, one per line:
14638> collect bar,baz
14639> collect $regs
14640> while-stepping 12
5a9351ae 14641 > collect $pc, arr[i]
b37052ae
EZ
14642 > end
14643end
14644@end smallexample
14645
14646@kindex collect @r{(tracepoints)}
3065dfb6 14647@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14648Collect values of the given expressions when the tracepoint is hit.
14649This command accepts a comma-separated list of any valid expressions.
14650In addition to global, static, or local variables, the following
14651special arguments are supported:
14652
14653@table @code
14654@item $regs
0fb4aa4b 14655Collect all registers.
b37052ae
EZ
14656
14657@item $args
0fb4aa4b 14658Collect all function arguments.
b37052ae
EZ
14659
14660@item $locals
0fb4aa4b
PA
14661Collect all local variables.
14662
6710bf39
SS
14663@item $_ret
14664Collect the return address. This is helpful if you want to see more
14665of a backtrace.
14666
2a60e18f 14667@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14668determined up front, and the wrong address / registers may end up
14669collected instead. On some architectures the reliability is higher
14670for tracepoints at function entry, while on others it's the opposite.
14671When this happens, backtracing will stop because the return address is
14672found unavailable (unless another collect rule happened to match it).
14673
62e5f89c
SDJ
14674@item $_probe_argc
14675Collects the number of arguments from the static probe at which the
14676tracepoint is located.
14677@xref{Static Probe Points}.
14678
14679@item $_probe_arg@var{n}
14680@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14681from the static probe at which the tracepoint is located.
14682@xref{Static Probe Points}.
14683
0fb4aa4b
PA
14684@item $_sdata
14685@vindex $_sdata@r{, collect}
14686Collect static tracepoint marker specific data. Only available for
14687static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14688Lists}. On the UST static tracepoints library backend, an
14689instrumentation point resembles a @code{printf} function call. The
14690tracing library is able to collect user specified data formatted to a
14691character string using the format provided by the programmer that
14692instrumented the program. Other backends have similar mechanisms.
14693Here's an example of a UST marker call:
14694
14695@smallexample
14696 const char master_name[] = "$your_name";
14697 trace_mark(channel1, marker1, "hello %s", master_name)
14698@end smallexample
14699
14700In this case, collecting @code{$_sdata} collects the string
14701@samp{hello $yourname}. When analyzing the trace buffer, you can
14702inspect @samp{$_sdata} like any other variable available to
14703@value{GDBN}.
b37052ae
EZ
14704@end table
14705
14706You can give several consecutive @code{collect} commands, each one
14707with a single argument, or one @code{collect} command with several
5a9351ae 14708arguments separated by commas; the effect is the same.
b37052ae 14709
3065dfb6
SS
14710The optional @var{mods} changes the usual handling of the arguments.
14711@code{s} requests that pointers to chars be handled as strings, in
14712particular collecting the contents of the memory being pointed at, up
14713to the first zero. The upper bound is by default the value of the
14714@code{print elements} variable; if @code{s} is followed by a decimal
14715number, that is the upper bound instead. So for instance
14716@samp{collect/s25 mystr} collects as many as 25 characters at
14717@samp{mystr}.
14718
f5c37c66
EZ
14719The command @code{info scope} (@pxref{Symbols, info scope}) is
14720particularly useful for figuring out what data to collect.
14721
6da95a67
SS
14722@kindex teval @r{(tracepoints)}
14723@item teval @var{expr1}, @var{expr2}, @dots{}
14724Evaluate the given expressions when the tracepoint is hit. This
14725command accepts a comma-separated list of expressions. The results
14726are discarded, so this is mainly useful for assigning values to trace
14727state variables (@pxref{Trace State Variables}) without adding those
14728values to the trace buffer, as would be the case if the @code{collect}
14729action were used.
14730
b37052ae
EZ
14731@kindex while-stepping @r{(tracepoints)}
14732@item while-stepping @var{n}
c9429232 14733Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14734collecting new data after each step. The @code{while-stepping}
c9429232
SS
14735command is followed by the list of what to collect while stepping
14736(followed by its own @code{end} command):
b37052ae
EZ
14737
14738@smallexample
14739> while-stepping 12
14740 > collect $regs, myglobal
14741 > end
14742>
14743@end smallexample
14744
14745@noindent
7d13fe92
SS
14746Note that @code{$pc} is not automatically collected by
14747@code{while-stepping}; you need to explicitly collect that register if
14748you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14749@code{stepping}.
236f1d4d
SS
14750
14751@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14752@kindex set default-collect
14753@cindex default collection action
14754This variable is a list of expressions to collect at each tracepoint
14755hit. It is effectively an additional @code{collect} action prepended
14756to every tracepoint action list. The expressions are parsed
14757individually for each tracepoint, so for instance a variable named
14758@code{xyz} may be interpreted as a global for one tracepoint, and a
14759local for another, as appropriate to the tracepoint's location.
14760
14761@item show default-collect
14762@kindex show default-collect
14763Show the list of expressions that are collected by default at each
14764tracepoint hit.
14765
b37052ae
EZ
14766@end table
14767
14768@node Listing Tracepoints
14769@subsection Listing Tracepoints
14770
14771@table @code
e5a67952
MS
14772@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14773@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14774@cindex information about tracepoints
e5a67952 14775@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14776Display information about the tracepoint @var{num}. If you don't
14777specify a tracepoint number, displays information about all the
14778tracepoints defined so far. The format is similar to that used for
14779@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14780command, simply restricting itself to tracepoints.
14781
14782A tracepoint's listing may include additional information specific to
14783tracing:
b37052ae
EZ
14784
14785@itemize @bullet
14786@item
b37052ae 14787its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14788
14789@item
14790the state about installed on target of each location
b37052ae
EZ
14791@end itemize
14792
14793@smallexample
14794(@value{GDBP}) @b{info trace}
1042e4c0
SS
14795Num Type Disp Enb Address What
147961 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14797 while-stepping 20
14798 collect globfoo, $regs
14799 end
14800 collect globfoo2
14801 end
1042e4c0 14802 pass count 1200
f2a8bc8a
YQ
148032 tracepoint keep y <MULTIPLE>
14804 collect $eip
148052.1 y 0x0804859c in func4 at change-loc.h:35
14806 installed on target
148072.2 y 0xb7ffc480 in func4 at change-loc.h:35
14808 installed on target
148092.3 y <PENDING> set_tracepoint
148103 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14811 not installed on target
b37052ae
EZ
14812(@value{GDBP})
14813@end smallexample
14814
14815@noindent
14816This command can be abbreviated @code{info tp}.
14817@end table
14818
0fb4aa4b
PA
14819@node Listing Static Tracepoint Markers
14820@subsection Listing Static Tracepoint Markers
14821
14822@table @code
14823@kindex info static-tracepoint-markers
14824@cindex information about static tracepoint markers
14825@item info static-tracepoint-markers
14826Display information about all static tracepoint markers defined in the
14827program.
14828
14829For each marker, the following columns are printed:
14830
14831@table @emph
14832@item Count
14833An incrementing counter, output to help readability. This is not a
14834stable identifier.
14835@item ID
14836The marker ID, as reported by the target.
14837@item Enabled or Disabled
14838Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14839that are not enabled.
14840@item Address
14841Where the marker is in your program, as a memory address.
14842@item What
14843Where the marker is in the source for your program, as a file and line
14844number. If the debug information included in the program does not
14845allow @value{GDBN} to locate the source of the marker, this column
14846will be left blank.
14847@end table
14848
14849@noindent
14850In addition, the following information may be printed for each marker:
14851
14852@table @emph
14853@item Data
14854User data passed to the tracing library by the marker call. In the
14855UST backend, this is the format string passed as argument to the
14856marker call.
14857@item Static tracepoints probing the marker
14858The list of static tracepoints attached to the marker.
14859@end table
14860
14861@smallexample
14862(@value{GDBP}) info static-tracepoint-markers
14863Cnt ID Enb Address What
148641 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14865 Data: number1 %d number2 %d
14866 Probed by static tracepoints: #2
148672 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14868 Data: str %s
14869(@value{GDBP})
14870@end smallexample
14871@end table
14872
79a6e687
BW
14873@node Starting and Stopping Trace Experiments
14874@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14875
14876@table @code
f196051f 14877@kindex tstart [ @var{notes} ]
b37052ae
EZ
14878@cindex start a new trace experiment
14879@cindex collected data discarded
14880@item tstart
f196051f
SS
14881This command starts the trace experiment, and begins collecting data.
14882It has the side effect of discarding all the data collected in the
14883trace buffer during the previous trace experiment. If any arguments
14884are supplied, they are taken as a note and stored with the trace
14885experiment's state. The notes may be arbitrary text, and are
14886especially useful with disconnected tracing in a multi-user context;
14887the notes can explain what the trace is doing, supply user contact
14888information, and so forth.
14889
14890@kindex tstop [ @var{notes} ]
b37052ae
EZ
14891@cindex stop a running trace experiment
14892@item tstop
f196051f
SS
14893This command stops the trace experiment. If any arguments are
14894supplied, they are recorded with the experiment as a note. This is
14895useful if you are stopping a trace started by someone else, for
14896instance if the trace is interfering with the system's behavior and
14897needs to be stopped quickly.
b37052ae 14898
68c71a2e 14899@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14900automatically if any tracepoint's passcount is reached
14901(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14902
14903@kindex tstatus
14904@cindex status of trace data collection
14905@cindex trace experiment, status of
14906@item tstatus
14907This command displays the status of the current trace data
14908collection.
14909@end table
14910
14911Here is an example of the commands we described so far:
14912
14913@smallexample
14914(@value{GDBP}) @b{trace gdb_c_test}
14915(@value{GDBP}) @b{actions}
14916Enter actions for tracepoint #1, one per line.
14917> collect $regs,$locals,$args
14918> while-stepping 11
14919 > collect $regs
14920 > end
14921> end
14922(@value{GDBP}) @b{tstart}
14923 [time passes @dots{}]
14924(@value{GDBP}) @b{tstop}
14925@end smallexample
14926
03f2bd59 14927@anchor{disconnected tracing}
d5551862
SS
14928@cindex disconnected tracing
14929You can choose to continue running the trace experiment even if
14930@value{GDBN} disconnects from the target, voluntarily or
14931involuntarily. For commands such as @code{detach}, the debugger will
14932ask what you want to do with the trace. But for unexpected
14933terminations (@value{GDBN} crash, network outage), it would be
14934unfortunate to lose hard-won trace data, so the variable
14935@code{disconnected-tracing} lets you decide whether the trace should
14936continue running without @value{GDBN}.
14937
14938@table @code
14939@item set disconnected-tracing on
14940@itemx set disconnected-tracing off
14941@kindex set disconnected-tracing
14942Choose whether a tracing run should continue to run if @value{GDBN}
14943has disconnected from the target. Note that @code{detach} or
14944@code{quit} will ask you directly what to do about a running trace no
14945matter what this variable's setting, so the variable is mainly useful
14946for handling unexpected situations, such as loss of the network.
14947
14948@item show disconnected-tracing
14949@kindex show disconnected-tracing
14950Show the current choice for disconnected tracing.
14951
14952@end table
14953
14954When you reconnect to the target, the trace experiment may or may not
14955still be running; it might have filled the trace buffer in the
14956meantime, or stopped for one of the other reasons. If it is running,
14957it will continue after reconnection.
14958
14959Upon reconnection, the target will upload information about the
14960tracepoints in effect. @value{GDBN} will then compare that
14961information to the set of tracepoints currently defined, and attempt
14962to match them up, allowing for the possibility that the numbers may
14963have changed due to creation and deletion in the meantime. If one of
14964the target's tracepoints does not match any in @value{GDBN}, the
14965debugger will create a new tracepoint, so that you have a number with
14966which to specify that tracepoint. This matching-up process is
14967necessarily heuristic, and it may result in useless tracepoints being
14968created; you may simply delete them if they are of no use.
b37052ae 14969
4daf5ac0
SS
14970@cindex circular trace buffer
14971If your target agent supports a @dfn{circular trace buffer}, then you
14972can run a trace experiment indefinitely without filling the trace
14973buffer; when space runs out, the agent deletes already-collected trace
14974frames, oldest first, until there is enough room to continue
14975collecting. This is especially useful if your tracepoints are being
14976hit too often, and your trace gets terminated prematurely because the
14977buffer is full. To ask for a circular trace buffer, simply set
81896e36 14978@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14979including during tracing; if the agent can do it, it will change
14980buffer handling on the fly, otherwise it will not take effect until
14981the next run.
14982
14983@table @code
14984@item set circular-trace-buffer on
14985@itemx set circular-trace-buffer off
14986@kindex set circular-trace-buffer
14987Choose whether a tracing run should use a linear or circular buffer
14988for trace data. A linear buffer will not lose any trace data, but may
14989fill up prematurely, while a circular buffer will discard old trace
14990data, but it will have always room for the latest tracepoint hits.
14991
14992@item show circular-trace-buffer
14993@kindex show circular-trace-buffer
14994Show the current choice for the trace buffer. Note that this may not
14995match the agent's current buffer handling, nor is it guaranteed to
14996match the setting that might have been in effect during a past run,
14997for instance if you are looking at frames from a trace file.
14998
14999@end table
15000
f6f899bf
HAQ
15001@table @code
15002@item set trace-buffer-size @var{n}
f81d1120 15003@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
15004@kindex set trace-buffer-size
15005Request that the target use a trace buffer of @var{n} bytes. Not all
15006targets will honor the request; they may have a compiled-in size for
15007the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
15008@code{unlimited} or @code{-1} to let the target use whatever size it
15009likes. This is also the default.
f6f899bf
HAQ
15010
15011@item show trace-buffer-size
15012@kindex show trace-buffer-size
15013Show the current requested size for the trace buffer. Note that this
15014will only match the actual size if the target supports size-setting,
15015and was able to handle the requested size. For instance, if the
15016target can only change buffer size between runs, this variable will
15017not reflect the change until the next run starts. Use @code{tstatus}
15018to get a report of the actual buffer size.
15019@end table
15020
f196051f
SS
15021@table @code
15022@item set trace-user @var{text}
15023@kindex set trace-user
15024
15025@item show trace-user
15026@kindex show trace-user
15027
15028@item set trace-notes @var{text}
15029@kindex set trace-notes
15030Set the trace run's notes.
15031
15032@item show trace-notes
15033@kindex show trace-notes
15034Show the trace run's notes.
15035
15036@item set trace-stop-notes @var{text}
15037@kindex set trace-stop-notes
15038Set the trace run's stop notes. The handling of the note is as for
15039@code{tstop} arguments; the set command is convenient way to fix a
15040stop note that is mistaken or incomplete.
15041
15042@item show trace-stop-notes
15043@kindex show trace-stop-notes
15044Show the trace run's stop notes.
15045
15046@end table
15047
c9429232
SS
15048@node Tracepoint Restrictions
15049@subsection Tracepoint Restrictions
15050
15051@cindex tracepoint restrictions
15052There are a number of restrictions on the use of tracepoints. As
15053described above, tracepoint data gathering occurs on the target
15054without interaction from @value{GDBN}. Thus the full capabilities of
15055the debugger are not available during data gathering, and then at data
15056examination time, you will be limited by only having what was
15057collected. The following items describe some common problems, but it
15058is not exhaustive, and you may run into additional difficulties not
15059mentioned here.
15060
15061@itemize @bullet
15062
15063@item
15064Tracepoint expressions are intended to gather objects (lvalues). Thus
15065the full flexibility of GDB's expression evaluator is not available.
15066You cannot call functions, cast objects to aggregate types, access
15067convenience variables or modify values (except by assignment to trace
15068state variables). Some language features may implicitly call
15069functions (for instance Objective-C fields with accessors), and therefore
15070cannot be collected either.
15071
15072@item
15073Collection of local variables, either individually or in bulk with
15074@code{$locals} or @code{$args}, during @code{while-stepping} may
15075behave erratically. The stepping action may enter a new scope (for
15076instance by stepping into a function), or the location of the variable
15077may change (for instance it is loaded into a register). The
15078tracepoint data recorded uses the location information for the
15079variables that is correct for the tracepoint location. When the
15080tracepoint is created, it is not possible, in general, to determine
15081where the steps of a @code{while-stepping} sequence will advance the
15082program---particularly if a conditional branch is stepped.
15083
15084@item
15085Collection of an incompletely-initialized or partially-destroyed object
15086may result in something that @value{GDBN} cannot display, or displays
15087in a misleading way.
15088
15089@item
15090When @value{GDBN} displays a pointer to character it automatically
15091dereferences the pointer to also display characters of the string
15092being pointed to. However, collecting the pointer during tracing does
15093not automatically collect the string. You need to explicitly
15094dereference the pointer and provide size information if you want to
15095collect not only the pointer, but the memory pointed to. For example,
15096@code{*ptr@@50} can be used to collect the 50 element array pointed to
15097by @code{ptr}.
15098
15099@item
15100It is not possible to collect a complete stack backtrace at a
15101tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 15102bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
15103(adjust to use the name of the actual stack pointer register on your
15104target architecture, and the amount of stack you wish to capture).
15105Then the @code{backtrace} command will show a partial backtrace when
15106using a trace frame. The number of stack frames that can be examined
15107depends on the sizes of the frames in the collected stack. Note that
15108if you ask for a block so large that it goes past the bottom of the
15109stack, the target agent may report an error trying to read from an
15110invalid address.
15111
af54718e
SS
15112@item
15113If you do not collect registers at a tracepoint, @value{GDBN} can
15114infer that the value of @code{$pc} must be the same as the address of
15115the tracepoint and use that when you are looking at a trace frame
15116for that tracepoint. However, this cannot work if the tracepoint has
15117multiple locations (for instance if it was set in a function that was
15118inlined), or if it has a @code{while-stepping} loop. In those cases
15119@value{GDBN} will warn you that it can't infer @code{$pc}, and default
15120it to zero.
15121
c9429232
SS
15122@end itemize
15123
b37052ae 15124@node Analyze Collected Data
79a6e687 15125@section Using the Collected Data
b37052ae
EZ
15126
15127After the tracepoint experiment ends, you use @value{GDBN} commands
15128for examining the trace data. The basic idea is that each tracepoint
15129collects a trace @dfn{snapshot} every time it is hit and another
15130snapshot every time it single-steps. All these snapshots are
15131consecutively numbered from zero and go into a buffer, and you can
15132examine them later. The way you examine them is to @dfn{focus} on a
15133specific trace snapshot. When the remote stub is focused on a trace
15134snapshot, it will respond to all @value{GDBN} requests for memory and
15135registers by reading from the buffer which belongs to that snapshot,
15136rather than from @emph{real} memory or registers of the program being
15137debugged. This means that @strong{all} @value{GDBN} commands
15138(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15139behave as if we were currently debugging the program state as it was
15140when the tracepoint occurred. Any requests for data that are not in
15141the buffer will fail.
15142
15143@menu
15144* tfind:: How to select a trace snapshot
15145* tdump:: How to display all data for a snapshot
6149aea9 15146* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
15147@end menu
15148
15149@node tfind
15150@subsection @code{tfind @var{n}}
15151
15152@kindex tfind
15153@cindex select trace snapshot
15154@cindex find trace snapshot
15155The basic command for selecting a trace snapshot from the buffer is
15156@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15157counting from zero. If no argument @var{n} is given, the next
15158snapshot is selected.
15159
15160Here are the various forms of using the @code{tfind} command.
15161
15162@table @code
15163@item tfind start
15164Find the first snapshot in the buffer. This is a synonym for
15165@code{tfind 0} (since 0 is the number of the first snapshot).
15166
15167@item tfind none
15168Stop debugging trace snapshots, resume @emph{live} debugging.
15169
15170@item tfind end
15171Same as @samp{tfind none}.
15172
15173@item tfind
310cdbb6
YQ
15174No argument means find the next trace snapshot or find the first
15175one if no trace snapshot is selected.
b37052ae
EZ
15176
15177@item tfind -
15178Find the previous trace snapshot before the current one. This permits
15179retracing earlier steps.
15180
15181@item tfind tracepoint @var{num}
15182Find the next snapshot associated with tracepoint @var{num}. Search
15183proceeds forward from the last examined trace snapshot. If no
15184argument @var{num} is given, it means find the next snapshot collected
15185for the same tracepoint as the current snapshot.
15186
15187@item tfind pc @var{addr}
15188Find the next snapshot associated with the value @var{addr} of the
15189program counter. Search proceeds forward from the last examined trace
15190snapshot. If no argument @var{addr} is given, it means find the next
15191snapshot with the same value of PC as the current snapshot.
15192
15193@item tfind outside @var{addr1}, @var{addr2}
15194Find the next snapshot whose PC is outside the given range of
081dfbf7 15195addresses (exclusive).
b37052ae
EZ
15196
15197@item tfind range @var{addr1}, @var{addr2}
15198Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 15199@var{addr2} (inclusive).
b37052ae
EZ
15200
15201@item tfind line @r{[}@var{file}:@r{]}@var{n}
15202Find the next snapshot associated with the source line @var{n}. If
15203the optional argument @var{file} is given, refer to line @var{n} in
15204that source file. Search proceeds forward from the last examined
15205trace snapshot. If no argument @var{n} is given, it means find the
15206next line other than the one currently being examined; thus saying
15207@code{tfind line} repeatedly can appear to have the same effect as
15208stepping from line to line in a @emph{live} debugging session.
15209@end table
15210
15211The default arguments for the @code{tfind} commands are specifically
15212designed to make it easy to scan through the trace buffer. For
15213instance, @code{tfind} with no argument selects the next trace
15214snapshot, and @code{tfind -} with no argument selects the previous
15215trace snapshot. So, by giving one @code{tfind} command, and then
15216simply hitting @key{RET} repeatedly you can examine all the trace
15217snapshots in order. Or, by saying @code{tfind -} and then hitting
15218@key{RET} repeatedly you can examine the snapshots in reverse order.
15219The @code{tfind line} command with no argument selects the snapshot
15220for the next source line executed. The @code{tfind pc} command with
15221no argument selects the next snapshot with the same program counter
15222(PC) as the current frame. The @code{tfind tracepoint} command with
15223no argument selects the next trace snapshot collected by the same
15224tracepoint as the current one.
15225
15226In addition to letting you scan through the trace buffer manually,
15227these commands make it easy to construct @value{GDBN} scripts that
15228scan through the trace buffer and print out whatever collected data
15229you are interested in. Thus, if we want to examine the PC, FP, and SP
15230registers from each trace frame in the buffer, we can say this:
15231
15232@smallexample
15233(@value{GDBP}) @b{tfind start}
15234(@value{GDBP}) @b{while ($trace_frame != -1)}
15235> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15236 $trace_frame, $pc, $sp, $fp
15237> tfind
15238> end
15239
15240Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15241Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15242Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15243Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15244Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15245Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15246Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15247Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15248Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15249Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15250Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15251@end smallexample
15252
15253Or, if we want to examine the variable @code{X} at each source line in
15254the buffer:
15255
15256@smallexample
15257(@value{GDBP}) @b{tfind start}
15258(@value{GDBP}) @b{while ($trace_frame != -1)}
15259> printf "Frame %d, X == %d\n", $trace_frame, X
15260> tfind line
15261> end
15262
15263Frame 0, X = 1
15264Frame 7, X = 2
15265Frame 13, X = 255
15266@end smallexample
15267
15268@node tdump
15269@subsection @code{tdump}
15270@kindex tdump
15271@cindex dump all data collected at tracepoint
15272@cindex tracepoint data, display
15273
15274This command takes no arguments. It prints all the data collected at
15275the current trace snapshot.
15276
15277@smallexample
15278(@value{GDBP}) @b{trace 444}
15279(@value{GDBP}) @b{actions}
15280Enter actions for tracepoint #2, one per line:
15281> collect $regs, $locals, $args, gdb_long_test
15282> end
15283
15284(@value{GDBP}) @b{tstart}
15285
15286(@value{GDBP}) @b{tfind line 444}
15287#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15288at gdb_test.c:444
15289444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15290
15291(@value{GDBP}) @b{tdump}
15292Data collected at tracepoint 2, trace frame 1:
15293d0 0xc4aa0085 -995491707
15294d1 0x18 24
15295d2 0x80 128
15296d3 0x33 51
15297d4 0x71aea3d 119204413
15298d5 0x22 34
15299d6 0xe0 224
15300d7 0x380035 3670069
15301a0 0x19e24a 1696330
15302a1 0x3000668 50333288
15303a2 0x100 256
15304a3 0x322000 3284992
15305a4 0x3000698 50333336
15306a5 0x1ad3cc 1758156
15307fp 0x30bf3c 0x30bf3c
15308sp 0x30bf34 0x30bf34
15309ps 0x0 0
15310pc 0x20b2c8 0x20b2c8
15311fpcontrol 0x0 0
15312fpstatus 0x0 0
15313fpiaddr 0x0 0
15314p = 0x20e5b4 "gdb-test"
15315p1 = (void *) 0x11
15316p2 = (void *) 0x22
15317p3 = (void *) 0x33
15318p4 = (void *) 0x44
15319p5 = (void *) 0x55
15320p6 = (void *) 0x66
15321gdb_long_test = 17 '\021'
15322
15323(@value{GDBP})
15324@end smallexample
15325
af54718e
SS
15326@code{tdump} works by scanning the tracepoint's current collection
15327actions and printing the value of each expression listed. So
15328@code{tdump} can fail, if after a run, you change the tracepoint's
15329actions to mention variables that were not collected during the run.
15330
15331Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15332uses the collected value of @code{$pc} to distinguish between trace
15333frames that were collected at the tracepoint hit, and frames that were
15334collected while stepping. This allows it to correctly choose whether
15335to display the basic list of collections, or the collections from the
15336body of the while-stepping loop. However, if @code{$pc} was not collected,
15337then @code{tdump} will always attempt to dump using the basic collection
15338list, and may fail if a while-stepping frame does not include all the
15339same data that is collected at the tracepoint hit.
15340@c This is getting pretty arcane, example would be good.
15341
6149aea9
PA
15342@node save tracepoints
15343@subsection @code{save tracepoints @var{filename}}
15344@kindex save tracepoints
b37052ae
EZ
15345@kindex save-tracepoints
15346@cindex save tracepoints for future sessions
15347
15348This command saves all current tracepoint definitions together with
15349their actions and passcounts, into a file @file{@var{filename}}
15350suitable for use in a later debugging session. To read the saved
15351tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15352Files}). The @w{@code{save-tracepoints}} command is a deprecated
15353alias for @w{@code{save tracepoints}}
b37052ae
EZ
15354
15355@node Tracepoint Variables
15356@section Convenience Variables for Tracepoints
15357@cindex tracepoint variables
15358@cindex convenience variables for tracepoints
15359
15360@table @code
15361@vindex $trace_frame
15362@item (int) $trace_frame
15363The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15364snapshot is selected.
15365
15366@vindex $tracepoint
15367@item (int) $tracepoint
15368The tracepoint for the current trace snapshot.
15369
15370@vindex $trace_line
15371@item (int) $trace_line
15372The line number for the current trace snapshot.
15373
15374@vindex $trace_file
15375@item (char []) $trace_file
15376The source file for the current trace snapshot.
15377
15378@vindex $trace_func
15379@item (char []) $trace_func
15380The name of the function containing @code{$tracepoint}.
15381@end table
15382
15383Note: @code{$trace_file} is not suitable for use in @code{printf},
15384use @code{output} instead.
15385
15386Here's a simple example of using these convenience variables for
15387stepping through all the trace snapshots and printing some of their
f61e138d
SS
15388data. Note that these are not the same as trace state variables,
15389which are managed by the target.
b37052ae
EZ
15390
15391@smallexample
15392(@value{GDBP}) @b{tfind start}
15393
15394(@value{GDBP}) @b{while $trace_frame != -1}
15395> output $trace_file
15396> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15397> tfind
15398> end
15399@end smallexample
15400
00bf0b85
SS
15401@node Trace Files
15402@section Using Trace Files
15403@cindex trace files
15404
15405In some situations, the target running a trace experiment may no
15406longer be available; perhaps it crashed, or the hardware was needed
15407for a different activity. To handle these cases, you can arrange to
15408dump the trace data into a file, and later use that file as a source
15409of trace data, via the @code{target tfile} command.
15410
15411@table @code
15412
15413@kindex tsave
15414@item tsave [ -r ] @var{filename}
d0353e76 15415@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15416Save the trace data to @var{filename}. By default, this command
15417assumes that @var{filename} refers to the host filesystem, so if
15418necessary @value{GDBN} will copy raw trace data up from the target and
15419then save it. If the target supports it, you can also supply the
15420optional argument @code{-r} (``remote'') to direct the target to save
15421the data directly into @var{filename} in its own filesystem, which may be
15422more efficient if the trace buffer is very large. (Note, however, that
15423@code{target tfile} can only read from files accessible to the host.)
d0353e76 15424By default, this command will save trace frame in tfile format.
be06ba8c 15425You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15426format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15427that can be shared by multiple debugging and tracing tools. Please go to
15428@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15429
15430@kindex target tfile
15431@kindex tfile
393fd4c3
YQ
15432@kindex target ctf
15433@kindex ctf
00bf0b85 15434@item target tfile @var{filename}
393fd4c3
YQ
15435@itemx target ctf @var{dirname}
15436Use the file named @var{filename} or directory named @var{dirname} as
15437a source of trace data. Commands that examine data work as they do with
15438a live target, but it is not possible to run any new trace experiments.
15439@code{tstatus} will report the state of the trace run at the moment
15440the data was saved, as well as the current trace frame you are examining.
697aa1b7 15441Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15442the host.
15443
15444@smallexample
15445(@value{GDBP}) target ctf ctf.ctf
15446(@value{GDBP}) tfind
15447Found trace frame 0, tracepoint 2
1544839 ++a; /* set tracepoint 1 here */
15449(@value{GDBP}) tdump
15450Data collected at tracepoint 2, trace frame 0:
15451i = 0
15452a = 0
15453b = 1 '\001'
15454c = @{"123", "456", "789", "123", "456", "789"@}
15455d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15456(@value{GDBP}) p b
15457$1 = 1
15458@end smallexample
00bf0b85
SS
15459
15460@end table
15461
df0cd8c5
JB
15462@node Overlays
15463@chapter Debugging Programs That Use Overlays
15464@cindex overlays
15465
15466If your program is too large to fit completely in your target system's
15467memory, you can sometimes use @dfn{overlays} to work around this
15468problem. @value{GDBN} provides some support for debugging programs that
15469use overlays.
15470
15471@menu
15472* How Overlays Work:: A general explanation of overlays.
15473* Overlay Commands:: Managing overlays in @value{GDBN}.
15474* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15475 mapped by asking the inferior.
15476* Overlay Sample Program:: A sample program using overlays.
15477@end menu
15478
15479@node How Overlays Work
15480@section How Overlays Work
15481@cindex mapped overlays
15482@cindex unmapped overlays
15483@cindex load address, overlay's
15484@cindex mapped address
15485@cindex overlay area
15486
15487Suppose you have a computer whose instruction address space is only 64
15488kilobytes long, but which has much more memory which can be accessed by
15489other means: special instructions, segment registers, or memory
15490management hardware, for example. Suppose further that you want to
15491adapt a program which is larger than 64 kilobytes to run on this system.
15492
15493One solution is to identify modules of your program which are relatively
15494independent, and need not call each other directly; call these modules
15495@dfn{overlays}. Separate the overlays from the main program, and place
15496their machine code in the larger memory. Place your main program in
15497instruction memory, but leave at least enough space there to hold the
15498largest overlay as well.
15499
15500Now, to call a function located in an overlay, you must first copy that
15501overlay's machine code from the large memory into the space set aside
15502for it in the instruction memory, and then jump to its entry point
15503there.
15504
c928edc0
AC
15505@c NB: In the below the mapped area's size is greater or equal to the
15506@c size of all overlays. This is intentional to remind the developer
15507@c that overlays don't necessarily need to be the same size.
15508
474c8240 15509@smallexample
df0cd8c5 15510@group
c928edc0
AC
15511 Data Instruction Larger
15512Address Space Address Space Address Space
15513+-----------+ +-----------+ +-----------+
15514| | | | | |
15515+-----------+ +-----------+ +-----------+<-- overlay 1
15516| program | | main | .----| overlay 1 | load address
15517| variables | | program | | +-----------+
15518| and heap | | | | | |
15519+-----------+ | | | +-----------+<-- overlay 2
15520| | +-----------+ | | | load address
15521+-----------+ | | | .-| overlay 2 |
15522 | | | | | |
15523 mapped --->+-----------+ | | +-----------+
15524 address | | | | | |
15525 | overlay | <-' | | |
15526 | area | <---' +-----------+<-- overlay 3
15527 | | <---. | | load address
15528 +-----------+ `--| overlay 3 |
15529 | | | |
15530 +-----------+ | |
15531 +-----------+
15532 | |
15533 +-----------+
15534
15535 @anchor{A code overlay}A code overlay
df0cd8c5 15536@end group
474c8240 15537@end smallexample
df0cd8c5 15538
c928edc0
AC
15539The diagram (@pxref{A code overlay}) shows a system with separate data
15540and instruction address spaces. To map an overlay, the program copies
15541its code from the larger address space to the instruction address space.
15542Since the overlays shown here all use the same mapped address, only one
15543may be mapped at a time. For a system with a single address space for
15544data and instructions, the diagram would be similar, except that the
15545program variables and heap would share an address space with the main
15546program and the overlay area.
df0cd8c5
JB
15547
15548An overlay loaded into instruction memory and ready for use is called a
15549@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15550instruction memory. An overlay not present (or only partially present)
15551in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15552is its address in the larger memory. The mapped address is also called
15553the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15554called the @dfn{load memory address}, or @dfn{LMA}.
15555
15556Unfortunately, overlays are not a completely transparent way to adapt a
15557program to limited instruction memory. They introduce a new set of
15558global constraints you must keep in mind as you design your program:
15559
15560@itemize @bullet
15561
15562@item
15563Before calling or returning to a function in an overlay, your program
15564must make sure that overlay is actually mapped. Otherwise, the call or
15565return will transfer control to the right address, but in the wrong
15566overlay, and your program will probably crash.
15567
15568@item
15569If the process of mapping an overlay is expensive on your system, you
15570will need to choose your overlays carefully to minimize their effect on
15571your program's performance.
15572
15573@item
15574The executable file you load onto your system must contain each
15575overlay's instructions, appearing at the overlay's load address, not its
15576mapped address. However, each overlay's instructions must be relocated
15577and its symbols defined as if the overlay were at its mapped address.
15578You can use GNU linker scripts to specify different load and relocation
15579addresses for pieces of your program; see @ref{Overlay Description,,,
15580ld.info, Using ld: the GNU linker}.
15581
15582@item
15583The procedure for loading executable files onto your system must be able
15584to load their contents into the larger address space as well as the
15585instruction and data spaces.
15586
15587@end itemize
15588
15589The overlay system described above is rather simple, and could be
15590improved in many ways:
15591
15592@itemize @bullet
15593
15594@item
15595If your system has suitable bank switch registers or memory management
15596hardware, you could use those facilities to make an overlay's load area
15597contents simply appear at their mapped address in instruction space.
15598This would probably be faster than copying the overlay to its mapped
15599area in the usual way.
15600
15601@item
15602If your overlays are small enough, you could set aside more than one
15603overlay area, and have more than one overlay mapped at a time.
15604
15605@item
15606You can use overlays to manage data, as well as instructions. In
15607general, data overlays are even less transparent to your design than
15608code overlays: whereas code overlays only require care when you call or
15609return to functions, data overlays require care every time you access
15610the data. Also, if you change the contents of a data overlay, you
15611must copy its contents back out to its load address before you can copy a
15612different data overlay into the same mapped area.
15613
15614@end itemize
15615
15616
15617@node Overlay Commands
15618@section Overlay Commands
15619
15620To use @value{GDBN}'s overlay support, each overlay in your program must
15621correspond to a separate section of the executable file. The section's
15622virtual memory address and load memory address must be the overlay's
15623mapped and load addresses. Identifying overlays with sections allows
15624@value{GDBN} to determine the appropriate address of a function or
15625variable, depending on whether the overlay is mapped or not.
15626
15627@value{GDBN}'s overlay commands all start with the word @code{overlay};
15628you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15629
15630@table @code
15631@item overlay off
4644b6e3 15632@kindex overlay
df0cd8c5
JB
15633Disable @value{GDBN}'s overlay support. When overlay support is
15634disabled, @value{GDBN} assumes that all functions and variables are
15635always present at their mapped addresses. By default, @value{GDBN}'s
15636overlay support is disabled.
15637
15638@item overlay manual
df0cd8c5
JB
15639@cindex manual overlay debugging
15640Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15641relies on you to tell it which overlays are mapped, and which are not,
15642using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15643commands described below.
15644
15645@item overlay map-overlay @var{overlay}
15646@itemx overlay map @var{overlay}
df0cd8c5
JB
15647@cindex map an overlay
15648Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15649be the name of the object file section containing the overlay. When an
15650overlay is mapped, @value{GDBN} assumes it can find the overlay's
15651functions and variables at their mapped addresses. @value{GDBN} assumes
15652that any other overlays whose mapped ranges overlap that of
15653@var{overlay} are now unmapped.
15654
15655@item overlay unmap-overlay @var{overlay}
15656@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15657@cindex unmap an overlay
15658Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15659must be the name of the object file section containing the overlay.
15660When an overlay is unmapped, @value{GDBN} assumes it can find the
15661overlay's functions and variables at their load addresses.
15662
15663@item overlay auto
df0cd8c5
JB
15664Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15665consults a data structure the overlay manager maintains in the inferior
15666to see which overlays are mapped. For details, see @ref{Automatic
15667Overlay Debugging}.
15668
15669@item overlay load-target
15670@itemx overlay load
df0cd8c5
JB
15671@cindex reloading the overlay table
15672Re-read the overlay table from the inferior. Normally, @value{GDBN}
15673re-reads the table @value{GDBN} automatically each time the inferior
15674stops, so this command should only be necessary if you have changed the
15675overlay mapping yourself using @value{GDBN}. This command is only
15676useful when using automatic overlay debugging.
15677
15678@item overlay list-overlays
15679@itemx overlay list
15680@cindex listing mapped overlays
15681Display a list of the overlays currently mapped, along with their mapped
15682addresses, load addresses, and sizes.
15683
15684@end table
15685
15686Normally, when @value{GDBN} prints a code address, it includes the name
15687of the function the address falls in:
15688
474c8240 15689@smallexample
f7dc1244 15690(@value{GDBP}) print main
df0cd8c5 15691$3 = @{int ()@} 0x11a0 <main>
474c8240 15692@end smallexample
df0cd8c5
JB
15693@noindent
15694When overlay debugging is enabled, @value{GDBN} recognizes code in
15695unmapped overlays, and prints the names of unmapped functions with
15696asterisks around them. For example, if @code{foo} is a function in an
15697unmapped overlay, @value{GDBN} prints it this way:
15698
474c8240 15699@smallexample
f7dc1244 15700(@value{GDBP}) overlay list
df0cd8c5 15701No sections are mapped.
f7dc1244 15702(@value{GDBP}) print foo
df0cd8c5 15703$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15704@end smallexample
df0cd8c5
JB
15705@noindent
15706When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15707name normally:
15708
474c8240 15709@smallexample
f7dc1244 15710(@value{GDBP}) overlay list
b383017d 15711Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15712 mapped at 0x1016 - 0x104a
f7dc1244 15713(@value{GDBP}) print foo
df0cd8c5 15714$6 = @{int (int)@} 0x1016 <foo>
474c8240 15715@end smallexample
df0cd8c5
JB
15716
15717When overlay debugging is enabled, @value{GDBN} can find the correct
15718address for functions and variables in an overlay, whether or not the
15719overlay is mapped. This allows most @value{GDBN} commands, like
15720@code{break} and @code{disassemble}, to work normally, even on unmapped
15721code. However, @value{GDBN}'s breakpoint support has some limitations:
15722
15723@itemize @bullet
15724@item
15725@cindex breakpoints in overlays
15726@cindex overlays, setting breakpoints in
15727You can set breakpoints in functions in unmapped overlays, as long as
15728@value{GDBN} can write to the overlay at its load address.
15729@item
15730@value{GDBN} can not set hardware or simulator-based breakpoints in
15731unmapped overlays. However, if you set a breakpoint at the end of your
15732overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15733you are using manual overlay management), @value{GDBN} will re-set its
15734breakpoints properly.
15735@end itemize
15736
15737
15738@node Automatic Overlay Debugging
15739@section Automatic Overlay Debugging
15740@cindex automatic overlay debugging
15741
15742@value{GDBN} can automatically track which overlays are mapped and which
15743are not, given some simple co-operation from the overlay manager in the
15744inferior. If you enable automatic overlay debugging with the
15745@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15746looks in the inferior's memory for certain variables describing the
15747current state of the overlays.
15748
15749Here are the variables your overlay manager must define to support
15750@value{GDBN}'s automatic overlay debugging:
15751
15752@table @asis
15753
15754@item @code{_ovly_table}:
15755This variable must be an array of the following structures:
15756
474c8240 15757@smallexample
df0cd8c5
JB
15758struct
15759@{
15760 /* The overlay's mapped address. */
15761 unsigned long vma;
15762
15763 /* The size of the overlay, in bytes. */
15764 unsigned long size;
15765
15766 /* The overlay's load address. */
15767 unsigned long lma;
15768
15769 /* Non-zero if the overlay is currently mapped;
15770 zero otherwise. */
15771 unsigned long mapped;
15772@}
474c8240 15773@end smallexample
df0cd8c5
JB
15774
15775@item @code{_novlys}:
15776This variable must be a four-byte signed integer, holding the total
15777number of elements in @code{_ovly_table}.
15778
15779@end table
15780
15781To decide whether a particular overlay is mapped or not, @value{GDBN}
15782looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15783@code{lma} members equal the VMA and LMA of the overlay's section in the
15784executable file. When @value{GDBN} finds a matching entry, it consults
15785the entry's @code{mapped} member to determine whether the overlay is
15786currently mapped.
15787
81d46470 15788In addition, your overlay manager may define a function called
def71bfa 15789@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15790will silently set a breakpoint there. If the overlay manager then
15791calls this function whenever it has changed the overlay table, this
15792will enable @value{GDBN} to accurately keep track of which overlays
15793are in program memory, and update any breakpoints that may be set
b383017d 15794in overlays. This will allow breakpoints to work even if the
81d46470
MS
15795overlays are kept in ROM or other non-writable memory while they
15796are not being executed.
df0cd8c5
JB
15797
15798@node Overlay Sample Program
15799@section Overlay Sample Program
15800@cindex overlay example program
15801
15802When linking a program which uses overlays, you must place the overlays
15803at their load addresses, while relocating them to run at their mapped
15804addresses. To do this, you must write a linker script (@pxref{Overlay
15805Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15806since linker scripts are specific to a particular host system, target
15807architecture, and target memory layout, this manual cannot provide
15808portable sample code demonstrating @value{GDBN}'s overlay support.
15809
15810However, the @value{GDBN} source distribution does contain an overlaid
15811program, with linker scripts for a few systems, as part of its test
15812suite. The program consists of the following files from
15813@file{gdb/testsuite/gdb.base}:
15814
15815@table @file
15816@item overlays.c
15817The main program file.
15818@item ovlymgr.c
15819A simple overlay manager, used by @file{overlays.c}.
15820@item foo.c
15821@itemx bar.c
15822@itemx baz.c
15823@itemx grbx.c
15824Overlay modules, loaded and used by @file{overlays.c}.
15825@item d10v.ld
15826@itemx m32r.ld
15827Linker scripts for linking the test program on the @code{d10v-elf}
15828and @code{m32r-elf} targets.
15829@end table
15830
15831You can build the test program using the @code{d10v-elf} GCC
15832cross-compiler like this:
15833
474c8240 15834@smallexample
df0cd8c5
JB
15835$ d10v-elf-gcc -g -c overlays.c
15836$ d10v-elf-gcc -g -c ovlymgr.c
15837$ d10v-elf-gcc -g -c foo.c
15838$ d10v-elf-gcc -g -c bar.c
15839$ d10v-elf-gcc -g -c baz.c
15840$ d10v-elf-gcc -g -c grbx.c
15841$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15842 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15843@end smallexample
df0cd8c5
JB
15844
15845The build process is identical for any other architecture, except that
15846you must substitute the appropriate compiler and linker script for the
15847target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15848
15849
6d2ebf8b 15850@node Languages
c906108c
SS
15851@chapter Using @value{GDBN} with Different Languages
15852@cindex languages
15853
c906108c
SS
15854Although programming languages generally have common aspects, they are
15855rarely expressed in the same manner. For instance, in ANSI C,
15856dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15857Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15858represented (and displayed) differently. Hex numbers in C appear as
c906108c 15859@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15860
15861@cindex working language
15862Language-specific information is built into @value{GDBN} for some languages,
15863allowing you to express operations like the above in your program's
15864native language, and allowing @value{GDBN} to output values in a manner
15865consistent with the syntax of your program's native language. The
15866language you use to build expressions is called the @dfn{working
15867language}.
15868
15869@menu
15870* Setting:: Switching between source languages
15871* Show:: Displaying the language
c906108c 15872* Checks:: Type and range checks
79a6e687
BW
15873* Supported Languages:: Supported languages
15874* Unsupported Languages:: Unsupported languages
c906108c
SS
15875@end menu
15876
6d2ebf8b 15877@node Setting
79a6e687 15878@section Switching Between Source Languages
c906108c
SS
15879
15880There are two ways to control the working language---either have @value{GDBN}
15881set it automatically, or select it manually yourself. You can use the
15882@code{set language} command for either purpose. On startup, @value{GDBN}
15883defaults to setting the language automatically. The working language is
15884used to determine how expressions you type are interpreted, how values
15885are printed, etc.
15886
15887In addition to the working language, every source file that
15888@value{GDBN} knows about has its own working language. For some object
15889file formats, the compiler might indicate which language a particular
15890source file is in. However, most of the time @value{GDBN} infers the
15891language from the name of the file. The language of a source file
b37052ae 15892controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15893show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15894set the language of a source file from within @value{GDBN}, but you can
15895set the language associated with a filename extension. @xref{Show, ,
79a6e687 15896Displaying the Language}.
c906108c
SS
15897
15898This is most commonly a problem when you use a program, such
5d161b24 15899as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15900another language. In that case, make the
15901program use @code{#line} directives in its C output; that way
15902@value{GDBN} will know the correct language of the source code of the original
15903program, and will display that source code, not the generated C code.
15904
15905@menu
15906* Filenames:: Filename extensions and languages.
15907* Manually:: Setting the working language manually
15908* Automatically:: Having @value{GDBN} infer the source language
15909@end menu
15910
6d2ebf8b 15911@node Filenames
79a6e687 15912@subsection List of Filename Extensions and Languages
c906108c
SS
15913
15914If a source file name ends in one of the following extensions, then
15915@value{GDBN} infers that its language is the one indicated.
15916
15917@table @file
e07c999f
PH
15918@item .ada
15919@itemx .ads
15920@itemx .adb
15921@itemx .a
15922Ada source file.
c906108c
SS
15923
15924@item .c
15925C source file
15926
15927@item .C
15928@itemx .cc
15929@itemx .cp
15930@itemx .cpp
15931@itemx .cxx
15932@itemx .c++
b37052ae 15933C@t{++} source file
c906108c 15934
6aecb9c2
JB
15935@item .d
15936D source file
15937
b37303ee
AF
15938@item .m
15939Objective-C source file
15940
c906108c
SS
15941@item .f
15942@itemx .F
15943Fortran source file
15944
c906108c
SS
15945@item .mod
15946Modula-2 source file
c906108c
SS
15947
15948@item .s
15949@itemx .S
15950Assembler source file. This actually behaves almost like C, but
15951@value{GDBN} does not skip over function prologues when stepping.
15952@end table
15953
15954In addition, you may set the language associated with a filename
79a6e687 15955extension. @xref{Show, , Displaying the Language}.
c906108c 15956
6d2ebf8b 15957@node Manually
79a6e687 15958@subsection Setting the Working Language
c906108c
SS
15959
15960If you allow @value{GDBN} to set the language automatically,
15961expressions are interpreted the same way in your debugging session and
15962your program.
15963
15964@kindex set language
15965If you wish, you may set the language manually. To do this, issue the
15966command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15967a language, such as
c906108c 15968@code{c} or @code{modula-2}.
c906108c
SS
15969For a list of the supported languages, type @samp{set language}.
15970
c906108c
SS
15971Setting the language manually prevents @value{GDBN} from updating the working
15972language automatically. This can lead to confusion if you try
15973to debug a program when the working language is not the same as the
15974source language, when an expression is acceptable to both
15975languages---but means different things. For instance, if the current
15976source file were written in C, and @value{GDBN} was parsing Modula-2, a
15977command such as:
15978
474c8240 15979@smallexample
c906108c 15980print a = b + c
474c8240 15981@end smallexample
c906108c
SS
15982
15983@noindent
15984might not have the effect you intended. In C, this means to add
15985@code{b} and @code{c} and place the result in @code{a}. The result
15986printed would be the value of @code{a}. In Modula-2, this means to compare
15987@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15988
6d2ebf8b 15989@node Automatically
79a6e687 15990@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15991
15992To have @value{GDBN} set the working language automatically, use
15993@samp{set language local} or @samp{set language auto}. @value{GDBN}
15994then infers the working language. That is, when your program stops in a
15995frame (usually by encountering a breakpoint), @value{GDBN} sets the
15996working language to the language recorded for the function in that
15997frame. If the language for a frame is unknown (that is, if the function
15998or block corresponding to the frame was defined in a source file that
15999does not have a recognized extension), the current working language is
16000not changed, and @value{GDBN} issues a warning.
16001
16002This may not seem necessary for most programs, which are written
16003entirely in one source language. However, program modules and libraries
16004written in one source language can be used by a main program written in
16005a different source language. Using @samp{set language auto} in this
16006case frees you from having to set the working language manually.
16007
6d2ebf8b 16008@node Show
79a6e687 16009@section Displaying the Language
c906108c
SS
16010
16011The following commands help you find out which language is the
16012working language, and also what language source files were written in.
16013
c906108c
SS
16014@table @code
16015@item show language
403cb6b1 16016@anchor{show language}
9c16f35a 16017@kindex show language
c906108c
SS
16018Display the current working language. This is the
16019language you can use with commands such as @code{print} to
16020build and compute expressions that may involve variables in your program.
16021
16022@item info frame
4644b6e3 16023@kindex info frame@r{, show the source language}
5d161b24 16024Display the source language for this frame. This language becomes the
c906108c 16025working language if you use an identifier from this frame.
79a6e687 16026@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
16027information listed here.
16028
16029@item info source
4644b6e3 16030@kindex info source@r{, show the source language}
c906108c 16031Display the source language of this source file.
5d161b24 16032@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
16033information listed here.
16034@end table
16035
16036In unusual circumstances, you may have source files with extensions
16037not in the standard list. You can then set the extension associated
16038with a language explicitly:
16039
c906108c 16040@table @code
09d4efe1 16041@item set extension-language @var{ext} @var{language}
9c16f35a 16042@kindex set extension-language
09d4efe1
EZ
16043Tell @value{GDBN} that source files with extension @var{ext} are to be
16044assumed as written in the source language @var{language}.
c906108c
SS
16045
16046@item info extensions
9c16f35a 16047@kindex info extensions
c906108c
SS
16048List all the filename extensions and the associated languages.
16049@end table
16050
6d2ebf8b 16051@node Checks
79a6e687 16052@section Type and Range Checking
c906108c 16053
c906108c
SS
16054Some languages are designed to guard you against making seemingly common
16055errors through a series of compile- and run-time checks. These include
a451cb65 16056checking the type of arguments to functions and operators and making
c906108c
SS
16057sure mathematical overflows are caught at run time. Checks such as
16058these help to ensure a program's correctness once it has been compiled
a451cb65 16059by eliminating type mismatches and providing active checks for range
c906108c
SS
16060errors when your program is running.
16061
a451cb65
KS
16062By default @value{GDBN} checks for these errors according to the
16063rules of the current source language. Although @value{GDBN} does not check
16064the statements in your program, it can check expressions entered directly
16065into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
16066
16067@menu
16068* Type Checking:: An overview of type checking
16069* Range Checking:: An overview of range checking
16070@end menu
16071
16072@cindex type checking
16073@cindex checks, type
6d2ebf8b 16074@node Type Checking
79a6e687 16075@subsection An Overview of Type Checking
c906108c 16076
a451cb65 16077Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
16078arguments to operators and functions have to be of the correct type,
16079otherwise an error occurs. These checks prevent type mismatch
16080errors from ever causing any run-time problems. For example,
16081
16082@smallexample
a451cb65
KS
16083int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16084
16085(@value{GDBP}) print obj.my_method (0)
16086$1 = 2
c906108c 16087@exdent but
a451cb65
KS
16088(@value{GDBP}) print obj.my_method (0x1234)
16089Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
16090@end smallexample
16091
a451cb65
KS
16092The second example fails because in C@t{++} the integer constant
16093@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 16094
a451cb65
KS
16095For the expressions you use in @value{GDBN} commands, you can tell
16096@value{GDBN} to not enforce strict type checking or
5d161b24 16097to treat any mismatches as errors and abandon the expression;
a451cb65
KS
16098When type checking is disabled, @value{GDBN} successfully evaluates
16099expressions like the second example above.
c906108c 16100
a451cb65 16101Even if type checking is off, there may be other reasons
5d161b24
DB
16102related to type that prevent @value{GDBN} from evaluating an expression.
16103For instance, @value{GDBN} does not know how to add an @code{int} and
16104a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
16105with the language in use and usually arise from expressions which make
16106little sense to evaluate anyway.
c906108c 16107
a451cb65 16108@value{GDBN} provides some additional commands for controlling type checking:
c906108c 16109
c906108c
SS
16110@kindex set check type
16111@kindex show check type
16112@table @code
c906108c
SS
16113@item set check type on
16114@itemx set check type off
a451cb65 16115Set strict type checking on or off. If any type mismatches occur in
d4f3574e 16116evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
16117message and aborts evaluation of the expression.
16118
a451cb65
KS
16119@item show check type
16120Show the current setting of type checking and whether @value{GDBN}
16121is enforcing strict type checking rules.
c906108c
SS
16122@end table
16123
16124@cindex range checking
16125@cindex checks, range
6d2ebf8b 16126@node Range Checking
79a6e687 16127@subsection An Overview of Range Checking
c906108c
SS
16128
16129In some languages (such as Modula-2), it is an error to exceed the
16130bounds of a type; this is enforced with run-time checks. Such range
16131checking is meant to ensure program correctness by making sure
16132computations do not overflow, or indices on an array element access do
16133not exceed the bounds of the array.
16134
16135For expressions you use in @value{GDBN} commands, you can tell
16136@value{GDBN} to treat range errors in one of three ways: ignore them,
16137always treat them as errors and abandon the expression, or issue
16138warnings but evaluate the expression anyway.
16139
16140A range error can result from numerical overflow, from exceeding an
16141array index bound, or when you type a constant that is not a member
16142of any type. Some languages, however, do not treat overflows as an
16143error. In many implementations of C, mathematical overflow causes the
16144result to ``wrap around'' to lower values---for example, if @var{m} is
16145the largest integer value, and @var{s} is the smallest, then
16146
474c8240 16147@smallexample
c906108c 16148@var{m} + 1 @result{} @var{s}
474c8240 16149@end smallexample
c906108c
SS
16150
16151This, too, is specific to individual languages, and in some cases
79a6e687
BW
16152specific to individual compilers or machines. @xref{Supported Languages, ,
16153Supported Languages}, for further details on specific languages.
c906108c
SS
16154
16155@value{GDBN} provides some additional commands for controlling the range checker:
16156
c906108c
SS
16157@kindex set check range
16158@kindex show check range
16159@table @code
16160@item set check range auto
16161Set range checking on or off based on the current working language.
79a6e687 16162@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
16163each language.
16164
16165@item set check range on
16166@itemx set check range off
16167Set range checking on or off, overriding the default setting for the
16168current working language. A warning is issued if the setting does not
c3f6f71d
JM
16169match the language default. If a range error occurs and range checking is on,
16170then a message is printed and evaluation of the expression is aborted.
c906108c
SS
16171
16172@item set check range warn
16173Output messages when the @value{GDBN} range checker detects a range error,
16174but attempt to evaluate the expression anyway. Evaluating the
16175expression may still be impossible for other reasons, such as accessing
16176memory that the process does not own (a typical example from many Unix
16177systems).
16178
85be4f5a 16179@item show check range
c906108c
SS
16180Show the current setting of the range checker, and whether or not it is
16181being set automatically by @value{GDBN}.
16182@end table
c906108c 16183
79a6e687
BW
16184@node Supported Languages
16185@section Supported Languages
c906108c 16186
9c37b5ae 16187@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 16188OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 16189@c This is false ...
c906108c
SS
16190Some @value{GDBN} features may be used in expressions regardless of the
16191language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16192and the @samp{@{type@}addr} construct (@pxref{Expressions,
16193,Expressions}) can be used with the constructs of any supported
16194language.
16195
16196The following sections detail to what degree each source language is
16197supported by @value{GDBN}. These sections are not meant to be language
16198tutorials or references, but serve only as a reference guide to what the
16199@value{GDBN} expression parser accepts, and what input and output
16200formats should look like for different languages. There are many good
16201books written on each of these languages; please look to these for a
16202language reference or tutorial.
16203
c906108c 16204@menu
b37303ee 16205* C:: C and C@t{++}
6aecb9c2 16206* D:: D
a766d390 16207* Go:: Go
b383017d 16208* Objective-C:: Objective-C
f4b8a18d 16209* OpenCL C:: OpenCL C
09d4efe1 16210* Fortran:: Fortran
9c16f35a 16211* Pascal:: Pascal
0bdfa368 16212* Rust:: Rust
b37303ee 16213* Modula-2:: Modula-2
e07c999f 16214* Ada:: Ada
c906108c
SS
16215@end menu
16216
6d2ebf8b 16217@node C
b37052ae 16218@subsection C and C@t{++}
7a292a7a 16219
b37052ae
EZ
16220@cindex C and C@t{++}
16221@cindex expressions in C or C@t{++}
c906108c 16222
b37052ae 16223Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
16224to both languages. Whenever this is the case, we discuss those languages
16225together.
16226
41afff9a
EZ
16227@cindex C@t{++}
16228@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
16229@cindex @sc{gnu} C@t{++}
16230The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16231compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16232effectively, you must compile your C@t{++} programs with a supported
16233C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
16234compiler (@code{aCC}).
16235
c906108c 16236@menu
b37052ae
EZ
16237* C Operators:: C and C@t{++} operators
16238* C Constants:: C and C@t{++} constants
79a6e687 16239* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
16240* C Defaults:: Default settings for C and C@t{++}
16241* C Checks:: C and C@t{++} type and range checks
c906108c 16242* Debugging C:: @value{GDBN} and C
79a6e687 16243* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 16244* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 16245@end menu
c906108c 16246
6d2ebf8b 16247@node C Operators
79a6e687 16248@subsubsection C and C@t{++} Operators
7a292a7a 16249
b37052ae 16250@cindex C and C@t{++} operators
c906108c
SS
16251
16252Operators must be defined on values of specific types. For instance,
16253@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16254often defined on groups of types.
c906108c 16255
b37052ae 16256For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16257
16258@itemize @bullet
53a5351d 16259
c906108c 16260@item
c906108c 16261@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16262specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16263
16264@item
d4f3574e
SS
16265@emph{Floating-point types} include @code{float}, @code{double}, and
16266@code{long double} (if supported by the target platform).
c906108c
SS
16267
16268@item
53a5351d 16269@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16270
16271@item
16272@emph{Scalar types} include all of the above.
53a5351d 16273
c906108c
SS
16274@end itemize
16275
16276@noindent
16277The following operators are supported. They are listed here
16278in order of increasing precedence:
16279
16280@table @code
16281@item ,
16282The comma or sequencing operator. Expressions in a comma-separated list
16283are evaluated from left to right, with the result of the entire
16284expression being the last expression evaluated.
16285
16286@item =
16287Assignment. The value of an assignment expression is the value
16288assigned. Defined on scalar types.
16289
16290@item @var{op}=
16291Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16292and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16293@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16294@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16295@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16296
16297@item ?:
16298The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16299of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16300should be of an integral type.
c906108c
SS
16301
16302@item ||
16303Logical @sc{or}. Defined on integral types.
16304
16305@item &&
16306Logical @sc{and}. Defined on integral types.
16307
16308@item |
16309Bitwise @sc{or}. Defined on integral types.
16310
16311@item ^
16312Bitwise exclusive-@sc{or}. Defined on integral types.
16313
16314@item &
16315Bitwise @sc{and}. Defined on integral types.
16316
16317@item ==@r{, }!=
16318Equality and inequality. Defined on scalar types. The value of these
16319expressions is 0 for false and non-zero for true.
16320
16321@item <@r{, }>@r{, }<=@r{, }>=
16322Less than, greater than, less than or equal, greater than or equal.
16323Defined on scalar types. The value of these expressions is 0 for false
16324and non-zero for true.
16325
16326@item <<@r{, }>>
16327left shift, and right shift. Defined on integral types.
16328
16329@item @@
16330The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16331
16332@item +@r{, }-
16333Addition and subtraction. Defined on integral types, floating-point types and
16334pointer types.
16335
16336@item *@r{, }/@r{, }%
16337Multiplication, division, and modulus. Multiplication and division are
16338defined on integral and floating-point types. Modulus is defined on
16339integral types.
16340
16341@item ++@r{, }--
16342Increment and decrement. When appearing before a variable, the
16343operation is performed before the variable is used in an expression;
16344when appearing after it, the variable's value is used before the
16345operation takes place.
16346
16347@item *
16348Pointer dereferencing. Defined on pointer types. Same precedence as
16349@code{++}.
16350
16351@item &
16352Address operator. Defined on variables. Same precedence as @code{++}.
16353
b37052ae
EZ
16354For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16355allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16356to examine the address
b37052ae 16357where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16358stored.
c906108c
SS
16359
16360@item -
16361Negative. Defined on integral and floating-point types. Same
16362precedence as @code{++}.
16363
16364@item !
16365Logical negation. Defined on integral types. Same precedence as
16366@code{++}.
16367
16368@item ~
16369Bitwise complement operator. Defined on integral types. Same precedence as
16370@code{++}.
16371
16372
16373@item .@r{, }->
16374Structure member, and pointer-to-structure member. For convenience,
16375@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16376pointer based on the stored type information.
16377Defined on @code{struct} and @code{union} data.
16378
c906108c
SS
16379@item .*@r{, }->*
16380Dereferences of pointers to members.
c906108c
SS
16381
16382@item []
16383Array indexing. @code{@var{a}[@var{i}]} is defined as
16384@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16385
16386@item ()
16387Function parameter list. Same precedence as @code{->}.
16388
c906108c 16389@item ::
b37052ae 16390C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16391and @code{class} types.
c906108c
SS
16392
16393@item ::
7a292a7a
SS
16394Doubled colons also represent the @value{GDBN} scope operator
16395(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16396above.
c906108c
SS
16397@end table
16398
c906108c
SS
16399If an operator is redefined in the user code, @value{GDBN} usually
16400attempts to invoke the redefined version instead of using the operator's
16401predefined meaning.
c906108c 16402
6d2ebf8b 16403@node C Constants
79a6e687 16404@subsubsection C and C@t{++} Constants
c906108c 16405
b37052ae 16406@cindex C and C@t{++} constants
c906108c 16407
b37052ae 16408@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16409following ways:
c906108c
SS
16410
16411@itemize @bullet
16412@item
16413Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16414specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16415by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16416@samp{l}, specifying that the constant should be treated as a
16417@code{long} value.
16418
16419@item
16420Floating point constants are a sequence of digits, followed by a decimal
16421point, followed by a sequence of digits, and optionally followed by an
16422exponent. An exponent is of the form:
16423@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16424sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16425A floating-point constant may also end with a letter @samp{f} or
16426@samp{F}, specifying that the constant should be treated as being of
16427the @code{float} (as opposed to the default @code{double}) type; or with
16428a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16429constant.
c906108c
SS
16430
16431@item
16432Enumerated constants consist of enumerated identifiers, or their
16433integral equivalents.
16434
16435@item
16436Character constants are a single character surrounded by single quotes
16437(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16438(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16439be represented by a letter or by @dfn{escape sequences}, which are of
16440the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16441of the character's ordinal value; or of the form @samp{\@var{x}}, where
16442@samp{@var{x}} is a predefined special character---for example,
16443@samp{\n} for newline.
16444
e0f8f636
TT
16445Wide character constants can be written by prefixing a character
16446constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16447form of @samp{x}. The target wide character set is used when
16448computing the value of this constant (@pxref{Character Sets}).
16449
c906108c 16450@item
96a2c332
SS
16451String constants are a sequence of character constants surrounded by
16452double quotes (@code{"}). Any valid character constant (as described
16453above) may appear. Double quotes within the string must be preceded by
16454a backslash, so for instance @samp{"a\"b'c"} is a string of five
16455characters.
c906108c 16456
e0f8f636
TT
16457Wide string constants can be written by prefixing a string constant
16458with @samp{L}, as in C. The target wide character set is used when
16459computing the value of this constant (@pxref{Character Sets}).
16460
c906108c
SS
16461@item
16462Pointer constants are an integral value. You can also write pointers
16463to constants using the C operator @samp{&}.
16464
16465@item
16466Array constants are comma-separated lists surrounded by braces @samp{@{}
16467and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16468integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16469and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16470@end itemize
16471
79a6e687
BW
16472@node C Plus Plus Expressions
16473@subsubsection C@t{++} Expressions
b37052ae
EZ
16474
16475@cindex expressions in C@t{++}
16476@value{GDBN} expression handling can interpret most C@t{++} expressions.
16477
0179ffac
DC
16478@cindex debugging C@t{++} programs
16479@cindex C@t{++} compilers
16480@cindex debug formats and C@t{++}
16481@cindex @value{NGCC} and C@t{++}
c906108c 16482@quotation
e0f8f636
TT
16483@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16484the proper compiler and the proper debug format. Currently,
16485@value{GDBN} works best when debugging C@t{++} code that is compiled
16486with the most recent version of @value{NGCC} possible. The DWARF
16487debugging format is preferred; @value{NGCC} defaults to this on most
16488popular platforms. Other compilers and/or debug formats are likely to
16489work badly or not at all when using @value{GDBN} to debug C@t{++}
16490code. @xref{Compilation}.
c906108c 16491@end quotation
c906108c
SS
16492
16493@enumerate
16494
16495@cindex member functions
16496@item
16497Member function calls are allowed; you can use expressions like
16498
474c8240 16499@smallexample
c906108c 16500count = aml->GetOriginal(x, y)
474c8240 16501@end smallexample
c906108c 16502
41afff9a 16503@vindex this@r{, inside C@t{++} member functions}
b37052ae 16504@cindex namespace in C@t{++}
c906108c
SS
16505@item
16506While a member function is active (in the selected stack frame), your
16507expressions have the same namespace available as the member function;
16508that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16509pointer @code{this} following the same rules as C@t{++}. @code{using}
16510declarations in the current scope are also respected by @value{GDBN}.
c906108c 16511
c906108c 16512@cindex call overloaded functions
d4f3574e 16513@cindex overloaded functions, calling
b37052ae 16514@cindex type conversions in C@t{++}
c906108c
SS
16515@item
16516You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16517call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16518perform overload resolution involving user-defined type conversions,
16519calls to constructors, or instantiations of templates that do not exist
16520in the program. It also cannot handle ellipsis argument lists or
16521default arguments.
16522
16523It does perform integral conversions and promotions, floating-point
16524promotions, arithmetic conversions, pointer conversions, conversions of
16525class objects to base classes, and standard conversions such as those of
16526functions or arrays to pointers; it requires an exact match on the
16527number of function arguments.
16528
16529Overload resolution is always performed, unless you have specified
79a6e687
BW
16530@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16531,@value{GDBN} Features for C@t{++}}.
c906108c 16532
d4f3574e 16533You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16534explicit function signature to call an overloaded function, as in
16535@smallexample
16536p 'foo(char,int)'('x', 13)
16537@end smallexample
d4f3574e 16538
c906108c 16539The @value{GDBN} command-completion facility can simplify this;
79a6e687 16540see @ref{Completion, ,Command Completion}.
c906108c 16541
c906108c
SS
16542@cindex reference declarations
16543@item
c0f55cc6
AV
16544@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16545references; you can use them in expressions just as you do in C@t{++}
16546source---they are automatically dereferenced.
c906108c
SS
16547
16548In the parameter list shown when @value{GDBN} displays a frame, the values of
16549reference variables are not displayed (unlike other variables); this
16550avoids clutter, since references are often used for large structures.
16551The @emph{address} of a reference variable is always shown, unless
16552you have specified @samp{set print address off}.
16553
16554@item
b37052ae 16555@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16556expressions can use it just as expressions in your program do. Since
16557one scope may be defined in another, you can use @code{::} repeatedly if
16558necessary, for example in an expression like
16559@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16560resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16561debugging (@pxref{Variables, ,Program Variables}).
c906108c 16562
e0f8f636
TT
16563@item
16564@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16565specification.
16566@end enumerate
c906108c 16567
6d2ebf8b 16568@node C Defaults
79a6e687 16569@subsubsection C and C@t{++} Defaults
7a292a7a 16570
b37052ae 16571@cindex C and C@t{++} defaults
c906108c 16572
a451cb65
KS
16573If you allow @value{GDBN} to set range checking automatically, it
16574defaults to @code{off} whenever the working language changes to
b37052ae 16575C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16576selects the working language.
c906108c
SS
16577
16578If you allow @value{GDBN} to set the language automatically, it
16579recognizes source files whose names end with @file{.c}, @file{.C}, or
16580@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16581these files, it sets the working language to C or C@t{++}.
79a6e687 16582@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16583for further details.
16584
6d2ebf8b 16585@node C Checks
79a6e687 16586@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16587
b37052ae 16588@cindex C and C@t{++} checks
c906108c 16589
a451cb65
KS
16590By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16591checking is used. However, if you turn type checking off, @value{GDBN}
16592will allow certain non-standard conversions, such as promoting integer
16593constants to pointers.
c906108c
SS
16594
16595Range checking, if turned on, is done on mathematical operations. Array
16596indices are not checked, since they are often used to index a pointer
16597that is not itself an array.
c906108c 16598
6d2ebf8b 16599@node Debugging C
c906108c 16600@subsubsection @value{GDBN} and C
c906108c
SS
16601
16602The @code{set print union} and @code{show print union} commands apply to
16603the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16604inside a @code{struct} or @code{class} is also printed. Otherwise, it
16605appears as @samp{@{...@}}.
c906108c
SS
16606
16607The @code{@@} operator aids in the debugging of dynamic arrays, formed
16608with pointers and a memory allocation function. @xref{Expressions,
16609,Expressions}.
16610
79a6e687
BW
16611@node Debugging C Plus Plus
16612@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16613
b37052ae 16614@cindex commands for C@t{++}
7a292a7a 16615
b37052ae
EZ
16616Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16617designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16618
16619@table @code
16620@cindex break in overloaded functions
16621@item @r{breakpoint menus}
16622When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16623@value{GDBN} has the capability to display a menu of possible breakpoint
16624locations to help you specify which function definition you want.
16625@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16626
b37052ae 16627@cindex overloading in C@t{++}
c906108c
SS
16628@item rbreak @var{regex}
16629Setting breakpoints using regular expressions is helpful for setting
16630breakpoints on overloaded functions that are not members of any special
16631classes.
79a6e687 16632@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16633
b37052ae 16634@cindex C@t{++} exception handling
c906108c 16635@item catch throw
591f19e8 16636@itemx catch rethrow
c906108c 16637@itemx catch catch
b37052ae 16638Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16639Catchpoints, , Setting Catchpoints}.
c906108c
SS
16640
16641@cindex inheritance
16642@item ptype @var{typename}
16643Print inheritance relationships as well as other information for type
16644@var{typename}.
16645@xref{Symbols, ,Examining the Symbol Table}.
16646
c4aeac85
TT
16647@item info vtbl @var{expression}.
16648The @code{info vtbl} command can be used to display the virtual
16649method tables of the object computed by @var{expression}. This shows
16650one entry per virtual table; there may be multiple virtual tables when
16651multiple inheritance is in use.
16652
439250fb
DE
16653@cindex C@t{++} demangling
16654@item demangle @var{name}
16655Demangle @var{name}.
16656@xref{Symbols}, for a more complete description of the @code{demangle} command.
16657
b37052ae 16658@cindex C@t{++} symbol display
c906108c
SS
16659@item set print demangle
16660@itemx show print demangle
16661@itemx set print asm-demangle
16662@itemx show print asm-demangle
b37052ae
EZ
16663Control whether C@t{++} symbols display in their source form, both when
16664displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16665@xref{Print Settings, ,Print Settings}.
c906108c
SS
16666
16667@item set print object
16668@itemx show print object
16669Choose whether to print derived (actual) or declared types of objects.
79a6e687 16670@xref{Print Settings, ,Print Settings}.
c906108c
SS
16671
16672@item set print vtbl
16673@itemx show print vtbl
16674Control the format for printing virtual function tables.
79a6e687 16675@xref{Print Settings, ,Print Settings}.
c906108c 16676(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16677ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16678
16679@kindex set overload-resolution
d4f3574e 16680@cindex overloaded functions, overload resolution
c906108c 16681@item set overload-resolution on
b37052ae 16682Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16683is on. For overloaded functions, @value{GDBN} evaluates the arguments
16684and searches for a function whose signature matches the argument types,
79a6e687
BW
16685using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16686Expressions, ,C@t{++} Expressions}, for details).
16687If it cannot find a match, it emits a message.
c906108c
SS
16688
16689@item set overload-resolution off
b37052ae 16690Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16691overloaded functions that are not class member functions, @value{GDBN}
16692chooses the first function of the specified name that it finds in the
16693symbol table, whether or not its arguments are of the correct type. For
16694overloaded functions that are class member functions, @value{GDBN}
16695searches for a function whose signature @emph{exactly} matches the
16696argument types.
c906108c 16697
9c16f35a
EZ
16698@kindex show overload-resolution
16699@item show overload-resolution
16700Show the current setting of overload resolution.
16701
c906108c
SS
16702@item @r{Overloaded symbol names}
16703You can specify a particular definition of an overloaded symbol, using
b37052ae 16704the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16705@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16706also use the @value{GDBN} command-line word completion facilities to list the
16707available choices, or to finish the type list for you.
79a6e687 16708@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16709
16710@item @r{Breakpoints in functions with ABI tags}
16711
16712The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16713correspond to changes in the ABI of a type, function, or variable that
16714would not otherwise be reflected in a mangled name. See
16715@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16716for more detail.
16717
16718The ABI tags are visible in C@t{++} demangled names. For example, a
16719function that returns a std::string:
16720
16721@smallexample
16722std::string function(int);
16723@end smallexample
16724
16725@noindent
16726when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16727tag, and @value{GDBN} displays the symbol like this:
16728
16729@smallexample
16730function[abi:cxx11](int)
16731@end smallexample
16732
16733You can set a breakpoint on such functions simply as if they had no
16734tag. For example:
16735
16736@smallexample
16737(gdb) b function(int)
16738Breakpoint 2 at 0x40060d: file main.cc, line 10.
16739(gdb) info breakpoints
16740Num Type Disp Enb Address What
167411 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16742 at main.cc:10
16743@end smallexample
16744
16745On the rare occasion you need to disambiguate between different ABI
16746tags, you can do so by simply including the ABI tag in the function
16747name, like:
16748
16749@smallexample
16750(@value{GDBP}) b ambiguous[abi:other_tag](int)
16751@end smallexample
c906108c 16752@end table
c906108c 16753
febe4383
TJB
16754@node Decimal Floating Point
16755@subsubsection Decimal Floating Point format
16756@cindex decimal floating point format
16757
16758@value{GDBN} can examine, set and perform computations with numbers in
16759decimal floating point format, which in the C language correspond to the
16760@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16761specified by the extension to support decimal floating-point arithmetic.
16762
16763There are two encodings in use, depending on the architecture: BID (Binary
16764Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16765PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16766configured target.
febe4383
TJB
16767
16768Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16769to manipulate decimal floating point numbers, it is not possible to convert
16770(using a cast, for example) integers wider than 32-bit to decimal float.
16771
16772In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16773point computations, error checking in decimal float operations ignores
16774underflow, overflow and divide by zero exceptions.
16775
4acd40f3 16776In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16777to inspect @code{_Decimal128} values stored in floating point registers.
16778See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16779
6aecb9c2
JB
16780@node D
16781@subsection D
16782
16783@cindex D
16784@value{GDBN} can be used to debug programs written in D and compiled with
16785GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16786specific feature --- dynamic arrays.
16787
a766d390
DE
16788@node Go
16789@subsection Go
16790
16791@cindex Go (programming language)
16792@value{GDBN} can be used to debug programs written in Go and compiled with
16793@file{gccgo} or @file{6g} compilers.
16794
16795Here is a summary of the Go-specific features and restrictions:
16796
16797@table @code
16798@cindex current Go package
16799@item The current Go package
16800The name of the current package does not need to be specified when
16801specifying global variables and functions.
16802
16803For example, given the program:
16804
16805@example
16806package main
16807var myglob = "Shall we?"
16808func main () @{
16809 // ...
16810@}
16811@end example
16812
16813When stopped inside @code{main} either of these work:
16814
16815@example
16816(gdb) p myglob
16817(gdb) p main.myglob
16818@end example
16819
16820@cindex builtin Go types
16821@item Builtin Go types
16822The @code{string} type is recognized by @value{GDBN} and is printed
16823as a string.
16824
16825@cindex builtin Go functions
16826@item Builtin Go functions
16827The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16828function and handles it internally.
a766d390
DE
16829
16830@cindex restrictions on Go expressions
16831@item Restrictions on Go expressions
16832All Go operators are supported except @code{&^}.
16833The Go @code{_} ``blank identifier'' is not supported.
16834Automatic dereferencing of pointers is not supported.
50f042b9 16835@end table
a766d390 16836
b37303ee
AF
16837@node Objective-C
16838@subsection Objective-C
16839
16840@cindex Objective-C
16841This section provides information about some commands and command
721c2651
EZ
16842options that are useful for debugging Objective-C code. See also
16843@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16844few more commands specific to Objective-C support.
b37303ee
AF
16845
16846@menu
b383017d
RM
16847* Method Names in Commands::
16848* The Print Command with Objective-C::
b37303ee
AF
16849@end menu
16850
c8f4133a 16851@node Method Names in Commands
b37303ee
AF
16852@subsubsection Method Names in Commands
16853
16854The following commands have been extended to accept Objective-C method
16855names as line specifications:
16856
16857@kindex clear@r{, and Objective-C}
16858@kindex break@r{, and Objective-C}
16859@kindex info line@r{, and Objective-C}
16860@kindex jump@r{, and Objective-C}
16861@kindex list@r{, and Objective-C}
16862@itemize
16863@item @code{clear}
16864@item @code{break}
16865@item @code{info line}
16866@item @code{jump}
16867@item @code{list}
16868@end itemize
16869
16870A fully qualified Objective-C method name is specified as
16871
16872@smallexample
16873-[@var{Class} @var{methodName}]
16874@end smallexample
16875
c552b3bb
JM
16876where the minus sign is used to indicate an instance method and a
16877plus sign (not shown) is used to indicate a class method. The class
16878name @var{Class} and method name @var{methodName} are enclosed in
16879brackets, similar to the way messages are specified in Objective-C
16880source code. For example, to set a breakpoint at the @code{create}
16881instance method of class @code{Fruit} in the program currently being
16882debugged, enter:
b37303ee
AF
16883
16884@smallexample
16885break -[Fruit create]
16886@end smallexample
16887
16888To list ten program lines around the @code{initialize} class method,
16889enter:
16890
16891@smallexample
16892list +[NSText initialize]
16893@end smallexample
16894
c552b3bb
JM
16895In the current version of @value{GDBN}, the plus or minus sign is
16896required. In future versions of @value{GDBN}, the plus or minus
16897sign will be optional, but you can use it to narrow the search. It
16898is also possible to specify just a method name:
b37303ee
AF
16899
16900@smallexample
16901break create
16902@end smallexample
16903
16904You must specify the complete method name, including any colons. If
16905your program's source files contain more than one @code{create} method,
16906you'll be presented with a numbered list of classes that implement that
16907method. Indicate your choice by number, or type @samp{0} to exit if
16908none apply.
16909
16910As another example, to clear a breakpoint established at the
16911@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16912
16913@smallexample
16914clear -[NSWindow makeKeyAndOrderFront:]
16915@end smallexample
16916
16917@node The Print Command with Objective-C
16918@subsubsection The Print Command With Objective-C
721c2651 16919@cindex Objective-C, print objects
c552b3bb
JM
16920@kindex print-object
16921@kindex po @r{(@code{print-object})}
b37303ee 16922
c552b3bb 16923The print command has also been extended to accept methods. For example:
b37303ee
AF
16924
16925@smallexample
c552b3bb 16926print -[@var{object} hash]
b37303ee
AF
16927@end smallexample
16928
16929@cindex print an Objective-C object description
c552b3bb
JM
16930@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16931@noindent
16932will tell @value{GDBN} to send the @code{hash} message to @var{object}
16933and print the result. Also, an additional command has been added,
16934@code{print-object} or @code{po} for short, which is meant to print
16935the description of an object. However, this command may only work
16936with certain Objective-C libraries that have a particular hook
16937function, @code{_NSPrintForDebugger}, defined.
b37303ee 16938
f4b8a18d
KW
16939@node OpenCL C
16940@subsection OpenCL C
16941
16942@cindex OpenCL C
16943This section provides information about @value{GDBN}s OpenCL C support.
16944
16945@menu
16946* OpenCL C Datatypes::
16947* OpenCL C Expressions::
16948* OpenCL C Operators::
16949@end menu
16950
16951@node OpenCL C Datatypes
16952@subsubsection OpenCL C Datatypes
16953
16954@cindex OpenCL C Datatypes
16955@value{GDBN} supports the builtin scalar and vector datatypes specified
16956by OpenCL 1.1. In addition the half- and double-precision floating point
16957data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16958extensions are also known to @value{GDBN}.
16959
16960@node OpenCL C Expressions
16961@subsubsection OpenCL C Expressions
16962
16963@cindex OpenCL C Expressions
16964@value{GDBN} supports accesses to vector components including the access as
16965lvalue where possible. Since OpenCL C is based on C99 most C expressions
16966supported by @value{GDBN} can be used as well.
16967
16968@node OpenCL C Operators
16969@subsubsection OpenCL C Operators
16970
16971@cindex OpenCL C Operators
16972@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16973vector data types.
16974
09d4efe1
EZ
16975@node Fortran
16976@subsection Fortran
16977@cindex Fortran-specific support in @value{GDBN}
16978
814e32d7
WZ
16979@value{GDBN} can be used to debug programs written in Fortran, but it
16980currently supports only the features of Fortran 77 language.
16981
16982@cindex trailing underscore, in Fortran symbols
16983Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16984among them) append an underscore to the names of variables and
16985functions. When you debug programs compiled by those compilers, you
16986will need to refer to variables and functions with a trailing
16987underscore.
16988
16989@menu
16990* Fortran Operators:: Fortran operators and expressions
16991* Fortran Defaults:: Default settings for Fortran
79a6e687 16992* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16993@end menu
16994
16995@node Fortran Operators
79a6e687 16996@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16997
16998@cindex Fortran operators and expressions
16999
17000Operators must be defined on values of specific types. For instance,
17001@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 17002arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
17003
17004@table @code
17005@item **
99e008fe 17006The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
17007of the second one.
17008
17009@item :
17010The range operator. Normally used in the form of array(low:high) to
17011represent a section of array.
68837c9d
MD
17012
17013@item %
17014The access component operator. Normally used to access elements in derived
17015types. Also suitable for unions. As unions aren't part of regular Fortran,
17016this can only happen when accessing a register that uses a gdbarch-defined
17017union type.
0a4b0913
AB
17018@item ::
17019The scope operator. Normally used to access variables in modules or
17020to set breakpoints on subroutines nested in modules or in other
17021subroutines (internal subroutines).
814e32d7
WZ
17022@end table
17023
17024@node Fortran Defaults
17025@subsubsection Fortran Defaults
17026
17027@cindex Fortran Defaults
17028
17029Fortran symbols are usually case-insensitive, so @value{GDBN} by
17030default uses case-insensitive matches for Fortran symbols. You can
17031change that with the @samp{set case-insensitive} command, see
17032@ref{Symbols}, for the details.
17033
79a6e687
BW
17034@node Special Fortran Commands
17035@subsubsection Special Fortran Commands
814e32d7
WZ
17036
17037@cindex Special Fortran commands
17038
db2e3e2e
BW
17039@value{GDBN} has some commands to support Fortran-specific features,
17040such as displaying common blocks.
814e32d7 17041
09d4efe1
EZ
17042@table @code
17043@cindex @code{COMMON} blocks, Fortran
17044@kindex info common
17045@item info common @r{[}@var{common-name}@r{]}
17046This command prints the values contained in the Fortran @code{COMMON}
17047block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 17048all @code{COMMON} blocks visible at the current program location are
09d4efe1 17049printed.
a5c641b5
AB
17050@cindex arrays slices (Fortran)
17051@kindex set fortran repack-array-slices
17052@kindex show fortran repack-array-slices
17053@item set fortran repack-array-slices [on|off]
17054@item show fortran repack-array-slices
17055When taking a slice from an array, a Fortran compiler can choose to
17056either produce an array descriptor that describes the slice in place,
17057or it may repack the slice, copying the elements of the slice into a
17058new region of memory.
17059
17060When this setting is on, then @value{GDBN} will also repack array
17061slices in some situations. When this setting is off, then
17062@value{GDBN} will create array descriptors for slices that reference
17063the original data in place.
17064
17065@value{GDBN} will never repack an array slice if the data for the
17066slice is contiguous within the original array.
17067
17068@value{GDBN} will always repack string slices if the data for the
17069slice is non-contiguous within the original string as @value{GDBN}
17070does not support printing non-contiguous strings.
17071
17072The default for this setting is @code{off}.
09d4efe1
EZ
17073@end table
17074
9c16f35a
EZ
17075@node Pascal
17076@subsection Pascal
17077
17078@cindex Pascal support in @value{GDBN}, limitations
17079Debugging Pascal programs which use sets, subranges, file variables, or
17080nested functions does not currently work. @value{GDBN} does not support
17081entering expressions, printing values, or similar features using Pascal
17082syntax.
17083
17084The Pascal-specific command @code{set print pascal_static-members}
17085controls whether static members of Pascal objects are displayed.
17086@xref{Print Settings, pascal_static-members}.
17087
0bdfa368
TT
17088@node Rust
17089@subsection Rust
17090
17091@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17092Programming Language}. Type- and value-printing, and expression
17093parsing, are reasonably complete. However, there are a few
17094peculiarities and holes to be aware of.
17095
17096@itemize @bullet
17097@item
17098Linespecs (@pxref{Specify Location}) are never relative to the current
17099crate. Instead, they act as if there were a global namespace of
17100crates, somewhat similar to the way @code{extern crate} behaves.
17101
17102That is, if @value{GDBN} is stopped at a breakpoint in a function in
17103crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17104to set a breakpoint in a function named @samp{f} in a crate named
17105@samp{B}.
17106
17107As a consequence of this approach, linespecs also cannot refer to
17108items using @samp{self::} or @samp{super::}.
17109
17110@item
17111Because @value{GDBN} implements Rust name-lookup semantics in
17112expressions, it will sometimes prepend the current crate to a name.
17113For example, if @value{GDBN} is stopped at a breakpoint in the crate
17114@samp{K}, then @code{print ::x::y} will try to find the symbol
17115@samp{K::x::y}.
17116
17117However, since it is useful to be able to refer to other crates when
17118debugging, @value{GDBN} provides the @code{extern} extension to
17119circumvent this. To use the extension, just put @code{extern} before
17120a path expression to refer to the otherwise unavailable ``global''
17121scope.
17122
17123In the above example, if you wanted to refer to the symbol @samp{y} in
17124the crate @samp{x}, you would use @code{print extern x::y}.
17125
17126@item
17127The Rust expression evaluator does not support ``statement-like''
17128expressions such as @code{if} or @code{match}, or lambda expressions.
17129
17130@item
17131Tuple expressions are not implemented.
17132
17133@item
17134The Rust expression evaluator does not currently implement the
17135@code{Drop} trait. Objects that may be created by the evaluator will
17136never be destroyed.
17137
17138@item
17139@value{GDBN} does not implement type inference for generics. In order
17140to call generic functions or otherwise refer to generic items, you
17141will have to specify the type parameters manually.
17142
17143@item
17144@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17145cases this does not cause any problems. However, in an expression
17146context, completing a generic function name will give syntactically
17147invalid results. This happens because Rust requires the @samp{::}
17148operator between the function name and its generic arguments. For
17149example, @value{GDBN} might provide a completion like
17150@code{crate::f<u32>}, where the parser would require
17151@code{crate::f::<u32>}.
17152
17153@item
17154As of this writing, the Rust compiler (version 1.8) has a few holes in
17155the debugging information it generates. These holes prevent certain
17156features from being implemented by @value{GDBN}:
17157@itemize @bullet
17158
17159@item
17160Method calls cannot be made via traits.
17161
0bdfa368
TT
17162@item
17163Operator overloading is not implemented.
17164
17165@item
17166When debugging in a monomorphized function, you cannot use the generic
17167type names.
17168
17169@item
17170The type @code{Self} is not available.
17171
17172@item
17173@code{use} statements are not available, so some names may not be
17174available in the crate.
17175@end itemize
17176@end itemize
17177
09d4efe1 17178@node Modula-2
c906108c 17179@subsection Modula-2
7a292a7a 17180
d4f3574e 17181@cindex Modula-2, @value{GDBN} support
c906108c
SS
17182
17183The extensions made to @value{GDBN} to support Modula-2 only support
17184output from the @sc{gnu} Modula-2 compiler (which is currently being
17185developed). Other Modula-2 compilers are not currently supported, and
17186attempting to debug executables produced by them is most likely
17187to give an error as @value{GDBN} reads in the executable's symbol
17188table.
17189
17190@cindex expressions in Modula-2
17191@menu
17192* M2 Operators:: Built-in operators
17193* Built-In Func/Proc:: Built-in functions and procedures
17194* M2 Constants:: Modula-2 constants
72019c9c 17195* M2 Types:: Modula-2 types
c906108c
SS
17196* M2 Defaults:: Default settings for Modula-2
17197* Deviations:: Deviations from standard Modula-2
17198* M2 Checks:: Modula-2 type and range checks
17199* M2 Scope:: The scope operators @code{::} and @code{.}
17200* GDB/M2:: @value{GDBN} and Modula-2
17201@end menu
17202
6d2ebf8b 17203@node M2 Operators
c906108c
SS
17204@subsubsection Operators
17205@cindex Modula-2 operators
17206
17207Operators must be defined on values of specific types. For instance,
17208@code{+} is defined on numbers, but not on structures. Operators are
17209often defined on groups of types. For the purposes of Modula-2, the
17210following definitions hold:
17211
17212@itemize @bullet
17213
17214@item
17215@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17216their subranges.
17217
17218@item
17219@emph{Character types} consist of @code{CHAR} and its subranges.
17220
17221@item
17222@emph{Floating-point types} consist of @code{REAL}.
17223
17224@item
17225@emph{Pointer types} consist of anything declared as @code{POINTER TO
17226@var{type}}.
17227
17228@item
17229@emph{Scalar types} consist of all of the above.
17230
17231@item
17232@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17233
17234@item
17235@emph{Boolean types} consist of @code{BOOLEAN}.
17236@end itemize
17237
17238@noindent
17239The following operators are supported, and appear in order of
17240increasing precedence:
17241
17242@table @code
17243@item ,
17244Function argument or array index separator.
17245
17246@item :=
17247Assignment. The value of @var{var} @code{:=} @var{value} is
17248@var{value}.
17249
17250@item <@r{, }>
17251Less than, greater than on integral, floating-point, or enumerated
17252types.
17253
17254@item <=@r{, }>=
96a2c332 17255Less than or equal to, greater than or equal to
c906108c
SS
17256on integral, floating-point and enumerated types, or set inclusion on
17257set types. Same precedence as @code{<}.
17258
17259@item =@r{, }<>@r{, }#
17260Equality and two ways of expressing inequality, valid on scalar types.
17261Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17262available for inequality, since @code{#} conflicts with the script
17263comment character.
17264
17265@item IN
17266Set membership. Defined on set types and the types of their members.
17267Same precedence as @code{<}.
17268
17269@item OR
17270Boolean disjunction. Defined on boolean types.
17271
17272@item AND@r{, }&
d4f3574e 17273Boolean conjunction. Defined on boolean types.
c906108c
SS
17274
17275@item @@
17276The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17277
17278@item +@r{, }-
17279Addition and subtraction on integral and floating-point types, or union
17280and difference on set types.
17281
17282@item *
17283Multiplication on integral and floating-point types, or set intersection
17284on set types.
17285
17286@item /
17287Division on floating-point types, or symmetric set difference on set
17288types. Same precedence as @code{*}.
17289
17290@item DIV@r{, }MOD
17291Integer division and remainder. Defined on integral types. Same
17292precedence as @code{*}.
17293
17294@item -
99e008fe 17295Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17296
17297@item ^
17298Pointer dereferencing. Defined on pointer types.
17299
17300@item NOT
17301Boolean negation. Defined on boolean types. Same precedence as
17302@code{^}.
17303
17304@item .
17305@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17306precedence as @code{^}.
17307
17308@item []
17309Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17310
17311@item ()
17312Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17313as @code{^}.
17314
17315@item ::@r{, }.
17316@value{GDBN} and Modula-2 scope operators.
17317@end table
17318
17319@quotation
72019c9c 17320@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17321treats the use of the operator @code{IN}, or the use of operators
17322@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17323@code{<=}, and @code{>=} on sets as an error.
17324@end quotation
17325
cb51c4e0 17326
6d2ebf8b 17327@node Built-In Func/Proc
79a6e687 17328@subsubsection Built-in Functions and Procedures
cb51c4e0 17329@cindex Modula-2 built-ins
c906108c
SS
17330
17331Modula-2 also makes available several built-in procedures and functions.
17332In describing these, the following metavariables are used:
17333
17334@table @var
17335
17336@item a
17337represents an @code{ARRAY} variable.
17338
17339@item c
17340represents a @code{CHAR} constant or variable.
17341
17342@item i
17343represents a variable or constant of integral type.
17344
17345@item m
17346represents an identifier that belongs to a set. Generally used in the
17347same function with the metavariable @var{s}. The type of @var{s} should
17348be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17349
17350@item n
17351represents a variable or constant of integral or floating-point type.
17352
17353@item r
17354represents a variable or constant of floating-point type.
17355
17356@item t
17357represents a type.
17358
17359@item v
17360represents a variable.
17361
17362@item x
17363represents a variable or constant of one of many types. See the
17364explanation of the function for details.
17365@end table
17366
17367All Modula-2 built-in procedures also return a result, described below.
17368
17369@table @code
17370@item ABS(@var{n})
17371Returns the absolute value of @var{n}.
17372
17373@item CAP(@var{c})
17374If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17375equivalent, otherwise it returns its argument.
c906108c
SS
17376
17377@item CHR(@var{i})
17378Returns the character whose ordinal value is @var{i}.
17379
17380@item DEC(@var{v})
c3f6f71d 17381Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17382
17383@item DEC(@var{v},@var{i})
17384Decrements the value in the variable @var{v} by @var{i}. Returns the
17385new value.
17386
17387@item EXCL(@var{m},@var{s})
17388Removes the element @var{m} from the set @var{s}. Returns the new
17389set.
17390
17391@item FLOAT(@var{i})
17392Returns the floating point equivalent of the integer @var{i}.
17393
17394@item HIGH(@var{a})
17395Returns the index of the last member of @var{a}.
17396
17397@item INC(@var{v})
c3f6f71d 17398Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17399
17400@item INC(@var{v},@var{i})
17401Increments the value in the variable @var{v} by @var{i}. Returns the
17402new value.
17403
17404@item INCL(@var{m},@var{s})
17405Adds the element @var{m} to the set @var{s} if it is not already
17406there. Returns the new set.
17407
17408@item MAX(@var{t})
17409Returns the maximum value of the type @var{t}.
17410
17411@item MIN(@var{t})
17412Returns the minimum value of the type @var{t}.
17413
17414@item ODD(@var{i})
17415Returns boolean TRUE if @var{i} is an odd number.
17416
17417@item ORD(@var{x})
17418Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17419value of a character is its @sc{ascii} value (on machines supporting
17420the @sc{ascii} character set). The argument @var{x} must be of an
17421ordered type, which include integral, character and enumerated types.
c906108c
SS
17422
17423@item SIZE(@var{x})
697aa1b7
EZ
17424Returns the size of its argument. The argument @var{x} can be a
17425variable or a type.
c906108c
SS
17426
17427@item TRUNC(@var{r})
17428Returns the integral part of @var{r}.
17429
844781a1 17430@item TSIZE(@var{x})
697aa1b7
EZ
17431Returns the size of its argument. The argument @var{x} can be a
17432variable or a type.
844781a1 17433
c906108c
SS
17434@item VAL(@var{t},@var{i})
17435Returns the member of the type @var{t} whose ordinal value is @var{i}.
17436@end table
17437
17438@quotation
17439@emph{Warning:} Sets and their operations are not yet supported, so
17440@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17441an error.
17442@end quotation
17443
17444@cindex Modula-2 constants
6d2ebf8b 17445@node M2 Constants
c906108c
SS
17446@subsubsection Constants
17447
17448@value{GDBN} allows you to express the constants of Modula-2 in the following
17449ways:
17450
17451@itemize @bullet
17452
17453@item
17454Integer constants are simply a sequence of digits. When used in an
17455expression, a constant is interpreted to be type-compatible with the
17456rest of the expression. Hexadecimal integers are specified by a
17457trailing @samp{H}, and octal integers by a trailing @samp{B}.
17458
17459@item
17460Floating point constants appear as a sequence of digits, followed by a
17461decimal point and another sequence of digits. An optional exponent can
17462then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17463@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17464digits of the floating point constant must be valid decimal (base 10)
17465digits.
17466
17467@item
17468Character constants consist of a single character enclosed by a pair of
17469like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17470also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17471followed by a @samp{C}.
17472
17473@item
17474String constants consist of a sequence of characters enclosed by a
17475pair of like quotes, either single (@code{'}) or double (@code{"}).
17476Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17477Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17478sequences.
17479
17480@item
17481Enumerated constants consist of an enumerated identifier.
17482
17483@item
17484Boolean constants consist of the identifiers @code{TRUE} and
17485@code{FALSE}.
17486
17487@item
17488Pointer constants consist of integral values only.
17489
17490@item
17491Set constants are not yet supported.
17492@end itemize
17493
72019c9c
GM
17494@node M2 Types
17495@subsubsection Modula-2 Types
17496@cindex Modula-2 types
17497
17498Currently @value{GDBN} can print the following data types in Modula-2
17499syntax: array types, record types, set types, pointer types, procedure
17500types, enumerated types, subrange types and base types. You can also
17501print the contents of variables declared using these type.
17502This section gives a number of simple source code examples together with
17503sample @value{GDBN} sessions.
17504
17505The first example contains the following section of code:
17506
17507@smallexample
17508VAR
17509 s: SET OF CHAR ;
17510 r: [20..40] ;
17511@end smallexample
17512
17513@noindent
17514and you can request @value{GDBN} to interrogate the type and value of
17515@code{r} and @code{s}.
17516
17517@smallexample
17518(@value{GDBP}) print s
17519@{'A'..'C', 'Z'@}
17520(@value{GDBP}) ptype s
17521SET OF CHAR
17522(@value{GDBP}) print r
1752321
17524(@value{GDBP}) ptype r
17525[20..40]
17526@end smallexample
17527
17528@noindent
17529Likewise if your source code declares @code{s} as:
17530
17531@smallexample
17532VAR
17533 s: SET ['A'..'Z'] ;
17534@end smallexample
17535
17536@noindent
17537then you may query the type of @code{s} by:
17538
17539@smallexample
17540(@value{GDBP}) ptype s
17541type = SET ['A'..'Z']
17542@end smallexample
17543
17544@noindent
17545Note that at present you cannot interactively manipulate set
17546expressions using the debugger.
17547
17548The following example shows how you might declare an array in Modula-2
17549and how you can interact with @value{GDBN} to print its type and contents:
17550
17551@smallexample
17552VAR
17553 s: ARRAY [-10..10] OF CHAR ;
17554@end smallexample
17555
17556@smallexample
17557(@value{GDBP}) ptype s
17558ARRAY [-10..10] OF CHAR
17559@end smallexample
17560
17561Note that the array handling is not yet complete and although the type
17562is printed correctly, expression handling still assumes that all
17563arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17564above.
72019c9c
GM
17565
17566Here are some more type related Modula-2 examples:
17567
17568@smallexample
17569TYPE
17570 colour = (blue, red, yellow, green) ;
17571 t = [blue..yellow] ;
17572VAR
17573 s: t ;
17574BEGIN
17575 s := blue ;
17576@end smallexample
17577
17578@noindent
17579The @value{GDBN} interaction shows how you can query the data type
17580and value of a variable.
17581
17582@smallexample
17583(@value{GDBP}) print s
17584$1 = blue
17585(@value{GDBP}) ptype t
17586type = [blue..yellow]
17587@end smallexample
17588
17589@noindent
17590In this example a Modula-2 array is declared and its contents
17591displayed. Observe that the contents are written in the same way as
17592their @code{C} counterparts.
17593
17594@smallexample
17595VAR
17596 s: ARRAY [1..5] OF CARDINAL ;
17597BEGIN
17598 s[1] := 1 ;
17599@end smallexample
17600
17601@smallexample
17602(@value{GDBP}) print s
17603$1 = @{1, 0, 0, 0, 0@}
17604(@value{GDBP}) ptype s
17605type = ARRAY [1..5] OF CARDINAL
17606@end smallexample
17607
17608The Modula-2 language interface to @value{GDBN} also understands
17609pointer types as shown in this example:
17610
17611@smallexample
17612VAR
17613 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17614BEGIN
17615 NEW(s) ;
17616 s^[1] := 1 ;
17617@end smallexample
17618
17619@noindent
17620and you can request that @value{GDBN} describes the type of @code{s}.
17621
17622@smallexample
17623(@value{GDBP}) ptype s
17624type = POINTER TO ARRAY [1..5] OF CARDINAL
17625@end smallexample
17626
17627@value{GDBN} handles compound types as we can see in this example.
17628Here we combine array types, record types, pointer types and subrange
17629types:
17630
17631@smallexample
17632TYPE
17633 foo = RECORD
17634 f1: CARDINAL ;
17635 f2: CHAR ;
17636 f3: myarray ;
17637 END ;
17638
17639 myarray = ARRAY myrange OF CARDINAL ;
17640 myrange = [-2..2] ;
17641VAR
17642 s: POINTER TO ARRAY myrange OF foo ;
17643@end smallexample
17644
17645@noindent
17646and you can ask @value{GDBN} to describe the type of @code{s} as shown
17647below.
17648
17649@smallexample
17650(@value{GDBP}) ptype s
17651type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17652 f1 : CARDINAL;
17653 f2 : CHAR;
17654 f3 : ARRAY [-2..2] OF CARDINAL;
17655END
17656@end smallexample
17657
6d2ebf8b 17658@node M2 Defaults
79a6e687 17659@subsubsection Modula-2 Defaults
c906108c
SS
17660@cindex Modula-2 defaults
17661
17662If type and range checking are set automatically by @value{GDBN}, they
17663both default to @code{on} whenever the working language changes to
d4f3574e 17664Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17665selected the working language.
17666
17667If you allow @value{GDBN} to set the language automatically, then entering
17668code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17669working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17670Infer the Source Language}, for further details.
c906108c 17671
6d2ebf8b 17672@node Deviations
79a6e687 17673@subsubsection Deviations from Standard Modula-2
c906108c
SS
17674@cindex Modula-2, deviations from
17675
17676A few changes have been made to make Modula-2 programs easier to debug.
17677This is done primarily via loosening its type strictness:
17678
17679@itemize @bullet
17680@item
17681Unlike in standard Modula-2, pointer constants can be formed by
17682integers. This allows you to modify pointer variables during
17683debugging. (In standard Modula-2, the actual address contained in a
17684pointer variable is hidden from you; it can only be modified
17685through direct assignment to another pointer variable or expression that
17686returned a pointer.)
17687
17688@item
17689C escape sequences can be used in strings and characters to represent
17690non-printable characters. @value{GDBN} prints out strings with these
17691escape sequences embedded. Single non-printable characters are
17692printed using the @samp{CHR(@var{nnn})} format.
17693
17694@item
17695The assignment operator (@code{:=}) returns the value of its right-hand
17696argument.
17697
17698@item
17699All built-in procedures both modify @emph{and} return their argument.
17700@end itemize
17701
6d2ebf8b 17702@node M2 Checks
79a6e687 17703@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17704@cindex Modula-2 checks
17705
17706@quotation
17707@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17708range checking.
17709@end quotation
17710@c FIXME remove warning when type/range checks added
17711
17712@value{GDBN} considers two Modula-2 variables type equivalent if:
17713
17714@itemize @bullet
17715@item
17716They are of types that have been declared equivalent via a @code{TYPE
17717@var{t1} = @var{t2}} statement
17718
17719@item
17720They have been declared on the same line. (Note: This is true of the
17721@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17722@end itemize
17723
17724As long as type checking is enabled, any attempt to combine variables
17725whose types are not equivalent is an error.
17726
17727Range checking is done on all mathematical operations, assignment, array
17728index bounds, and all built-in functions and procedures.
17729
6d2ebf8b 17730@node M2 Scope
79a6e687 17731@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17732@cindex scope
41afff9a 17733@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17734@cindex colon, doubled as scope operator
17735@ifinfo
41afff9a 17736@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17737@c Info cannot handle :: but TeX can.
17738@end ifinfo
a67ec3f4 17739@ifnotinfo
41afff9a 17740@vindex ::@r{, in Modula-2}
a67ec3f4 17741@end ifnotinfo
c906108c
SS
17742
17743There are a few subtle differences between the Modula-2 scope operator
17744(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17745similar syntax:
17746
474c8240 17747@smallexample
c906108c
SS
17748
17749@var{module} . @var{id}
17750@var{scope} :: @var{id}
474c8240 17751@end smallexample
c906108c
SS
17752
17753@noindent
17754where @var{scope} is the name of a module or a procedure,
17755@var{module} the name of a module, and @var{id} is any declared
17756identifier within your program, except another module.
17757
17758Using the @code{::} operator makes @value{GDBN} search the scope
17759specified by @var{scope} for the identifier @var{id}. If it is not
17760found in the specified scope, then @value{GDBN} searches all scopes
17761enclosing the one specified by @var{scope}.
17762
17763Using the @code{.} operator makes @value{GDBN} search the current scope for
17764the identifier specified by @var{id} that was imported from the
17765definition module specified by @var{module}. With this operator, it is
17766an error if the identifier @var{id} was not imported from definition
17767module @var{module}, or if @var{id} is not an identifier in
17768@var{module}.
17769
6d2ebf8b 17770@node GDB/M2
c906108c
SS
17771@subsubsection @value{GDBN} and Modula-2
17772
17773Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17774Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17775specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17776@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17777apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17778analogue in Modula-2.
17779
17780The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17781with any language, is not useful with Modula-2. Its
c906108c 17782intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17783created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17784address can be specified by an integral constant, the construct
d4f3574e 17785@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17786
17787@cindex @code{#} in Modula-2
17788In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17789interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17790
e07c999f
PH
17791@node Ada
17792@subsection Ada
17793@cindex Ada
17794
17795The extensions made to @value{GDBN} for Ada only support
17796output from the @sc{gnu} Ada (GNAT) compiler.
17797Other Ada compilers are not currently supported, and
17798attempting to debug executables produced by them is most likely
17799to be difficult.
17800
17801
17802@cindex expressions in Ada
17803@menu
17804* Ada Mode Intro:: General remarks on the Ada syntax
17805 and semantics supported by Ada mode
17806 in @value{GDBN}.
17807* Omissions from Ada:: Restrictions on the Ada expression syntax.
17808* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17809* Overloading support for Ada:: Support for expressions involving overloaded
17810 subprograms.
e07c999f 17811* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17812* Ada Exceptions:: Ada Exceptions
20924a55
JB
17813* Ada Tasks:: Listing and setting breakpoints in tasks.
17814* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17815* Ravenscar Profile:: Tasking Support when using the Ravenscar
17816 Profile
3fcded8f 17817* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17818* Ada Glitches:: Known peculiarities of Ada mode.
17819@end menu
17820
17821@node Ada Mode Intro
17822@subsubsection Introduction
17823@cindex Ada mode, general
17824
17825The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17826syntax, with some extensions.
17827The philosophy behind the design of this subset is
17828
17829@itemize @bullet
17830@item
17831That @value{GDBN} should provide basic literals and access to operations for
17832arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17833leaving more sophisticated computations to subprograms written into the
17834program (which therefore may be called from @value{GDBN}).
17835
17836@item
17837That type safety and strict adherence to Ada language restrictions
17838are not particularly important to the @value{GDBN} user.
17839
17840@item
17841That brevity is important to the @value{GDBN} user.
17842@end itemize
17843
f3a2dd1a
JB
17844Thus, for brevity, the debugger acts as if all names declared in
17845user-written packages are directly visible, even if they are not visible
17846according to Ada rules, thus making it unnecessary to fully qualify most
17847names with their packages, regardless of context. Where this causes
17848ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17849
17850The debugger will start in Ada mode if it detects an Ada main program.
17851As for other languages, it will enter Ada mode when stopped in a program that
17852was translated from an Ada source file.
17853
17854While in Ada mode, you may use `@t{--}' for comments. This is useful
17855mostly for documenting command files. The standard @value{GDBN} comment
17856(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17857middle (to allow based literals).
17858
e07c999f
PH
17859@node Omissions from Ada
17860@subsubsection Omissions from Ada
17861@cindex Ada, omissions from
17862
17863Here are the notable omissions from the subset:
17864
17865@itemize @bullet
17866@item
17867Only a subset of the attributes are supported:
17868
17869@itemize @minus
17870@item
17871@t{'First}, @t{'Last}, and @t{'Length}
17872 on array objects (not on types and subtypes).
17873
17874@item
17875@t{'Min} and @t{'Max}.
17876
17877@item
17878@t{'Pos} and @t{'Val}.
17879
17880@item
17881@t{'Tag}.
17882
17883@item
17884@t{'Range} on array objects (not subtypes), but only as the right
17885operand of the membership (@code{in}) operator.
17886
17887@item
17888@t{'Access}, @t{'Unchecked_Access}, and
17889@t{'Unrestricted_Access} (a GNAT extension).
17890
17891@item
17892@t{'Address}.
17893@end itemize
17894
17895@item
17896The names in
17897@code{Characters.Latin_1} are not available and
17898concatenation is not implemented. Thus, escape characters in strings are
17899not currently available.
17900
17901@item
17902Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17903equality of representations. They will generally work correctly
17904for strings and arrays whose elements have integer or enumeration types.
17905They may not work correctly for arrays whose element
17906types have user-defined equality, for arrays of real values
17907(in particular, IEEE-conformant floating point, because of negative
17908zeroes and NaNs), and for arrays whose elements contain unused bits with
17909indeterminate values.
17910
17911@item
17912The other component-by-component array operations (@code{and}, @code{or},
17913@code{xor}, @code{not}, and relational tests other than equality)
17914are not implemented.
17915
17916@item
860701dc
PH
17917@cindex array aggregates (Ada)
17918@cindex record aggregates (Ada)
17919@cindex aggregates (Ada)
17920There is limited support for array and record aggregates. They are
17921permitted only on the right sides of assignments, as in these examples:
17922
17923@smallexample
077e0a52
JB
17924(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17925(@value{GDBP}) set An_Array := (1, others => 0)
17926(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17927(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17928(@value{GDBP}) set A_Record := (1, "Peter", True);
17929(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17930@end smallexample
17931
17932Changing a
17933discriminant's value by assigning an aggregate has an
17934undefined effect if that discriminant is used within the record.
17935However, you can first modify discriminants by directly assigning to
17936them (which normally would not be allowed in Ada), and then performing an
17937aggregate assignment. For example, given a variable @code{A_Rec}
17938declared to have a type such as:
17939
17940@smallexample
17941type Rec (Len : Small_Integer := 0) is record
17942 Id : Integer;
17943 Vals : IntArray (1 .. Len);
17944end record;
17945@end smallexample
17946
17947you can assign a value with a different size of @code{Vals} with two
17948assignments:
17949
17950@smallexample
077e0a52
JB
17951(@value{GDBP}) set A_Rec.Len := 4
17952(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17953@end smallexample
17954
17955As this example also illustrates, @value{GDBN} is very loose about the usual
17956rules concerning aggregates. You may leave out some of the
17957components of an array or record aggregate (such as the @code{Len}
17958component in the assignment to @code{A_Rec} above); they will retain their
17959original values upon assignment. You may freely use dynamic values as
17960indices in component associations. You may even use overlapping or
17961redundant component associations, although which component values are
17962assigned in such cases is not defined.
e07c999f
PH
17963
17964@item
17965Calls to dispatching subprograms are not implemented.
17966
17967@item
17968The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17969than that of real Ada. It makes only limited use of the context in
17970which a subexpression appears to resolve its meaning, and it is much
17971looser in its rules for allowing type matches. As a result, some
17972function calls will be ambiguous, and the user will be asked to choose
17973the proper resolution.
e07c999f
PH
17974
17975@item
17976The @code{new} operator is not implemented.
17977
17978@item
17979Entry calls are not implemented.
17980
17981@item
17982Aside from printing, arithmetic operations on the native VAX floating-point
17983formats are not supported.
17984
17985@item
17986It is not possible to slice a packed array.
158c7665
PH
17987
17988@item
17989The names @code{True} and @code{False}, when not part of a qualified name,
17990are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17991context.
17992Should your program
17993redefine these names in a package or procedure (at best a dubious practice),
17994you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17995@end itemize
17996
17997@node Additions to Ada
17998@subsubsection Additions to Ada
17999@cindex Ada, deviations from
18000
18001As it does for other languages, @value{GDBN} makes certain generic
18002extensions to Ada (@pxref{Expressions}):
18003
18004@itemize @bullet
18005@item
ae21e955
BW
18006If the expression @var{E} is a variable residing in memory (typically
18007a local variable or array element) and @var{N} is a positive integer,
18008then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18009@var{N}-1 adjacent variables following it in memory as an array. In
18010Ada, this operator is generally not necessary, since its prime use is
18011in displaying parts of an array, and slicing will usually do this in
18012Ada. However, there are occasional uses when debugging programs in
18013which certain debugging information has been optimized away.
e07c999f
PH
18014
18015@item
ae21e955
BW
18016@code{@var{B}::@var{var}} means ``the variable named @var{var} that
18017appears in function or file @var{B}.'' When @var{B} is a file name,
18018you must typically surround it in single quotes.
e07c999f
PH
18019
18020@item
18021The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18022@var{type} that appears at address @var{addr}.''
18023
18024@item
18025A name starting with @samp{$} is a convenience variable
18026(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18027@end itemize
18028
ae21e955
BW
18029In addition, @value{GDBN} provides a few other shortcuts and outright
18030additions specific to Ada:
e07c999f
PH
18031
18032@itemize @bullet
18033@item
18034The assignment statement is allowed as an expression, returning
18035its right-hand operand as its value. Thus, you may enter
18036
18037@smallexample
077e0a52
JB
18038(@value{GDBP}) set x := y + 3
18039(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
18040@end smallexample
18041
18042@item
18043The semicolon is allowed as an ``operator,'' returning as its value
18044the value of its right-hand operand.
18045This allows, for example,
18046complex conditional breaks:
18047
18048@smallexample
077e0a52
JB
18049(@value{GDBP}) break f
18050(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
18051@end smallexample
18052
18053@item
18054Rather than use catenation and symbolic character names to introduce special
18055characters into strings, one may instead use a special bracket notation,
18056which is also used to print strings. A sequence of characters of the form
18057@samp{["@var{XX}"]} within a string or character literal denotes the
18058(single) character whose numeric encoding is @var{XX} in hexadecimal. The
18059sequence of characters @samp{["""]} also denotes a single quotation mark
18060in strings. For example,
18061@smallexample
18062 "One line.["0a"]Next line.["0a"]"
18063@end smallexample
18064@noindent
ae21e955
BW
18065contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18066after each period.
e07c999f
PH
18067
18068@item
18069The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18070@t{'Max} is optional (and is ignored in any case). For example, it is valid
18071to write
18072
18073@smallexample
077e0a52 18074(@value{GDBP}) print 'max(x, y)
e07c999f
PH
18075@end smallexample
18076
18077@item
18078When printing arrays, @value{GDBN} uses positional notation when the
18079array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
18080For example, a one-dimensional array of three integers with a lower bound
18081of 3 might print as
e07c999f
PH
18082
18083@smallexample
18084(3 => 10, 17, 1)
18085@end smallexample
18086
18087@noindent
18088That is, in contrast to valid Ada, only the first component has a @code{=>}
18089clause.
18090
18091@item
18092You may abbreviate attributes in expressions with any unique,
18093multi-character subsequence of
18094their names (an exact match gets preference).
18095For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18096in place of @t{a'length}.
18097
18098@item
18099@cindex quoting Ada internal identifiers
18100Since Ada is case-insensitive, the debugger normally maps identifiers you type
18101to lower case. The GNAT compiler uses upper-case characters for
18102some of its internal identifiers, which are normally of no interest to users.
18103For the rare occasions when you actually have to look at them,
18104enclose them in angle brackets to avoid the lower-case mapping.
18105For example,
18106@smallexample
077e0a52 18107(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
18108@end smallexample
18109
18110@item
18111Printing an object of class-wide type or dereferencing an
18112access-to-class-wide value will display all the components of the object's
18113specific type (as indicated by its run-time tag). Likewise, component
18114selection on such a value will operate on the specific type of the
18115object.
18116
18117@end itemize
18118
3685b09f
PMR
18119@node Overloading support for Ada
18120@subsubsection Overloading support for Ada
18121@cindex overloading, Ada
18122
18123The debugger supports limited overloading. Given a subprogram call in which
18124the function symbol has multiple definitions, it will use the number of
18125actual parameters and some information about their types to attempt to narrow
18126the set of definitions. It also makes very limited use of context, preferring
18127procedures to functions in the context of the @code{call} command, and
18128functions to procedures elsewhere.
18129
18130If, after narrowing, the set of matching definitions still contains more than
18131one definition, @value{GDBN} will display a menu to query which one it should
18132use, for instance:
18133
18134@smallexample
18135(@value{GDBP}) print f(1)
18136Multiple matches for f
18137[0] cancel
18138[1] foo.f (integer) return boolean at foo.adb:23
18139[2] foo.f (foo.new_integer) return boolean at foo.adb:28
18140>
18141@end smallexample
18142
18143In this case, just select one menu entry either to cancel expression evaluation
18144(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18145instance (type the corresponding number and press @key{RET}).
18146
18147Here are a couple of commands to customize @value{GDBN}'s behavior in this
18148case:
18149
18150@table @code
18151
18152@kindex set ada print-signatures
18153@item set ada print-signatures
18154Control whether parameter types and return types are displayed in overloads
18155selection menus. It is @code{on} by default.
18156@xref{Overloading support for Ada}.
18157
18158@kindex show ada print-signatures
18159@item show ada print-signatures
18160Show the current setting for displaying parameter types and return types in
18161overloads selection menu.
18162@xref{Overloading support for Ada}.
18163
18164@end table
18165
e07c999f
PH
18166@node Stopping Before Main Program
18167@subsubsection Stopping at the Very Beginning
18168
18169@cindex breakpointing Ada elaboration code
18170It is sometimes necessary to debug the program during elaboration, and
18171before reaching the main procedure.
18172As defined in the Ada Reference
18173Manual, the elaboration code is invoked from a procedure called
18174@code{adainit}. To run your program up to the beginning of
18175elaboration, simply use the following two commands:
18176@code{tbreak adainit} and @code{run}.
18177
58d06528
JB
18178@node Ada Exceptions
18179@subsubsection Ada Exceptions
18180
18181A command is provided to list all Ada exceptions:
18182
18183@table @code
18184@kindex info exceptions
18185@item info exceptions
18186@itemx info exceptions @var{regexp}
18187The @code{info exceptions} command allows you to list all Ada exceptions
18188defined within the program being debugged, as well as their addresses.
18189With a regular expression, @var{regexp}, as argument, only those exceptions
18190whose names match @var{regexp} are listed.
18191@end table
18192
18193Below is a small example, showing how the command can be used, first
18194without argument, and next with a regular expression passed as an
18195argument.
18196
18197@smallexample
18198(@value{GDBP}) info exceptions
18199All defined Ada exceptions:
18200constraint_error: 0x613da0
18201program_error: 0x613d20
18202storage_error: 0x613ce0
18203tasking_error: 0x613ca0
18204const.aint_global_e: 0x613b00
18205(@value{GDBP}) info exceptions const.aint
18206All Ada exceptions matching regular expression "const.aint":
18207constraint_error: 0x613da0
18208const.aint_global_e: 0x613b00
18209@end smallexample
18210
18211It is also possible to ask @value{GDBN} to stop your program's execution
18212when an exception is raised. For more details, see @ref{Set Catchpoints}.
18213
20924a55
JB
18214@node Ada Tasks
18215@subsubsection Extensions for Ada Tasks
18216@cindex Ada, tasking
18217
18218Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18219@value{GDBN} provides the following task-related commands:
18220
18221@table @code
18222@kindex info tasks
18223@item info tasks
18224This command shows a list of current Ada tasks, as in the following example:
18225
18226
18227@smallexample
18228@iftex
18229@leftskip=0.5cm
18230@end iftex
18231(@value{GDBP}) info tasks
18232 ID TID P-ID Pri State Name
18233 1 8088000 0 15 Child Activation Wait main_task
18234 2 80a4000 1 15 Accept Statement b
18235 3 809a800 1 15 Child Activation Wait a
32cd1edc 18236* 4 80ae800 3 15 Runnable c
20924a55
JB
18237
18238@end smallexample
18239
18240@noindent
18241In this listing, the asterisk before the last task indicates it to be the
18242task currently being inspected.
18243
18244@table @asis
18245@item ID
18246Represents @value{GDBN}'s internal task number.
18247
18248@item TID
18249The Ada task ID.
18250
18251@item P-ID
18252The parent's task ID (@value{GDBN}'s internal task number).
18253
18254@item Pri
18255The base priority of the task.
18256
18257@item State
18258Current state of the task.
18259
18260@table @code
18261@item Unactivated
18262The task has been created but has not been activated. It cannot be
18263executing.
18264
20924a55
JB
18265@item Runnable
18266The task is not blocked for any reason known to Ada. (It may be waiting
18267for a mutex, though.) It is conceptually "executing" in normal mode.
18268
18269@item Terminated
18270The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18271that were waiting on terminate alternatives have been awakened and have
18272terminated themselves.
18273
18274@item Child Activation Wait
18275The task is waiting for created tasks to complete activation.
18276
18277@item Accept Statement
18278The task is waiting on an accept or selective wait statement.
18279
18280@item Waiting on entry call
18281The task is waiting on an entry call.
18282
18283@item Async Select Wait
18284The task is waiting to start the abortable part of an asynchronous
18285select statement.
18286
18287@item Delay Sleep
18288The task is waiting on a select statement with only a delay
18289alternative open.
18290
18291@item Child Termination Wait
18292The task is sleeping having completed a master within itself, and is
18293waiting for the tasks dependent on that master to become terminated or
18294waiting on a terminate Phase.
18295
18296@item Wait Child in Term Alt
18297The task is sleeping waiting for tasks on terminate alternatives to
18298finish terminating.
18299
18300@item Accepting RV with @var{taskno}
18301The task is accepting a rendez-vous with the task @var{taskno}.
18302@end table
18303
18304@item Name
18305Name of the task in the program.
18306
18307@end table
18308
18309@kindex info task @var{taskno}
18310@item info task @var{taskno}
6b92c0d3 18311This command shows detailed informations on the specified task, as in
20924a55
JB
18312the following example:
18313@smallexample
18314@iftex
18315@leftskip=0.5cm
18316@end iftex
18317(@value{GDBP}) info tasks
18318 ID TID P-ID Pri State Name
18319 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18320* 2 807c468 1 15 Runnable task_1
20924a55
JB
18321(@value{GDBP}) info task 2
18322Ada Task: 0x807c468
4993045d 18323Name: "task_1"
87f7ab7b
JB
18324Thread: 0
18325LWP: 0x1fac
4993045d 18326Parent: 1 ("main_task")
20924a55
JB
18327Base Priority: 15
18328State: Runnable
18329@end smallexample
18330
18331@item task
18332@kindex task@r{ (Ada)}
18333@cindex current Ada task ID
4993045d 18334This command prints the ID and name of the current task.
20924a55
JB
18335
18336@smallexample
18337@iftex
18338@leftskip=0.5cm
18339@end iftex
18340(@value{GDBP}) info tasks
18341 ID TID P-ID Pri State Name
18342 1 8077870 0 15 Child Activation Wait main_task
4993045d 18343* 2 807c458 1 15 Runnable some_task
20924a55 18344(@value{GDBP}) task
4993045d 18345[Current task is 2 "some_task"]
20924a55
JB
18346@end smallexample
18347
18348@item task @var{taskno}
18349@cindex Ada task switching
5d5658a1 18350This command is like the @code{thread @var{thread-id}}
20924a55
JB
18351command (@pxref{Threads}). It switches the context of debugging
18352from the current task to the given task.
18353
18354@smallexample
18355@iftex
18356@leftskip=0.5cm
18357@end iftex
18358(@value{GDBP}) info tasks
18359 ID TID P-ID Pri State Name
18360 1 8077870 0 15 Child Activation Wait main_task
4993045d 18361* 2 807c458 1 15 Runnable some_task
20924a55 18362(@value{GDBP}) task 1
4993045d 18363[Switching to task 1 "main_task"]
20924a55
JB
18364#0 0x8067726 in pthread_cond_wait ()
18365(@value{GDBP}) bt
18366#0 0x8067726 in pthread_cond_wait ()
18367#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18368#2 0x805cb63 in system.task_primitives.operations.sleep ()
18369#3 0x806153e in system.tasking.stages.activate_tasks ()
18370#4 0x804aacc in un () at un.adb:5
18371@end smallexample
18372
629500fa
KS
18373@item break @var{location} task @var{taskno}
18374@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18375@cindex breakpoints and tasks, in Ada
18376@cindex task breakpoints, in Ada
18377@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18378These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18379command (@pxref{Thread Stops}). The
629500fa 18380@var{location} argument specifies source lines, as described
45ac276d
JB
18381in @ref{Specify Location}.
18382
18383Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18384to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18385particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18386numeric task identifiers assigned by @value{GDBN}, shown in the first
18387column of the @samp{info tasks} display.
18388
18389If you do not specify @samp{task @var{taskno}} when you set a
18390breakpoint, the breakpoint applies to @emph{all} tasks of your
18391program.
18392
18393You can use the @code{task} qualifier on conditional breakpoints as
18394well; in this case, place @samp{task @var{taskno}} before the
18395breakpoint condition (before the @code{if}).
18396
18397For example,
18398
18399@smallexample
18400@iftex
18401@leftskip=0.5cm
18402@end iftex
18403(@value{GDBP}) info tasks
18404 ID TID P-ID Pri State Name
18405 1 140022020 0 15 Child Activation Wait main_task
18406 2 140045060 1 15 Accept/Select Wait t2
18407 3 140044840 1 15 Runnable t1
18408* 4 140056040 1 15 Runnable t3
18409(@value{GDBP}) b 15 task 2
18410Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18411(@value{GDBP}) cont
18412Continuing.
18413task # 1 running
18414task # 2 running
18415
18416Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1841715 flush;
18418(@value{GDBP}) info tasks
18419 ID TID P-ID Pri State Name
18420 1 140022020 0 15 Child Activation Wait main_task
18421* 2 140045060 1 15 Runnable t2
18422 3 140044840 1 15 Runnable t1
18423 4 140056040 1 15 Delay Sleep t3
18424@end smallexample
20924a55
JB
18425@end table
18426
18427@node Ada Tasks and Core Files
18428@subsubsection Tasking Support when Debugging Core Files
18429@cindex Ada tasking and core file debugging
18430
18431When inspecting a core file, as opposed to debugging a live program,
18432tasking support may be limited or even unavailable, depending on
18433the platform being used.
18434For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18435switching is not supported.
20924a55 18436
32a8097b 18437On certain platforms, the debugger needs to perform some
20924a55
JB
18438memory writes in order to provide Ada tasking support. When inspecting
18439a core file, this means that the core file must be opened with read-write
18440privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18441Under these circumstances, you should make a backup copy of the core
18442file before inspecting it with @value{GDBN}.
18443
6e1bb179
JB
18444@node Ravenscar Profile
18445@subsubsection Tasking Support when using the Ravenscar Profile
18446@cindex Ravenscar Profile
18447
18448The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18449specifically designed for systems with safety-critical real-time
18450requirements.
18451
18452@table @code
18453@kindex set ravenscar task-switching on
18454@cindex task switching with program using Ravenscar Profile
18455@item set ravenscar task-switching on
18456Allows task switching when debugging a program that uses the Ravenscar
18457Profile. This is the default.
18458
18459@kindex set ravenscar task-switching off
18460@item set ravenscar task-switching off
18461Turn off task switching when debugging a program that uses the Ravenscar
18462Profile. This is mostly intended to disable the code that adds support
18463for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18464the Ravenscar runtime is preventing @value{GDBN} from working properly.
18465To be effective, this command should be run before the program is started.
18466
18467@kindex show ravenscar task-switching
18468@item show ravenscar task-switching
18469Show whether it is possible to switch from task to task in a program
18470using the Ravenscar Profile.
18471
18472@end table
18473
e09eef98
TT
18474@cindex Ravenscar thread
18475When Ravenscar task-switching is enabled, Ravenscar tasks are
18476announced by @value{GDBN} as if they were threads:
18477
18478@smallexample
18479(gdb) continue
18480[New Ravenscar Thread 0x2b8f0]
18481@end smallexample
18482
18483Both Ravenscar tasks and the underlying CPU threads will show up in
18484the output of @code{info threads}:
18485
18486@smallexample
18487(gdb) info threads
18488 Id Target Id Frame
18489 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18490 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18491 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18492 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18493* 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18494 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18495@end smallexample
18496
18497One known limitation of the Ravenscar support in @value{GDBN} is that
18498it isn't currently possible to single-step through the runtime
18499initialization sequence. If you need to debug this code, you should
18500use @code{set ravenscar task-switching off}.
18501
3fcded8f
JB
18502@node Ada Settings
18503@subsubsection Ada Settings
18504@cindex Ada settings
18505
18506@table @code
18507@kindex set varsize-limit
18508@item set varsize-limit @var{size}
18509Prevent @value{GDBN} from attempting to evaluate objects whose size
18510is above the given limit (@var{size}) when those sizes are computed
18511from run-time quantities. This is typically the case when the object
18512has a variable size, such as an array whose bounds are not known at
18513compile time for example. Setting @var{size} to @code{unlimited}
18514removes the size limitation. By default, the limit is about 65KB.
18515
18516The purpose of having such a limit is to prevent @value{GDBN} from
18517trying to grab enormous chunks of virtual memory when asked to evaluate
18518a quantity whose bounds have been corrupted or have not yet been fully
18519initialized. The limit applies to the results of some subexpressions
18520as well as to complete expressions. For example, an expression denoting
18521a simple integer component, such as @code{x.y.z}, may fail if the size of
18522@code{x.y} is variable and exceeds @code{size}. On the other hand,
18523@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18524@code{A} is an array variable with non-constant size, will generally
18525succeed regardless of the bounds on @code{A}, as long as the component
18526size is less than @var{size}.
18527
18528@kindex show varsize-limit
18529@item show varsize-limit
18530Show the limit on types whose size is determined by run-time quantities.
18531@end table
18532
e07c999f
PH
18533@node Ada Glitches
18534@subsubsection Known Peculiarities of Ada Mode
18535@cindex Ada, problems
18536
18537Besides the omissions listed previously (@pxref{Omissions from Ada}),
18538we know of several problems with and limitations of Ada mode in
18539@value{GDBN},
18540some of which will be fixed with planned future releases of the debugger
18541and the GNU Ada compiler.
18542
18543@itemize @bullet
e07c999f
PH
18544@item
18545Static constants that the compiler chooses not to materialize as objects in
18546storage are invisible to the debugger.
18547
18548@item
18549Named parameter associations in function argument lists are ignored (the
18550argument lists are treated as positional).
18551
18552@item
18553Many useful library packages are currently invisible to the debugger.
18554
18555@item
18556Fixed-point arithmetic, conversions, input, and output is carried out using
18557floating-point arithmetic, and may give results that only approximate those on
18558the host machine.
18559
e07c999f
PH
18560@item
18561The GNAT compiler never generates the prefix @code{Standard} for any of
18562the standard symbols defined by the Ada language. @value{GDBN} knows about
18563this: it will strip the prefix from names when you use it, and will never
18564look for a name you have so qualified among local symbols, nor match against
18565symbols in other packages or subprograms. If you have
18566defined entities anywhere in your program other than parameters and
18567local variables whose simple names match names in @code{Standard},
18568GNAT's lack of qualification here can cause confusion. When this happens,
18569you can usually resolve the confusion
18570by qualifying the problematic names with package
18571@code{Standard} explicitly.
18572@end itemize
18573
95433b34
JB
18574Older versions of the compiler sometimes generate erroneous debugging
18575information, resulting in the debugger incorrectly printing the value
18576of affected entities. In some cases, the debugger is able to work
18577around an issue automatically. In other cases, the debugger is able
18578to work around the issue, but the work-around has to be specifically
18579enabled.
18580
18581@kindex set ada trust-PAD-over-XVS
18582@kindex show ada trust-PAD-over-XVS
18583@table @code
18584
18585@item set ada trust-PAD-over-XVS on
18586Configure GDB to strictly follow the GNAT encoding when computing the
18587value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18588types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18589a complete description of the encoding used by the GNAT compiler).
18590This is the default.
18591
18592@item set ada trust-PAD-over-XVS off
18593This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18594sometimes prints the wrong value for certain entities, changing @code{ada
18595trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18596the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18597@code{off}, but this incurs a slight performance penalty, so it is
18598recommended to leave this setting to @code{on} unless necessary.
18599
18600@end table
18601
c6044dd1
JB
18602@cindex GNAT descriptive types
18603@cindex GNAT encoding
18604Internally, the debugger also relies on the compiler following a number
18605of conventions known as the @samp{GNAT Encoding}, all documented in
18606@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18607how the debugging information should be generated for certain types.
18608In particular, this convention makes use of @dfn{descriptive types},
18609which are artificial types generated purely to help the debugger.
18610
18611These encodings were defined at a time when the debugging information
18612format used was not powerful enough to describe some of the more complex
18613types available in Ada. Since DWARF allows us to express nearly all
18614Ada features, the long-term goal is to slowly replace these descriptive
18615types by their pure DWARF equivalent. To facilitate that transition,
18616a new maintenance option is available to force the debugger to ignore
18617those descriptive types. It allows the user to quickly evaluate how
18618well @value{GDBN} works without them.
18619
18620@table @code
18621
18622@kindex maint ada set ignore-descriptive-types
18623@item maintenance ada set ignore-descriptive-types [on|off]
18624Control whether the debugger should ignore descriptive types.
18625The default is not to ignore descriptives types (@code{off}).
18626
18627@kindex maint ada show ignore-descriptive-types
18628@item maintenance ada show ignore-descriptive-types
18629Show if descriptive types are ignored by @value{GDBN}.
18630
18631@end table
18632
79a6e687
BW
18633@node Unsupported Languages
18634@section Unsupported Languages
4e562065
JB
18635
18636@cindex unsupported languages
18637@cindex minimal language
18638In addition to the other fully-supported programming languages,
18639@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18640It does not represent a real programming language, but provides a set
18641of capabilities close to what the C or assembly languages provide.
18642This should allow most simple operations to be performed while debugging
18643an application that uses a language currently not supported by @value{GDBN}.
18644
18645If the language is set to @code{auto}, @value{GDBN} will automatically
18646select this language if the current frame corresponds to an unsupported
18647language.
18648
6d2ebf8b 18649@node Symbols
c906108c
SS
18650@chapter Examining the Symbol Table
18651
d4f3574e 18652The commands described in this chapter allow you to inquire about the
c906108c
SS
18653symbols (names of variables, functions and types) defined in your
18654program. This information is inherent in the text of your program and
18655does not change as your program executes. @value{GDBN} finds it in your
18656program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18657(@pxref{File Options, ,Choosing Files}), or by one of the
18658file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18659
18660@cindex symbol names
18661@cindex names of symbols
18662@cindex quoting names
d044bac8 18663@anchor{quoting names}
c906108c
SS
18664Occasionally, you may need to refer to symbols that contain unusual
18665characters, which @value{GDBN} ordinarily treats as word delimiters. The
18666most frequent case is in referring to static variables in other
79a6e687 18667source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18668are recorded in object files as debugging symbols, but @value{GDBN} would
18669ordinarily parse a typical file name, like @file{foo.c}, as the three words
18670@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18671@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18672
474c8240 18673@smallexample
c906108c 18674p 'foo.c'::x
474c8240 18675@end smallexample
c906108c
SS
18676
18677@noindent
18678looks up the value of @code{x} in the scope of the file @file{foo.c}.
18679
18680@table @code
a8f24a35
EZ
18681@cindex case-insensitive symbol names
18682@cindex case sensitivity in symbol names
18683@kindex set case-sensitive
18684@item set case-sensitive on
18685@itemx set case-sensitive off
18686@itemx set case-sensitive auto
18687Normally, when @value{GDBN} looks up symbols, it matches their names
18688with case sensitivity determined by the current source language.
18689Occasionally, you may wish to control that. The command @code{set
18690case-sensitive} lets you do that by specifying @code{on} for
18691case-sensitive matches or @code{off} for case-insensitive ones. If
18692you specify @code{auto}, case sensitivity is reset to the default
18693suitable for the source language. The default is case-sensitive
18694matches for all languages except for Fortran, for which the default is
18695case-insensitive matches.
18696
9c16f35a
EZ
18697@kindex show case-sensitive
18698@item show case-sensitive
a8f24a35
EZ
18699This command shows the current setting of case sensitivity for symbols
18700lookups.
18701
53342f27
TT
18702@kindex set print type methods
18703@item set print type methods
18704@itemx set print type methods on
18705@itemx set print type methods off
18706Normally, when @value{GDBN} prints a class, it displays any methods
18707declared in that class. You can control this behavior either by
18708passing the appropriate flag to @code{ptype}, or using @command{set
18709print type methods}. Specifying @code{on} will cause @value{GDBN} to
18710display the methods; this is the default. Specifying @code{off} will
18711cause @value{GDBN} to omit the methods.
18712
18713@kindex show print type methods
18714@item show print type methods
18715This command shows the current setting of method display when printing
18716classes.
18717
883fd55a
KS
18718@kindex set print type nested-type-limit
18719@item set print type nested-type-limit @var{limit}
18720@itemx set print type nested-type-limit unlimited
18721Set the limit of displayed nested types that the type printer will
18722show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18723nested definitions. By default, the type printer will not show any nested
18724types defined in classes.
18725
18726@kindex show print type nested-type-limit
18727@item show print type nested-type-limit
18728This command shows the current display limit of nested types when
18729printing classes.
18730
53342f27
TT
18731@kindex set print type typedefs
18732@item set print type typedefs
18733@itemx set print type typedefs on
18734@itemx set print type typedefs off
18735
18736Normally, when @value{GDBN} prints a class, it displays any typedefs
18737defined in that class. You can control this behavior either by
18738passing the appropriate flag to @code{ptype}, or using @command{set
18739print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18740display the typedef definitions; this is the default. Specifying
18741@code{off} will cause @value{GDBN} to omit the typedef definitions.
18742Note that this controls whether the typedef definition itself is
18743printed, not whether typedef names are substituted when printing other
18744types.
18745
18746@kindex show print type typedefs
18747@item show print type typedefs
18748This command shows the current setting of typedef display when
18749printing classes.
18750
c906108c 18751@kindex info address
b37052ae 18752@cindex address of a symbol
c906108c
SS
18753@item info address @var{symbol}
18754Describe where the data for @var{symbol} is stored. For a register
18755variable, this says which register it is kept in. For a non-register
18756local variable, this prints the stack-frame offset at which the variable
18757is always stored.
18758
18759Note the contrast with @samp{print &@var{symbol}}, which does not work
18760at all for a register variable, and for a stack local variable prints
18761the exact address of the current instantiation of the variable.
18762
3d67e040 18763@kindex info symbol
b37052ae 18764@cindex symbol from address
9c16f35a 18765@cindex closest symbol and offset for an address
3d67e040
EZ
18766@item info symbol @var{addr}
18767Print the name of a symbol which is stored at the address @var{addr}.
18768If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18769nearest symbol and an offset from it:
18770
474c8240 18771@smallexample
3d67e040
EZ
18772(@value{GDBP}) info symbol 0x54320
18773_initialize_vx + 396 in section .text
474c8240 18774@end smallexample
3d67e040
EZ
18775
18776@noindent
18777This is the opposite of the @code{info address} command. You can use
18778it to find out the name of a variable or a function given its address.
18779
c14c28ba
PP
18780For dynamically linked executables, the name of executable or shared
18781library containing the symbol is also printed:
18782
18783@smallexample
18784(@value{GDBP}) info symbol 0x400225
18785_start + 5 in section .text of /tmp/a.out
18786(@value{GDBP}) info symbol 0x2aaaac2811cf
18787__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18788@end smallexample
18789
439250fb
DE
18790@kindex demangle
18791@cindex demangle
18792@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18793Demangle @var{name}.
18794If @var{language} is provided it is the name of the language to demangle
18795@var{name} in. Otherwise @var{name} is demangled in the current language.
18796
18797The @samp{--} option specifies the end of options,
18798and is useful when @var{name} begins with a dash.
18799
18800The parameter @code{demangle-style} specifies how to interpret the kind
18801of mangling used. @xref{Print Settings}.
18802
c906108c 18803@kindex whatis
53342f27 18804@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18805Print the data type of @var{arg}, which can be either an expression
18806or a name of a data type. With no argument, print the data type of
18807@code{$}, the last value in the value history.
18808
18809If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18810is not actually evaluated, and any side-effecting operations (such as
18811assignments or function calls) inside it do not take place.
18812
18813If @var{arg} is a variable or an expression, @code{whatis} prints its
18814literal type as it is used in the source code. If the type was
18815defined using a @code{typedef}, @code{whatis} will @emph{not} print
18816the data type underlying the @code{typedef}. If the type of the
18817variable or the expression is a compound data type, such as
18818@code{struct} or @code{class}, @code{whatis} never prints their
18819fields or methods. It just prints the @code{struct}/@code{class}
18820name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18821such a compound data type, use @code{ptype}.
18822
18823If @var{arg} is a type name that was defined using @code{typedef},
18824@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18825Unrolling means that @code{whatis} will show the underlying type used
18826in the @code{typedef} declaration of @var{arg}. However, if that
18827underlying type is also a @code{typedef}, @code{whatis} will not
18828unroll it.
18829
18830For C code, the type names may also have the form @samp{class
18831@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18832@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18833
53342f27
TT
18834@var{flags} can be used to modify how the type is displayed.
18835Available flags are:
18836
18837@table @code
18838@item r
18839Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18840parameters and typedefs defined in a class when printing the class'
18841members. The @code{/r} flag disables this.
18842
18843@item m
18844Do not print methods defined in the class.
18845
18846@item M
18847Print methods defined in the class. This is the default, but the flag
18848exists in case you change the default with @command{set print type methods}.
18849
18850@item t
18851Do not print typedefs defined in the class. Note that this controls
18852whether the typedef definition itself is printed, not whether typedef
18853names are substituted when printing other types.
18854
18855@item T
18856Print typedefs defined in the class. This is the default, but the flag
18857exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18858
18859@item o
18860Print the offsets and sizes of fields in a struct, similar to what the
18861@command{pahole} tool does. This option implies the @code{/tm} flags.
18862
18863For example, given the following declarations:
18864
18865@smallexample
18866struct tuv
18867@{
18868 int a1;
18869 char *a2;
18870 int a3;
18871@};
18872
18873struct xyz
18874@{
18875 int f1;
18876 char f2;
18877 void *f3;
18878 struct tuv f4;
18879@};
18880
18881union qwe
18882@{
18883 struct tuv fff1;
18884 struct xyz fff2;
18885@};
18886
18887struct tyu
18888@{
18889 int a1 : 1;
18890 int a2 : 3;
18891 int a3 : 23;
18892 char a4 : 2;
18893 int64_t a5;
18894 int a6 : 5;
18895 int64_t a7 : 3;
18896@};
18897@end smallexample
18898
18899Issuing a @kbd{ptype /o struct tuv} command would print:
18900
18901@smallexample
18902(@value{GDBP}) ptype /o struct tuv
18903/* offset | size */ type = struct tuv @{
18904/* 0 | 4 */ int a1;
18905/* XXX 4-byte hole */
18906/* 8 | 8 */ char *a2;
18907/* 16 | 4 */ int a3;
18908
18909 /* total size (bytes): 24 */
18910 @}
18911@end smallexample
18912
18913Notice the format of the first column of comments. There, you can
18914find two parts separated by the @samp{|} character: the @emph{offset},
18915which indicates where the field is located inside the struct, in
18916bytes, and the @emph{size} of the field. Another interesting line is
18917the marker of a @emph{hole} in the struct, indicating that it may be
18918possible to pack the struct and make it use less space by reorganizing
18919its fields.
18920
18921It is also possible to print offsets inside an union:
18922
18923@smallexample
18924(@value{GDBP}) ptype /o union qwe
18925/* offset | size */ type = union qwe @{
18926/* 24 */ struct tuv @{
18927/* 0 | 4 */ int a1;
18928/* XXX 4-byte hole */
18929/* 8 | 8 */ char *a2;
18930/* 16 | 4 */ int a3;
18931
18932 /* total size (bytes): 24 */
18933 @} fff1;
18934/* 40 */ struct xyz @{
18935/* 0 | 4 */ int f1;
18936/* 4 | 1 */ char f2;
18937/* XXX 3-byte hole */
18938/* 8 | 8 */ void *f3;
18939/* 16 | 24 */ struct tuv @{
18940/* 16 | 4 */ int a1;
18941/* XXX 4-byte hole */
18942/* 24 | 8 */ char *a2;
18943/* 32 | 4 */ int a3;
18944
18945 /* total size (bytes): 24 */
18946 @} f4;
18947
18948 /* total size (bytes): 40 */
18949 @} fff2;
18950
18951 /* total size (bytes): 40 */
18952 @}
18953@end smallexample
18954
18955In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18956same space (because we are dealing with an union), the offset is not
18957printed for them. However, you can still examine the offset of each
18958of these structures' fields.
18959
18960Another useful scenario is printing the offsets of a struct containing
18961bitfields:
18962
18963@smallexample
18964(@value{GDBP}) ptype /o struct tyu
18965/* offset | size */ type = struct tyu @{
18966/* 0:31 | 4 */ int a1 : 1;
18967/* 0:28 | 4 */ int a2 : 3;
18968/* 0: 5 | 4 */ int a3 : 23;
18969/* 3: 3 | 1 */ signed char a4 : 2;
18970/* XXX 3-bit hole */
18971/* XXX 4-byte hole */
18972/* 8 | 8 */ int64_t a5;
9d3421af
TT
18973/* 16: 0 | 4 */ int a6 : 5;
18974/* 16: 5 | 8 */ int64_t a7 : 3;
18975"/* XXX 7-byte padding */
7c161838
SDJ
18976
18977 /* total size (bytes): 24 */
18978 @}
18979@end smallexample
18980
9d3421af
TT
18981Note how the offset information is now extended to also include the
18982first bit of the bitfield.
53342f27
TT
18983@end table
18984
c906108c 18985@kindex ptype
53342f27 18986@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18987@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18988detailed description of the type, instead of just the name of the type.
18989@xref{Expressions, ,Expressions}.
c906108c 18990
177bc839
JK
18991Contrary to @code{whatis}, @code{ptype} always unrolls any
18992@code{typedef}s in its argument declaration, whether the argument is
18993a variable, expression, or a data type. This means that @code{ptype}
18994of a variable or an expression will not print literally its type as
18995present in the source code---use @code{whatis} for that. @code{typedef}s at
18996the pointer or reference targets are also unrolled. Only @code{typedef}s of
18997fields, methods and inner @code{class typedef}s of @code{struct}s,
18998@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18999
c906108c
SS
19000For example, for this variable declaration:
19001
474c8240 19002@smallexample
177bc839
JK
19003typedef double real_t;
19004struct complex @{ real_t real; double imag; @};
19005typedef struct complex complex_t;
19006complex_t var;
19007real_t *real_pointer_var;
474c8240 19008@end smallexample
c906108c
SS
19009
19010@noindent
19011the two commands give this output:
19012
474c8240 19013@smallexample
c906108c 19014@group
177bc839
JK
19015(@value{GDBP}) whatis var
19016type = complex_t
19017(@value{GDBP}) ptype var
19018type = struct complex @{
19019 real_t real;
19020 double imag;
19021@}
19022(@value{GDBP}) whatis complex_t
19023type = struct complex
19024(@value{GDBP}) whatis struct complex
c906108c 19025type = struct complex
177bc839 19026(@value{GDBP}) ptype struct complex
c906108c 19027type = struct complex @{
177bc839 19028 real_t real;
c906108c
SS
19029 double imag;
19030@}
177bc839
JK
19031(@value{GDBP}) whatis real_pointer_var
19032type = real_t *
19033(@value{GDBP}) ptype real_pointer_var
19034type = double *
c906108c 19035@end group
474c8240 19036@end smallexample
c906108c
SS
19037
19038@noindent
19039As with @code{whatis}, using @code{ptype} without an argument refers to
19040the type of @code{$}, the last value in the value history.
19041
ab1adacd
EZ
19042@cindex incomplete type
19043Sometimes, programs use opaque data types or incomplete specifications
19044of complex data structure. If the debug information included in the
19045program does not allow @value{GDBN} to display a full declaration of
19046the data type, it will say @samp{<incomplete type>}. For example,
19047given these declarations:
19048
19049@smallexample
19050 struct foo;
19051 struct foo *fooptr;
19052@end smallexample
19053
19054@noindent
19055but no definition for @code{struct foo} itself, @value{GDBN} will say:
19056
19057@smallexample
ddb50cd7 19058 (@value{GDBP}) ptype foo
ab1adacd
EZ
19059 $1 = <incomplete type>
19060@end smallexample
19061
19062@noindent
19063``Incomplete type'' is C terminology for data types that are not
19064completely specified.
19065
d69cf9b2
PA
19066@cindex unknown type
19067Othertimes, information about a variable's type is completely absent
19068from the debug information included in the program. This most often
19069happens when the program or library where the variable is defined
19070includes no debug information at all. @value{GDBN} knows the variable
19071exists from inspecting the linker/loader symbol table (e.g., the ELF
19072dynamic symbol table), but such symbols do not contain type
19073information. Inspecting the type of a (global) variable for which
19074@value{GDBN} has no type information shows:
19075
19076@smallexample
19077 (@value{GDBP}) ptype var
19078 type = <data variable, no debug info>
19079@end smallexample
19080
19081@xref{Variables, no debug info variables}, for how to print the values
19082of such variables.
19083
c906108c 19084@kindex info types
a8eab7c6 19085@item info types [-q] [@var{regexp}]
09d4efe1
EZ
19086Print a brief description of all types whose names match the regular
19087expression @var{regexp} (or all types in your program, if you supply
19088no argument). Each complete typename is matched as though it were a
19089complete line; thus, @samp{i type value} gives information on all
19090types in your program whose names include the string @code{value}, but
19091@samp{i type ^value$} gives information only on types whose complete
19092name is @code{value}.
c906108c 19093
20813a0b
PW
19094In programs using different languages, @value{GDBN} chooses the syntax
19095to print the type description according to the
19096@samp{set language} value: using @samp{set language auto}
19097(see @ref{Automatically, ,Set Language Automatically}) means to use the
19098language of the type, other values mean to use
19099the manually specified language (see @ref{Manually, ,Set Language Manually}).
19100
c906108c
SS
19101This command differs from @code{ptype} in two ways: first, like
19102@code{whatis}, it does not print a detailed description; second, it
b744723f 19103lists all source files and line numbers where a type is defined.
c906108c 19104
a8eab7c6
AB
19105The output from @samp{into types} is proceeded with a header line
19106describing what types are being listed. The optional flag @samp{-q},
19107which stands for @samp{quiet}, disables printing this header
19108information.
19109
18a9fc12
TT
19110@kindex info type-printers
19111@item info type-printers
19112Versions of @value{GDBN} that ship with Python scripting enabled may
19113have ``type printers'' available. When using @command{ptype} or
19114@command{whatis}, these printers are consulted when the name of a type
19115is needed. @xref{Type Printing API}, for more information on writing
19116type printers.
19117
19118@code{info type-printers} displays all the available type printers.
19119
19120@kindex enable type-printer
19121@kindex disable type-printer
19122@item enable type-printer @var{name}@dots{}
19123@item disable type-printer @var{name}@dots{}
19124These commands can be used to enable or disable type printers.
19125
b37052ae
EZ
19126@kindex info scope
19127@cindex local variables
09d4efe1 19128@item info scope @var{location}
b37052ae 19129List all the variables local to a particular scope. This command
09d4efe1
EZ
19130accepts a @var{location} argument---a function name, a source line, or
19131an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
19132to the scope defined by that location. (@xref{Specify Location}, for
19133details about supported forms of @var{location}.) For example:
b37052ae
EZ
19134
19135@smallexample
19136(@value{GDBP}) @b{info scope command_line_handler}
19137Scope for command_line_handler:
19138Symbol rl is an argument at stack/frame offset 8, length 4.
19139Symbol linebuffer is in static storage at address 0x150a18, length 4.
19140Symbol linelength is in static storage at address 0x150a1c, length 4.
19141Symbol p is a local variable in register $esi, length 4.
19142Symbol p1 is a local variable in register $ebx, length 4.
19143Symbol nline is a local variable in register $edx, length 4.
19144Symbol repeat is a local variable at frame offset -8, length 4.
19145@end smallexample
19146
f5c37c66
EZ
19147@noindent
19148This command is especially useful for determining what data to collect
19149during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19150collect}.
19151
c906108c
SS
19152@kindex info source
19153@item info source
919d772c
JB
19154Show information about the current source file---that is, the source file for
19155the function containing the current point of execution:
19156@itemize @bullet
19157@item
19158the name of the source file, and the directory containing it,
19159@item
19160the directory it was compiled in,
19161@item
19162its length, in lines,
19163@item
19164which programming language it is written in,
19165@item
b6577aab
DE
19166if the debug information provides it, the program that compiled the file
19167(which may include, e.g., the compiler version and command line arguments),
19168@item
919d772c
JB
19169whether the executable includes debugging information for that file, and
19170if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19171@item
19172whether the debugging information includes information about
19173preprocessor macros.
19174@end itemize
19175
c906108c
SS
19176
19177@kindex info sources
19178@item info sources
19179Print the names of all source files in your program for which there is
19180debugging information, organized into two lists: files whose symbols
19181have already been read, and files whose symbols will be read when needed.
19182
ae60f04e
PW
19183@item info sources [-dirname | -basename] [--] [@var{regexp}]
19184Like @samp{info sources}, but only print the names of the files
19185matching the provided @var{regexp}.
19186By default, the @var{regexp} is used to match anywhere in the filename.
19187If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19188If @code{-basename}, only files having a basename matching @var{regexp}
19189are shown.
19190The matching is case-sensitive, except on operating systems that
19191have case-insensitive filesystem (e.g., MS-Windows).
19192
c906108c 19193@kindex info functions
4acfdd20 19194@item info functions [-q] [-n]
c906108c 19195Print the names and data types of all defined functions.
b744723f
AA
19196Similarly to @samp{info types}, this command groups its output by source
19197files and annotates each function definition with its source line
19198number.
c906108c 19199
20813a0b
PW
19200In programs using different languages, @value{GDBN} chooses the syntax
19201to print the function name and type according to the
19202@samp{set language} value: using @samp{set language auto}
19203(see @ref{Automatically, ,Set Language Automatically}) means to use the
19204language of the function, other values mean to use
19205the manually specified language (see @ref{Manually, ,Set Language Manually}).
19206
4acfdd20
AB
19207The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19208results. A non-debugging symbol is a symbol that comes from the
19209executable's symbol table, not from the debug information (for
19210example, DWARF) associated with the executable.
19211
d321477b
PW
19212The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19213printing header information and messages explaining why no functions
19214have been printed.
19215
4acfdd20 19216@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19217Like @samp{info functions}, but only print the names and data types
19218of the functions selected with the provided regexp(s).
19219
19220If @var{regexp} is provided, print only the functions whose names
19221match the regular expression @var{regexp}.
19222Thus, @samp{info fun step} finds all functions whose
b744723f
AA
19223names include @code{step}; @samp{info fun ^step} finds those whose names
19224start with @code{step}. If a function name contains characters that
19225conflict with the regular expression language (e.g.@:
1c5dfdad 19226@samp{operator*()}), they may be quoted with a backslash.
c906108c 19227
d321477b
PW
19228If @var{type_regexp} is provided, print only the functions whose
19229types, as printed by the @code{whatis} command, match
19230the regular expression @var{type_regexp}.
19231If @var{type_regexp} contains space(s), it should be enclosed in
19232quote characters. If needed, use backslash to escape the meaning
19233of special characters or quotes.
19234Thus, @samp{info fun -t '^int ('} finds the functions that return
19235an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19236have an argument type containing int; @samp{info fun -t '^int (' ^step}
19237finds the functions whose names start with @code{step} and that return
19238int.
19239
19240If both @var{regexp} and @var{type_regexp} are provided, a function
19241is printed only if its name matches @var{regexp} and its type matches
19242@var{type_regexp}.
19243
19244
c906108c 19245@kindex info variables
4acfdd20 19246@item info variables [-q] [-n]
0fe7935b 19247Print the names and data types of all variables that are defined
6ca652b0 19248outside of functions (i.e.@: excluding local variables).
b744723f
AA
19249The printed variables are grouped by source files and annotated with
19250their respective source line numbers.
c906108c 19251
20813a0b
PW
19252In programs using different languages, @value{GDBN} chooses the syntax
19253to print the variable name and type according to the
19254@samp{set language} value: using @samp{set language auto}
19255(see @ref{Automatically, ,Set Language Automatically}) means to use the
19256language of the variable, other values mean to use
19257the manually specified language (see @ref{Manually, ,Set Language Manually}).
19258
4acfdd20
AB
19259The @samp{-n} flag excludes non-debugging symbols from the results.
19260
d321477b
PW
19261The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19262printing header information and messages explaining why no variables
19263have been printed.
19264
4acfdd20 19265@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19266Like @kbd{info variables}, but only print the variables selected
19267with the provided regexp(s).
19268
19269If @var{regexp} is provided, print only the variables whose names
19270match the regular expression @var{regexp}.
19271
19272If @var{type_regexp} is provided, print only the variables whose
19273types, as printed by the @code{whatis} command, match
19274the regular expression @var{type_regexp}.
19275If @var{type_regexp} contains space(s), it should be enclosed in
19276quote characters. If needed, use backslash to escape the meaning
19277of special characters or quotes.
19278
19279If both @var{regexp} and @var{type_regexp} are provided, an argument
19280is printed only if its name matches @var{regexp} and its type matches
19281@var{type_regexp}.
c906108c 19282
59c35742
AB
19283@kindex info modules
19284@cindex modules
19285@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19286List all Fortran modules in the program, or all modules matching the
19287optional regular expression @var{regexp}.
19288
19289The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19290printing header information and messages explaining why no modules
19291have been printed.
165f8965
AB
19292
19293@kindex info module
19294@cindex Fortran modules, information about
19295@cindex functions and variables by Fortran module
19296@cindex module functions and variables
19297@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19298@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19299List all functions or variables within all Fortran modules. The set
19300of functions or variables listed can be limited by providing some or
19301all of the optional regular expressions. If @var{module-regexp} is
19302provided, then only Fortran modules matching @var{module-regexp} will
19303be searched. Only functions or variables whose type matches the
19304optional regular expression @var{type-regexp} will be listed. And
19305only functions or variables whose name matches the optional regular
19306expression @var{regexp} will be listed.
19307
19308The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19309printing header information and messages explaining why no functions
19310or variables have been printed.
59c35742 19311
b37303ee 19312@kindex info classes
721c2651 19313@cindex Objective-C, classes and selectors
b37303ee
AF
19314@item info classes
19315@itemx info classes @var{regexp}
19316Display all Objective-C classes in your program, or
19317(with the @var{regexp} argument) all those matching a particular regular
19318expression.
19319
19320@kindex info selectors
19321@item info selectors
19322@itemx info selectors @var{regexp}
19323Display all Objective-C selectors in your program, or
19324(with the @var{regexp} argument) all those matching a particular regular
19325expression.
19326
c906108c
SS
19327@ignore
19328This was never implemented.
19329@kindex info methods
19330@item info methods
19331@itemx info methods @var{regexp}
19332The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19333methods within C@t{++} program, or (with the @var{regexp} argument) a
19334specific set of methods found in the various C@t{++} classes. Many
19335C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19336from the @code{ptype} command can be overwhelming and hard to use. The
19337@code{info-methods} command filters the methods, printing only those
19338which match the regular-expression @var{regexp}.
19339@end ignore
19340
9c16f35a 19341@cindex opaque data types
c906108c
SS
19342@kindex set opaque-type-resolution
19343@item set opaque-type-resolution on
19344Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19345declared as a pointer to a @code{struct}, @code{class}, or
19346@code{union}---for example, @code{struct MyType *}---that is used in one
19347source file although the full declaration of @code{struct MyType} is in
19348another source file. The default is on.
19349
19350A change in the setting of this subcommand will not take effect until
19351the next time symbols for a file are loaded.
19352
19353@item set opaque-type-resolution off
19354Tell @value{GDBN} not to resolve opaque types. In this case, the type
19355is printed as follows:
19356@smallexample
19357@{<no data fields>@}
19358@end smallexample
19359
19360@kindex show opaque-type-resolution
19361@item show opaque-type-resolution
19362Show whether opaque types are resolved or not.
c906108c 19363
770e7fc7
DE
19364@kindex set print symbol-loading
19365@cindex print messages when symbols are loaded
19366@item set print symbol-loading
19367@itemx set print symbol-loading full
19368@itemx set print symbol-loading brief
19369@itemx set print symbol-loading off
19370The @code{set print symbol-loading} command allows you to control the
19371printing of messages when @value{GDBN} loads symbol information.
19372By default a message is printed for the executable and one for each
19373shared library, and normally this is what you want. However, when
19374debugging apps with large numbers of shared libraries these messages
19375can be annoying.
19376When set to @code{brief} a message is printed for each executable,
19377and when @value{GDBN} loads a collection of shared libraries at once
19378it will only print one message regardless of the number of shared
19379libraries. When set to @code{off} no messages are printed.
19380
19381@kindex show print symbol-loading
19382@item show print symbol-loading
19383Show whether messages will be printed when a @value{GDBN} command
19384entered from the keyboard causes symbol information to be loaded.
19385
c906108c
SS
19386@kindex maint print symbols
19387@cindex symbol dump
19388@kindex maint print psymbols
19389@cindex partial symbol dump
7c57fa1e
YQ
19390@kindex maint print msymbols
19391@cindex minimal symbol dump
34c41c68
DE
19392@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19393@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19394@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19395@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19396@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19397Write a dump of debugging symbol data into the file @var{filename} or
19398the terminal if @var{filename} is unspecified.
19399If @code{-objfile @var{objfile}} is specified, only dump symbols for
19400that objfile.
19401If @code{-pc @var{address}} is specified, only dump symbols for the file
19402with code at that address. Note that @var{address} may be a symbol like
19403@code{main}.
19404If @code{-source @var{source}} is specified, only dump symbols for that
19405source file.
19406
19407These commands are used to debug the @value{GDBN} symbol-reading code.
19408These commands do not modify internal @value{GDBN} state, therefore
19409@samp{maint print symbols} will only print symbols for already expanded symbol
19410tables.
19411You can use the command @code{info sources} to find out which files these are.
19412If you use @samp{maint print psymbols} instead, the dump shows information
19413about symbols that @value{GDBN} only knows partially---that is, symbols
19414defined in files that @value{GDBN} has skimmed, but not yet read completely.
19415Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19416``ELF symbols''.
19417
79a6e687 19418@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19419@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19420
5e7b2f39
JB
19421@kindex maint info symtabs
19422@kindex maint info psymtabs
44ea7b70
JB
19423@cindex listing @value{GDBN}'s internal symbol tables
19424@cindex symbol tables, listing @value{GDBN}'s internal
19425@cindex full symbol tables, listing @value{GDBN}'s internal
19426@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19427@item maint info symtabs @r{[} @var{regexp} @r{]}
19428@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19429
19430List the @code{struct symtab} or @code{struct partial_symtab}
19431structures whose names match @var{regexp}. If @var{regexp} is not
19432given, list them all. The output includes expressions which you can
19433copy into a @value{GDBN} debugging this one to examine a particular
19434structure in more detail. For example:
19435
19436@smallexample
5e7b2f39 19437(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19438@{ objfile /home/gnu/build/gdb/gdb
19439 ((struct objfile *) 0x82e69d0)
b383017d 19440 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19441 ((struct partial_symtab *) 0x8474b10)
19442 readin no
19443 fullname (null)
19444 text addresses 0x814d3c8 -- 0x8158074
19445 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19446 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19447 dependencies (none)
19448 @}
19449@}
5e7b2f39 19450(@value{GDBP}) maint info symtabs
44ea7b70
JB
19451(@value{GDBP})
19452@end smallexample
19453@noindent
19454We see that there is one partial symbol table whose filename contains
19455the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19456and we see that @value{GDBN} has not read in any symtabs yet at all.
19457If we set a breakpoint on a function, that will cause @value{GDBN} to
19458read the symtab for the compilation unit containing that function:
19459
19460@smallexample
19461(@value{GDBP}) break dwarf2_psymtab_to_symtab
19462Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19463line 1574.
5e7b2f39 19464(@value{GDBP}) maint info symtabs
b383017d 19465@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19466 ((struct objfile *) 0x82e69d0)
b383017d 19467 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19468 ((struct symtab *) 0x86c1f38)
19469 dirname (null)
19470 fullname (null)
19471 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19472 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19473 debugformat DWARF 2
19474 @}
19475@}
b383017d 19476(@value{GDBP})
44ea7b70 19477@end smallexample
44ea7b70 19478
f2403c39
AB
19479@kindex maint info line-table
19480@cindex listing @value{GDBN}'s internal line tables
19481@cindex line tables, listing @value{GDBN}'s internal
19482@item maint info line-table @r{[} @var{regexp} @r{]}
19483
19484List the @code{struct linetable} from all @code{struct symtab}
19485instances whose name matches @var{regexp}. If @var{regexp} is not
19486given, list the @code{struct linetable} from all @code{struct symtab}.
19487
f57d2163
DE
19488@kindex maint set symbol-cache-size
19489@cindex symbol cache size
19490@item maint set symbol-cache-size @var{size}
19491Set the size of the symbol cache to @var{size}.
19492The default size is intended to be good enough for debugging
19493most applications. This option exists to allow for experimenting
19494with different sizes.
19495
19496@kindex maint show symbol-cache-size
19497@item maint show symbol-cache-size
19498Show the size of the symbol cache.
19499
19500@kindex maint print symbol-cache
19501@cindex symbol cache, printing its contents
19502@item maint print symbol-cache
19503Print the contents of the symbol cache.
19504This is useful when debugging symbol cache issues.
19505
19506@kindex maint print symbol-cache-statistics
19507@cindex symbol cache, printing usage statistics
19508@item maint print symbol-cache-statistics
19509Print symbol cache usage statistics.
19510This helps determine how well the cache is being utilized.
19511
50a5f187 19512@kindex maint flush symbol-cache
f57d2163
DE
19513@kindex maint flush-symbol-cache
19514@cindex symbol cache, flushing
50a5f187
AB
19515@item maint flush symbol-cache
19516@itemx maint flush-symbol-cache
19517Flush the contents of the symbol cache, all entries are removed. This
19518command is useful when debugging the symbol cache. It is also useful
19519when collecting performance data. The command @code{maint
19520flush-symbol-cache} is deprecated in favor of @code{maint flush
19521symbol-cache}..
f57d2163
DE
19522
19523@end table
6a3ca067 19524
6d2ebf8b 19525@node Altering
c906108c
SS
19526@chapter Altering Execution
19527
19528Once you think you have found an error in your program, you might want to
19529find out for certain whether correcting the apparent error would lead to
19530correct results in the rest of the run. You can find the answer by
19531experiment, using the @value{GDBN} features for altering execution of the
19532program.
19533
19534For example, you can store new values into variables or memory
7a292a7a
SS
19535locations, give your program a signal, restart it at a different
19536address, or even return prematurely from a function.
c906108c
SS
19537
19538@menu
19539* Assignment:: Assignment to variables
19540* Jumping:: Continuing at a different address
c906108c 19541* Signaling:: Giving your program a signal
c906108c
SS
19542* Returning:: Returning from a function
19543* Calling:: Calling your program's functions
19544* Patching:: Patching your program
bb2ec1b3 19545* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19546@end menu
19547
6d2ebf8b 19548@node Assignment
79a6e687 19549@section Assignment to Variables
c906108c
SS
19550
19551@cindex assignment
19552@cindex setting variables
19553To alter the value of a variable, evaluate an assignment expression.
19554@xref{Expressions, ,Expressions}. For example,
19555
474c8240 19556@smallexample
c906108c 19557print x=4
474c8240 19558@end smallexample
c906108c
SS
19559
19560@noindent
19561stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19562value of the assignment expression (which is 4).
c906108c
SS
19563@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19564information on operators in supported languages.
c906108c
SS
19565
19566@kindex set variable
19567@cindex variables, setting
19568If you are not interested in seeing the value of the assignment, use the
19569@code{set} command instead of the @code{print} command. @code{set} is
19570really the same as @code{print} except that the expression's value is
19571not printed and is not put in the value history (@pxref{Value History,
79a6e687 19572,Value History}). The expression is evaluated only for its effects.
c906108c 19573
c906108c
SS
19574If the beginning of the argument string of the @code{set} command
19575appears identical to a @code{set} subcommand, use the @code{set
19576variable} command instead of just @code{set}. This command is identical
19577to @code{set} except for its lack of subcommands. For example, if your
19578program has a variable @code{width}, you get an error if you try to set
19579a new value with just @samp{set width=13}, because @value{GDBN} has the
19580command @code{set width}:
19581
474c8240 19582@smallexample
c906108c
SS
19583(@value{GDBP}) whatis width
19584type = double
19585(@value{GDBP}) p width
19586$4 = 13
19587(@value{GDBP}) set width=47
19588Invalid syntax in expression.
474c8240 19589@end smallexample
c906108c
SS
19590
19591@noindent
19592The invalid expression, of course, is @samp{=47}. In
19593order to actually set the program's variable @code{width}, use
19594
474c8240 19595@smallexample
c906108c 19596(@value{GDBP}) set var width=47
474c8240 19597@end smallexample
53a5351d 19598
c906108c
SS
19599Because the @code{set} command has many subcommands that can conflict
19600with the names of program variables, it is a good idea to use the
19601@code{set variable} command instead of just @code{set}. For example, if
19602your program has a variable @code{g}, you run into problems if you try
19603to set a new value with just @samp{set g=4}, because @value{GDBN} has
19604the command @code{set gnutarget}, abbreviated @code{set g}:
19605
474c8240 19606@smallexample
c906108c
SS
19607@group
19608(@value{GDBP}) whatis g
19609type = double
19610(@value{GDBP}) p g
19611$1 = 1
19612(@value{GDBP}) set g=4
2df3850c 19613(@value{GDBP}) p g
c906108c
SS
19614$2 = 1
19615(@value{GDBP}) r
19616The program being debugged has been started already.
19617Start it from the beginning? (y or n) y
19618Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19619"/home/smith/cc_progs/a.out": can't open to read symbols:
19620 Invalid bfd target.
c906108c
SS
19621(@value{GDBP}) show g
19622The current BFD target is "=4".
19623@end group
474c8240 19624@end smallexample
c906108c
SS
19625
19626@noindent
19627The program variable @code{g} did not change, and you silently set the
19628@code{gnutarget} to an invalid value. In order to set the variable
19629@code{g}, use
19630
474c8240 19631@smallexample
c906108c 19632(@value{GDBP}) set var g=4
474c8240 19633@end smallexample
c906108c
SS
19634
19635@value{GDBN} allows more implicit conversions in assignments than C; you can
19636freely store an integer value into a pointer variable or vice versa,
19637and you can convert any structure to any other structure that is the
19638same length or shorter.
19639@comment FIXME: how do structs align/pad in these conversions?
19640@comment /doc@cygnus.com 18dec1990
19641
19642To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19643construct to generate a value of specified type at a specified address
19644(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19645to memory location @code{0x83040} as an integer (which implies a certain size
19646and representation in memory), and
19647
474c8240 19648@smallexample
c906108c 19649set @{int@}0x83040 = 4
474c8240 19650@end smallexample
c906108c
SS
19651
19652@noindent
19653stores the value 4 into that memory location.
19654
6d2ebf8b 19655@node Jumping
79a6e687 19656@section Continuing at a Different Address
c906108c
SS
19657
19658Ordinarily, when you continue your program, you do so at the place where
19659it stopped, with the @code{continue} command. You can instead continue at
19660an address of your own choosing, with the following commands:
19661
19662@table @code
19663@kindex jump
c1d780c2 19664@kindex j @r{(@code{jump})}
629500fa 19665@item jump @var{location}
c1d780c2 19666@itemx j @var{location}
629500fa
KS
19667Resume execution at @var{location}. Execution stops again immediately
19668if there is a breakpoint there. @xref{Specify Location}, for a description
19669of the different forms of @var{location}. It is common
2a25a5ba
EZ
19670practice to use the @code{tbreak} command in conjunction with
19671@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19672
19673The @code{jump} command does not change the current stack frame, or
19674the stack pointer, or the contents of any memory location or any
629500fa 19675register other than the program counter. If @var{location} is in
c906108c
SS
19676a different function from the one currently executing, the results may
19677be bizarre if the two functions expect different patterns of arguments or
19678of local variables. For this reason, the @code{jump} command requests
19679confirmation if the specified line is not in the function currently
19680executing. However, even bizarre results are predictable if you are
19681well acquainted with the machine-language code of your program.
c906108c
SS
19682@end table
19683
53a5351d
JM
19684On many systems, you can get much the same effect as the @code{jump}
19685command by storing a new value into the register @code{$pc}. The
19686difference is that this does not start your program running; it only
19687changes the address of where it @emph{will} run when you continue. For
19688example,
c906108c 19689
474c8240 19690@smallexample
c906108c 19691set $pc = 0x485
474c8240 19692@end smallexample
c906108c
SS
19693
19694@noindent
19695makes the next @code{continue} command or stepping command execute at
19696address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19697@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19698
19699The most common occasion to use the @code{jump} command is to back
19700up---perhaps with more breakpoints set---over a portion of a program
19701that has already executed, in order to examine its execution in more
19702detail.
19703
c906108c 19704@c @group
6d2ebf8b 19705@node Signaling
79a6e687 19706@section Giving your Program a Signal
9c16f35a 19707@cindex deliver a signal to a program
c906108c
SS
19708
19709@table @code
19710@kindex signal
19711@item signal @var{signal}
70509625 19712Resume execution where your program is stopped, but immediately give it the
697aa1b7 19713signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19714signal. For example, on many systems @code{signal 2} and @code{signal
19715SIGINT} are both ways of sending an interrupt signal.
19716
19717Alternatively, if @var{signal} is zero, continue execution without
19718giving a signal. This is useful when your program stopped on account of
ae606bee 19719a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19720@code{continue} command; @samp{signal 0} causes it to resume without a
19721signal.
19722
70509625
PA
19723@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19724delivered to the currently selected thread, not the thread that last
19725reported a stop. This includes the situation where a thread was
19726stopped due to a signal. So if you want to continue execution
19727suppressing the signal that stopped a thread, you should select that
19728same thread before issuing the @samp{signal 0} command. If you issue
19729the @samp{signal 0} command with another thread as the selected one,
19730@value{GDBN} detects that and asks for confirmation.
19731
c906108c
SS
19732Invoking the @code{signal} command is not the same as invoking the
19733@code{kill} utility from the shell. Sending a signal with @code{kill}
19734causes @value{GDBN} to decide what to do with the signal depending on
19735the signal handling tables (@pxref{Signals}). The @code{signal} command
19736passes the signal directly to your program.
19737
81219e53
DE
19738@code{signal} does not repeat when you press @key{RET} a second time
19739after executing the command.
19740
19741@kindex queue-signal
19742@item queue-signal @var{signal}
19743Queue @var{signal} to be delivered immediately to the current thread
19744when execution of the thread resumes. The @var{signal} can be the name or
19745the number of a signal. For example, on many systems @code{signal 2} and
19746@code{signal SIGINT} are both ways of sending an interrupt signal.
19747The handling of the signal must be set to pass the signal to the program,
19748otherwise @value{GDBN} will report an error.
19749You can control the handling of signals from @value{GDBN} with the
19750@code{handle} command (@pxref{Signals}).
19751
19752Alternatively, if @var{signal} is zero, any currently queued signal
19753for the current thread is discarded and when execution resumes no signal
19754will be delivered. This is useful when your program stopped on account
19755of a signal and would ordinarily see the signal when resumed with the
19756@code{continue} command.
19757
19758This command differs from the @code{signal} command in that the signal
19759is just queued, execution is not resumed. And @code{queue-signal} cannot
19760be used to pass a signal whose handling state has been set to @code{nopass}
19761(@pxref{Signals}).
19762@end table
19763@c @end group
c906108c 19764
e5f8a7cc
PA
19765@xref{stepping into signal handlers}, for information on how stepping
19766commands behave when the thread has a signal queued.
19767
6d2ebf8b 19768@node Returning
79a6e687 19769@section Returning from a Function
c906108c
SS
19770
19771@table @code
19772@cindex returning from a function
19773@kindex return
19774@item return
19775@itemx return @var{expression}
19776You can cancel execution of a function call with the @code{return}
19777command. If you give an
19778@var{expression} argument, its value is used as the function's return
19779value.
19780@end table
19781
19782When you use @code{return}, @value{GDBN} discards the selected stack frame
19783(and all frames within it). You can think of this as making the
19784discarded frame return prematurely. If you wish to specify a value to
19785be returned, give that value as the argument to @code{return}.
19786
19787This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19788Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19789innermost remaining frame. That frame becomes selected. The
19790specified value is stored in the registers used for returning values
19791of functions.
19792
19793The @code{return} command does not resume execution; it leaves the
19794program stopped in the state that would exist if the function had just
19795returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19796and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19797selected stack frame returns naturally.
19798
61ff14c6
JK
19799@value{GDBN} needs to know how the @var{expression} argument should be set for
19800the inferior. The concrete registers assignment depends on the OS ABI and the
19801type being returned by the selected stack frame. For example it is common for
19802OS ABI to return floating point values in FPU registers while integer values in
19803CPU registers. Still some ABIs return even floating point values in CPU
19804registers. Larger integer widths (such as @code{long long int}) also have
19805specific placement rules. @value{GDBN} already knows the OS ABI from its
19806current target so it needs to find out also the type being returned to make the
19807assignment into the right register(s).
19808
19809Normally, the selected stack frame has debug info. @value{GDBN} will always
19810use the debug info instead of the implicit type of @var{expression} when the
19811debug info is available. For example, if you type @kbd{return -1}, and the
19812function in the current stack frame is declared to return a @code{long long
19813int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19814into a @code{long long int}:
19815
19816@smallexample
19817Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1981829 return 31;
19819(@value{GDBP}) return -1
19820Make func return now? (y or n) y
19821#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1982243 printf ("result=%lld\n", func ());
19823(@value{GDBP})
19824@end smallexample
19825
19826However, if the selected stack frame does not have a debug info, e.g., if the
19827function was compiled without debug info, @value{GDBN} has to find out the type
19828to return from user. Specifying a different type by mistake may set the value
19829in different inferior registers than the caller code expects. For example,
19830typing @kbd{return -1} with its implicit type @code{int} would set only a part
19831of a @code{long long int} result for a debug info less function (on 32-bit
19832architectures). Therefore the user is required to specify the return type by
19833an appropriate cast explicitly:
19834
19835@smallexample
19836Breakpoint 2, 0x0040050b in func ()
19837(@value{GDBP}) return -1
19838Return value type not available for selected stack frame.
19839Please use an explicit cast of the value to return.
19840(@value{GDBP}) return (long long int) -1
19841Make selected stack frame return now? (y or n) y
19842#0 0x00400526 in main ()
19843(@value{GDBP})
19844@end smallexample
19845
6d2ebf8b 19846@node Calling
79a6e687 19847@section Calling Program Functions
c906108c 19848
f8568604 19849@table @code
c906108c 19850@cindex calling functions
f8568604
EZ
19851@cindex inferior functions, calling
19852@item print @var{expr}
d3e8051b 19853Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19854The expression may include calls to functions in the program being
f8568604
EZ
19855debugged.
19856
c906108c 19857@kindex call
c906108c
SS
19858@item call @var{expr}
19859Evaluate the expression @var{expr} without displaying @code{void}
19860returned values.
c906108c
SS
19861
19862You can use this variant of the @code{print} command if you want to
f8568604
EZ
19863execute a function from your program that does not return anything
19864(a.k.a.@: @dfn{a void function}), but without cluttering the output
19865with @code{void} returned values that @value{GDBN} will otherwise
19866print. If the result is not void, it is printed and saved in the
19867value history.
19868@end table
19869
9c16f35a
EZ
19870It is possible for the function you call via the @code{print} or
19871@code{call} command to generate a signal (e.g., if there's a bug in
19872the function, or if you passed it incorrect arguments). What happens
19873in that case is controlled by the @code{set unwindonsignal} command.
19874
7cd1089b
PM
19875Similarly, with a C@t{++} program it is possible for the function you
19876call via the @code{print} or @code{call} command to generate an
19877exception that is not handled due to the constraints of the dummy
19878frame. In this case, any exception that is raised in the frame, but has
19879an out-of-frame exception handler will not be found. GDB builds a
19880dummy-frame for the inferior function call, and the unwinder cannot
19881seek for exception handlers outside of this dummy-frame. What happens
19882in that case is controlled by the
19883@code{set unwind-on-terminating-exception} command.
19884
9c16f35a
EZ
19885@table @code
19886@item set unwindonsignal
19887@kindex set unwindonsignal
19888@cindex unwind stack in called functions
19889@cindex call dummy stack unwinding
19890Set unwinding of the stack if a signal is received while in a function
19891that @value{GDBN} called in the program being debugged. If set to on,
19892@value{GDBN} unwinds the stack it created for the call and restores
19893the context to what it was before the call. If set to off (the
19894default), @value{GDBN} stops in the frame where the signal was
19895received.
19896
19897@item show unwindonsignal
19898@kindex show unwindonsignal
19899Show the current setting of stack unwinding in the functions called by
19900@value{GDBN}.
7cd1089b
PM
19901
19902@item set unwind-on-terminating-exception
19903@kindex set unwind-on-terminating-exception
19904@cindex unwind stack in called functions with unhandled exceptions
19905@cindex call dummy stack unwinding on unhandled exception.
19906Set unwinding of the stack if a C@t{++} exception is raised, but left
19907unhandled while in a function that @value{GDBN} called in the program being
19908debugged. If set to on (the default), @value{GDBN} unwinds the stack
19909it created for the call and restores the context to what it was before
19910the call. If set to off, @value{GDBN} the exception is delivered to
19911the default C@t{++} exception handler and the inferior terminated.
19912
19913@item show unwind-on-terminating-exception
19914@kindex show unwind-on-terminating-exception
19915Show the current setting of stack unwinding in the functions called by
19916@value{GDBN}.
19917
136afab8
PW
19918@item set may-call-functions
19919@kindex set may-call-functions
19920@cindex disabling calling functions in the program
19921@cindex calling functions in the program, disabling
19922Set permission to call functions in the program.
19923This controls whether @value{GDBN} will attempt to call functions in
19924the program, such as with expressions in the @code{print} command. It
19925defaults to @code{on}.
19926
19927To call a function in the program, @value{GDBN} has to temporarily
19928modify the state of the inferior. This has potentially undesired side
19929effects. Also, having @value{GDBN} call nested functions is likely to
19930be erroneous and may even crash the program being debugged. You can
19931avoid such hazards by forbidding @value{GDBN} from calling functions
19932in the program being debugged. If calling functions in the program
19933is forbidden, GDB will throw an error when a command (such as printing
19934an expression) starts a function call in the program.
19935
19936@item show may-call-functions
19937@kindex show may-call-functions
19938Show permission to call functions in the program.
19939
9c16f35a
EZ
19940@end table
19941
d69cf9b2
PA
19942@subsection Calling functions with no debug info
19943
19944@cindex no debug info functions
19945Sometimes, a function you wish to call is missing debug information.
19946In such case, @value{GDBN} does not know the type of the function,
19947including the types of the function's parameters. To avoid calling
19948the inferior function incorrectly, which could result in the called
19949function functioning erroneously and even crash, @value{GDBN} refuses
19950to call the function unless you tell it the type of the function.
19951
19952For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19953to do that. The simplest is to cast the call to the function's
19954declared return type. For example:
19955
19956@smallexample
19957(@value{GDBP}) p getenv ("PATH")
19958'getenv' has unknown return type; cast the call to its declared return type
19959(@value{GDBP}) p (char *) getenv ("PATH")
19960$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19961@end smallexample
19962
19963Casting the return type of a no-debug function is equivalent to
19964casting the function to a pointer to a prototyped function that has a
19965prototype that matches the types of the passed-in arguments, and
19966calling that. I.e., the call above is equivalent to:
19967
19968@smallexample
19969(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19970@end smallexample
19971
19972@noindent
19973and given this prototyped C or C++ function with float parameters:
19974
19975@smallexample
19976float multiply (float v1, float v2) @{ return v1 * v2; @}
19977@end smallexample
19978
19979@noindent
19980these calls are equivalent:
19981
19982@smallexample
19983(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19984(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19985@end smallexample
19986
19987If the function you wish to call is declared as unprototyped (i.e.@:
19988old K&R style), you must use the cast-to-function-pointer syntax, so
19989that @value{GDBN} knows that it needs to apply default argument
19990promotions (promote float arguments to double). @xref{ABI, float
19991promotion}. For example, given this unprototyped C function with
19992float parameters, and no debug info:
19993
19994@smallexample
19995float
19996multiply_noproto (v1, v2)
19997 float v1, v2;
19998@{
19999 return v1 * v2;
20000@}
20001@end smallexample
20002
20003@noindent
20004you call it like this:
20005
20006@smallexample
20007 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20008@end smallexample
c906108c 20009
6d2ebf8b 20010@node Patching
79a6e687 20011@section Patching Programs
7a292a7a 20012
c906108c
SS
20013@cindex patching binaries
20014@cindex writing into executables
c906108c 20015@cindex writing into corefiles
c906108c 20016
7a292a7a
SS
20017By default, @value{GDBN} opens the file containing your program's
20018executable code (or the corefile) read-only. This prevents accidental
20019alterations to machine code; but it also prevents you from intentionally
20020patching your program's binary.
c906108c
SS
20021
20022If you'd like to be able to patch the binary, you can specify that
20023explicitly with the @code{set write} command. For example, you might
20024want to turn on internal debugging flags, or even to make emergency
20025repairs.
20026
20027@table @code
20028@kindex set write
20029@item set write on
20030@itemx set write off
7a292a7a 20031If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 20032core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
20033off} (the default), @value{GDBN} opens them read-only.
20034
20035If you have already loaded a file, you must load it again (using the
7a292a7a
SS
20036@code{exec-file} or @code{core-file} command) after changing @code{set
20037write}, for your new setting to take effect.
c906108c
SS
20038
20039@item show write
20040@kindex show write
7a292a7a
SS
20041Display whether executable files and core files are opened for writing
20042as well as reading.
c906108c
SS
20043@end table
20044
bb2ec1b3
TT
20045@node Compiling and Injecting Code
20046@section Compiling and injecting code in @value{GDBN}
20047@cindex injecting code
20048@cindex writing into executables
20049@cindex compiling code
20050
20051@value{GDBN} supports on-demand compilation and code injection into
20052programs running under @value{GDBN}. GCC 5.0 or higher built with
20053@file{libcc1.so} must be installed for this functionality to be enabled.
20054This functionality is implemented with the following commands.
20055
20056@table @code
20057@kindex compile code
20058@item compile code @var{source-code}
20059@itemx compile code -raw @var{--} @var{source-code}
20060Compile @var{source-code} with the compiler language found as the current
20061language in @value{GDBN} (@pxref{Languages}). If compilation and
20062injection is not supported with the current language specified in
20063@value{GDBN}, or the compiler does not support this feature, an error
20064message will be printed. If @var{source-code} compiles and links
20065successfully, @value{GDBN} will load the object-code emitted,
20066and execute it within the context of the currently selected inferior.
20067It is important to note that the compiled code is executed immediately.
20068After execution, the compiled code is removed from @value{GDBN} and any
20069new types or variables you have defined will be deleted.
20070
20071The command allows you to specify @var{source-code} in two ways.
20072The simplest method is to provide a single line of code to the command.
20073E.g.:
20074
20075@smallexample
20076compile code printf ("hello world\n");
20077@end smallexample
20078
20079If you specify options on the command line as well as source code, they
20080may conflict. The @samp{--} delimiter can be used to separate options
20081from actual source code. E.g.:
20082
20083@smallexample
20084compile code -r -- printf ("hello world\n");
20085@end smallexample
20086
20087Alternatively you can enter source code as multiple lines of text. To
20088enter this mode, invoke the @samp{compile code} command without any text
20089following the command. This will start the multiple-line editor and
20090allow you to type as many lines of source code as required. When you
20091have completed typing, enter @samp{end} on its own line to exit the
20092editor.
20093
20094@smallexample
20095compile code
20096>printf ("hello\n");
20097>printf ("world\n");
20098>end
20099@end smallexample
20100
20101Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20102provided @var{source-code} in a callable scope. In this case, you must
20103specify the entry point of the code by defining a function named
20104@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20105inferior. Using @samp{-raw} option may be needed for example when
20106@var{source-code} requires @samp{#include} lines which may conflict with
20107inferior symbols otherwise.
20108
20109@kindex compile file
20110@item compile file @var{filename}
20111@itemx compile file -raw @var{filename}
20112Like @code{compile code}, but take the source code from @var{filename}.
20113
20114@smallexample
20115compile file /home/user/example.c
20116@end smallexample
20117@end table
20118
36de76f9 20119@table @code
3345721a
PA
20120@item compile print [[@var{options}] --] @var{expr}
20121@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
20122Compile and execute @var{expr} with the compiler language found as the
20123current language in @value{GDBN} (@pxref{Languages}). By default the
20124value of @var{expr} is printed in a format appropriate to its data type;
20125you can choose a different format by specifying @samp{/@var{f}}, where
20126@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
20127Formats}. The @code{compile print} command accepts the same options
20128as the @code{print} command; see @ref{print options}.
36de76f9 20129
3345721a
PA
20130@item compile print [[@var{options}] --]
20131@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
20132@cindex reprint the last value
20133Alternatively you can enter the expression (source code producing it) as
20134multiple lines of text. To enter this mode, invoke the @samp{compile print}
20135command without any text following the command. This will start the
20136multiple-line editor.
20137@end table
20138
e7a8570f
JK
20139@noindent
20140The process of compiling and injecting the code can be inspected using:
20141
20142@table @code
20143@anchor{set debug compile}
20144@item set debug compile
20145@cindex compile command debugging info
20146Turns on or off display of @value{GDBN} process of compiling and
20147injecting the code. The default is off.
20148
20149@item show debug compile
20150Displays the current state of displaying @value{GDBN} process of
20151compiling and injecting the code.
078a0207
KS
20152
20153@anchor{set debug compile-cplus-types}
20154@item set debug compile-cplus-types
20155@cindex compile C@t{++} type conversion
20156Turns on or off the display of C@t{++} type conversion debugging information.
20157The default is off.
20158
20159@item show debug compile-cplus-types
20160Displays the current state of displaying debugging information for
20161C@t{++} type conversion.
e7a8570f
JK
20162@end table
20163
20164@subsection Compilation options for the @code{compile} command
20165
20166@value{GDBN} needs to specify the right compilation options for the code
20167to be injected, in part to make its ABI compatible with the inferior
20168and in part to make the injected code compatible with @value{GDBN}'s
20169injecting process.
20170
20171@noindent
20172The options used, in increasing precedence:
20173
20174@table @asis
20175@item target architecture and OS options (@code{gdbarch})
20176These options depend on target processor type and target operating
20177system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20178(@code{-m64}) compilation option.
20179
20180@item compilation options recorded in the target
20181@value{NGCC} (since version 4.7) stores the options used for compilation
20182into @code{DW_AT_producer} part of DWARF debugging information according
20183to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20184explicitly specify @code{-g} during inferior compilation otherwise
20185@value{NGCC} produces no DWARF. This feature is only relevant for
20186platforms where @code{-g} produces DWARF by default, otherwise one may
20187try to enforce DWARF by using @code{-gdwarf-4}.
20188
20189@item compilation options set by @code{set compile-args}
20190@end table
20191
20192@noindent
20193You can override compilation options using the following command:
20194
20195@table @code
20196@item set compile-args
20197@cindex compile command options override
20198Set compilation options used for compiling and injecting code with the
20199@code{compile} commands. These options override any conflicting ones
20200from the target architecture and/or options stored during inferior
20201compilation.
20202
20203@item show compile-args
20204Displays the current state of compilation options override.
20205This does not show all the options actually used during compilation,
20206use @ref{set debug compile} for that.
20207@end table
20208
bb2ec1b3
TT
20209@subsection Caveats when using the @code{compile} command
20210
20211There are a few caveats to keep in mind when using the @code{compile}
20212command. As the caveats are different per language, the table below
20213highlights specific issues on a per language basis.
20214
20215@table @asis
20216@item C code examples and caveats
20217When the language in @value{GDBN} is set to @samp{C}, the compiler will
20218attempt to compile the source code with a @samp{C} compiler. The source
20219code provided to the @code{compile} command will have much the same
20220access to variables and types as it normally would if it were part of
20221the program currently being debugged in @value{GDBN}.
20222
20223Below is a sample program that forms the basis of the examples that
20224follow. This program has been compiled and loaded into @value{GDBN},
20225much like any other normal debugging session.
20226
20227@smallexample
20228void function1 (void)
20229@{
20230 int i = 42;
20231 printf ("function 1\n");
20232@}
20233
20234void function2 (void)
20235@{
20236 int j = 12;
20237 function1 ();
20238@}
20239
20240int main(void)
20241@{
20242 int k = 6;
20243 int *p;
20244 function2 ();
20245 return 0;
20246@}
20247@end smallexample
20248
20249For the purposes of the examples in this section, the program above has
20250been compiled, loaded into @value{GDBN}, stopped at the function
20251@code{main}, and @value{GDBN} is awaiting input from the user.
20252
20253To access variables and types for any program in @value{GDBN}, the
20254program must be compiled and packaged with debug information. The
20255@code{compile} command is not an exception to this rule. Without debug
20256information, you can still use the @code{compile} command, but you will
20257be very limited in what variables and types you can access.
20258
20259So with that in mind, the example above has been compiled with debug
20260information enabled. The @code{compile} command will have access to
20261all variables and types (except those that may have been optimized
20262out). Currently, as @value{GDBN} has stopped the program in the
20263@code{main} function, the @code{compile} command would have access to
20264the variable @code{k}. You could invoke the @code{compile} command
20265and type some source code to set the value of @code{k}. You can also
20266read it, or do anything with that variable you would normally do in
20267@code{C}. Be aware that changes to inferior variables in the
20268@code{compile} command are persistent. In the following example:
20269
20270@smallexample
20271compile code k = 3;
20272@end smallexample
20273
20274@noindent
20275the variable @code{k} is now 3. It will retain that value until
20276something else in the example program changes it, or another
20277@code{compile} command changes it.
20278
20279Normal scope and access rules apply to source code compiled and
20280injected by the @code{compile} command. In the example, the variables
20281@code{j} and @code{k} are not accessible yet, because the program is
20282currently stopped in the @code{main} function, where these variables
20283are not in scope. Therefore, the following command
20284
20285@smallexample
20286compile code j = 3;
20287@end smallexample
20288
20289@noindent
20290will result in a compilation error message.
20291
20292Once the program is continued, execution will bring these variables in
20293scope, and they will become accessible; then the code you specify via
20294the @code{compile} command will be able to access them.
20295
20296You can create variables and types with the @code{compile} command as
20297part of your source code. Variables and types that are created as part
20298of the @code{compile} command are not visible to the rest of the program for
20299the duration of its run. This example is valid:
20300
20301@smallexample
20302compile code int ff = 5; printf ("ff is %d\n", ff);
20303@end smallexample
20304
20305However, if you were to type the following into @value{GDBN} after that
20306command has completed:
20307
20308@smallexample
20309compile code printf ("ff is %d\n'', ff);
20310@end smallexample
20311
20312@noindent
20313a compiler error would be raised as the variable @code{ff} no longer
20314exists. Object code generated and injected by the @code{compile}
20315command is removed when its execution ends. Caution is advised
20316when assigning to program variables values of variables created by the
20317code submitted to the @code{compile} command. This example is valid:
20318
20319@smallexample
20320compile code int ff = 5; k = ff;
20321@end smallexample
20322
20323The value of the variable @code{ff} is assigned to @code{k}. The variable
20324@code{k} does not require the existence of @code{ff} to maintain the value
20325it has been assigned. However, pointers require particular care in
20326assignment. If the source code compiled with the @code{compile} command
20327changed the address of a pointer in the example program, perhaps to a
20328variable created in the @code{compile} command, that pointer would point
20329to an invalid location when the command exits. The following example
20330would likely cause issues with your debugged program:
20331
20332@smallexample
20333compile code int ff = 5; p = &ff;
20334@end smallexample
20335
20336In this example, @code{p} would point to @code{ff} when the
20337@code{compile} command is executing the source code provided to it.
20338However, as variables in the (example) program persist with their
20339assigned values, the variable @code{p} would point to an invalid
20340location when the command exists. A general rule should be followed
20341in that you should either assign @code{NULL} to any assigned pointers,
20342or restore a valid location to the pointer before the command exits.
20343
20344Similar caution must be exercised with any structs, unions, and typedefs
20345defined in @code{compile} command. Types defined in the @code{compile}
20346command will no longer be available in the next @code{compile} command.
20347Therefore, if you cast a variable to a type defined in the
20348@code{compile} command, care must be taken to ensure that any future
20349need to resolve the type can be achieved.
20350
20351@smallexample
20352(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20353(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20354gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20355Compilation failed.
20356(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2035742
20358@end smallexample
20359
20360Variables that have been optimized away by the compiler are not
20361accessible to the code submitted to the @code{compile} command.
20362Access to those variables will generate a compiler error which @value{GDBN}
20363will print to the console.
20364@end table
20365
e7a8570f
JK
20366@subsection Compiler search for the @code{compile} command
20367
6e41ddec
JK
20368@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20369which may not be obvious for remote targets of different architecture
20370than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20371@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20372target architecture and operating system. This search can be overriden
20373by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20374taken from shell that executed @value{GDBN}, it is not the value set by
20375@value{GDBN} command @code{set environment}). @xref{Environment}.
20376
e7a8570f
JK
20377
20378Specifically @code{PATH} is searched for binaries matching regular expression
20379@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20380debugged. @var{arch} is processor name --- multiarch is supported, so for
20381example both @code{i386} and @code{x86_64} targets look for pattern
20382@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20383for pattern @code{s390x?}. @var{os} is currently supported only for
20384pattern @code{linux(-gnu)?}.
20385
6e41ddec
JK
20386On Posix hosts the compiler driver @value{GDBN} needs to find also
20387shared library @file{libcc1.so} from the compiler. It is searched in
20388default shared library search path (overridable with usual environment
20389variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20390compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20391according to the installation of the found compiler --- as possibly
20392specified by the @code{set compile-gcc} command.
20393
20394@table @code
20395@item set compile-gcc
20396@cindex compile command driver filename override
20397Set compilation command used for compiling and injecting code with the
20398@code{compile} commands. If this option is not set (it is set to
20399an empty string), the search described above will occur --- that is the
20400default.
20401
20402@item show compile-gcc
20403Displays the current compile command @value{NGCC} driver filename.
20404If set, it is the main command @command{gcc}, found usually for example
20405under name @file{x86_64-linux-gnu-gcc}.
20406@end table
20407
6d2ebf8b 20408@node GDB Files
c906108c
SS
20409@chapter @value{GDBN} Files
20410
7a292a7a
SS
20411@value{GDBN} needs to know the file name of the program to be debugged,
20412both in order to read its symbol table and in order to start your
20413program. To debug a core dump of a previous run, you must also tell
20414@value{GDBN} the name of the core dump file.
c906108c
SS
20415
20416@menu
20417* Files:: Commands to specify files
2b4bf6af 20418* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20419* Separate Debug Files:: Debugging information in separate files
608e2dbb 20420* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20421* Index Files:: Index files speed up GDB
c906108c 20422* Symbol Errors:: Errors reading symbol files
b14b1491 20423* Data Files:: GDB data files
c906108c
SS
20424@end menu
20425
6d2ebf8b 20426@node Files
79a6e687 20427@section Commands to Specify Files
c906108c 20428
7a292a7a 20429@cindex symbol table
c906108c 20430@cindex core dump file
7a292a7a
SS
20431
20432You may want to specify executable and core dump file names. The usual
20433way to do this is at start-up time, using the arguments to
20434@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20435Out of @value{GDBN}}).
c906108c
SS
20436
20437Occasionally it is necessary to change to a different file during a
397ca115
EZ
20438@value{GDBN} session. Or you may run @value{GDBN} and forget to
20439specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20440via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20441Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20442new files are useful.
c906108c
SS
20443
20444@table @code
20445@cindex executable file
20446@kindex file
20447@item file @var{filename}
20448Use @var{filename} as the program to be debugged. It is read for its
20449symbols and for the contents of pure memory. It is also the program
20450executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20451directory and the file is not found in the @value{GDBN} working directory,
20452@value{GDBN} uses the environment variable @code{PATH} as a list of
20453directories to search, just as the shell does when looking for a program
20454to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20455and your program, using the @code{path} command.
20456
fc8be69e
EZ
20457@cindex unlinked object files
20458@cindex patching object files
20459You can load unlinked object @file{.o} files into @value{GDBN} using
20460the @code{file} command. You will not be able to ``run'' an object
20461file, but you can disassemble functions and inspect variables. Also,
20462if the underlying BFD functionality supports it, you could use
20463@kbd{gdb -write} to patch object files using this technique. Note
20464that @value{GDBN} can neither interpret nor modify relocations in this
20465case, so branches and some initialized variables will appear to go to
20466the wrong place. But this feature is still handy from time to time.
20467
c906108c
SS
20468@item file
20469@code{file} with no argument makes @value{GDBN} discard any information it
20470has on both executable file and the symbol table.
20471
20472@kindex exec-file
20473@item exec-file @r{[} @var{filename} @r{]}
20474Specify that the program to be run (but not the symbol table) is found
20475in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20476if necessary to locate your program. Omitting @var{filename} means to
20477discard information on the executable file.
20478
20479@kindex symbol-file
d4d429d5 20480@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20481Read symbol table information from file @var{filename}. @code{PATH} is
20482searched when necessary. Use the @code{file} command to get both symbol
20483table and program to run from the same file.
20484
d4d429d5
PT
20485If an optional @var{offset} is specified, it is added to the start
20486address of each section in the symbol file. This is useful if the
20487program is relocated at runtime, such as the Linux kernel with kASLR
20488enabled.
20489
c906108c
SS
20490@code{symbol-file} with no argument clears out @value{GDBN} information on your
20491program's symbol table.
20492
ae5a43e0
DJ
20493The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20494some breakpoints and auto-display expressions. This is because they may
20495contain pointers to the internal data recording symbols and data types,
20496which are part of the old symbol table data being discarded inside
20497@value{GDBN}.
c906108c
SS
20498
20499@code{symbol-file} does not repeat if you press @key{RET} again after
20500executing it once.
20501
20502When @value{GDBN} is configured for a particular environment, it
20503understands debugging information in whatever format is the standard
20504generated for that environment; you may use either a @sc{gnu} compiler, or
20505other compilers that adhere to the local conventions.
c906108c 20506Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20507using @code{@value{NGCC}} you can generate debugging information for
c906108c 20508optimized code.
c906108c
SS
20509
20510For most kinds of object files, with the exception of old SVR3 systems
20511using COFF, the @code{symbol-file} command does not normally read the
20512symbol table in full right away. Instead, it scans the symbol table
20513quickly to find which source files and which symbols are present. The
20514details are read later, one source file at a time, as they are needed.
20515
20516The purpose of this two-stage reading strategy is to make @value{GDBN}
20517start up faster. For the most part, it is invisible except for
20518occasional pauses while the symbol table details for a particular source
20519file are being read. (The @code{set verbose} command can turn these
20520pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20521Warnings and Messages}.)
c906108c 20522
c906108c
SS
20523We have not implemented the two-stage strategy for COFF yet. When the
20524symbol table is stored in COFF format, @code{symbol-file} reads the
20525symbol table data in full right away. Note that ``stabs-in-COFF''
20526still does the two-stage strategy, since the debug info is actually
20527in stabs format.
20528
20529@kindex readnow
20530@cindex reading symbols immediately
20531@cindex symbols, reading immediately
6ac33a4e
TT
20532@item symbol-file @r{[} -readnow @r{]} @var{filename}
20533@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20534You can override the @value{GDBN} two-stage strategy for reading symbol
20535tables by using the @samp{-readnow} option with any of the commands that
20536load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20537entire symbol table available.
c906108c 20538
97cbe998
SDJ
20539@cindex @code{-readnever}, option for symbol-file command
20540@cindex never read symbols
20541@cindex symbols, never read
20542@item symbol-file @r{[} -readnever @r{]} @var{filename}
20543@itemx file @r{[} -readnever @r{]} @var{filename}
20544You can instruct @value{GDBN} to never read the symbolic information
20545contained in @var{filename} by using the @samp{-readnever} option.
20546@xref{--readnever}.
20547
c906108c
SS
20548@c FIXME: for now no mention of directories, since this seems to be in
20549@c flux. 13mar1992 status is that in theory GDB would look either in
20550@c current dir or in same dir as myprog; but issues like competing
20551@c GDB's, or clutter in system dirs, mean that in practice right now
20552@c only current dir is used. FFish says maybe a special GDB hierarchy
20553@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20554@c files.
20555
c906108c 20556@kindex core-file
09d4efe1 20557@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20558@itemx core
c906108c
SS
20559Specify the whereabouts of a core dump file to be used as the ``contents
20560of memory''. Traditionally, core files contain only some parts of the
20561address space of the process that generated them; @value{GDBN} can access the
20562executable file itself for other parts.
20563
20564@code{core-file} with no argument specifies that no core file is
20565to be used.
20566
20567Note that the core file is ignored when your program is actually running
7a292a7a
SS
20568under @value{GDBN}. So, if you have been running your program and you
20569wish to debug a core file instead, you must kill the subprocess in which
20570the program is running. To do this, use the @code{kill} command
79a6e687 20571(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20572
c906108c
SS
20573@kindex add-symbol-file
20574@cindex dynamic linking
291f9a96 20575@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
20576The @code{add-symbol-file} command reads additional symbol table
20577information from the file @var{filename}. You would use this command
20578when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20579into the program that is running. The @var{textaddress} parameter gives
20580the memory address at which the file's text section has been loaded.
20581You can additionally specify the base address of other sections using
20582an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20583If a section is omitted, @value{GDBN} will use its default addresses
20584as found in @var{filename}. Any @var{address} or @var{textaddress}
20585can be given as an expression.
c906108c 20586
291f9a96
PT
20587If an optional @var{offset} is specified, it is added to the start
20588address of each section, except those for which the address was
20589specified explicitly.
20590
c906108c
SS
20591The symbol table of the file @var{filename} is added to the symbol table
20592originally read with the @code{symbol-file} command. You can use the
96a2c332 20593@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20594thus read is kept in addition to the old.
20595
20596Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20597
17d9d558
JB
20598@cindex relocatable object files, reading symbols from
20599@cindex object files, relocatable, reading symbols from
20600@cindex reading symbols from relocatable object files
20601@cindex symbols, reading from relocatable object files
20602@cindex @file{.o} files, reading symbols from
20603Although @var{filename} is typically a shared library file, an
20604executable file, or some other object file which has been fully
20605relocated for loading into a process, you can also load symbolic
20606information from relocatable @file{.o} files, as long as:
20607
20608@itemize @bullet
20609@item
20610the file's symbolic information refers only to linker symbols defined in
20611that file, not to symbols defined by other object files,
20612@item
20613every section the file's symbolic information refers to has actually
20614been loaded into the inferior, as it appears in the file, and
20615@item
20616you can determine the address at which every section was loaded, and
20617provide these to the @code{add-symbol-file} command.
20618@end itemize
20619
20620@noindent
20621Some embedded operating systems, like Sun Chorus and VxWorks, can load
20622relocatable files into an already running program; such systems
20623typically make the requirements above easy to meet. However, it's
20624important to recognize that many native systems use complex link
49efadf5 20625procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20626assembly, for example) that make the requirements difficult to meet. In
20627general, one cannot assume that using @code{add-symbol-file} to read a
20628relocatable object file's symbolic information will have the same effect
20629as linking the relocatable object file into the program in the normal
20630way.
20631
c906108c
SS
20632@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20633
98297bf6
NB
20634@kindex remove-symbol-file
20635@item remove-symbol-file @var{filename}
20636@item remove-symbol-file -a @var{address}
20637Remove a symbol file added via the @code{add-symbol-file} command. The
20638file to remove can be identified by its @var{filename} or by an @var{address}
20639that lies within the boundaries of this symbol file in memory. Example:
20640
20641@smallexample
20642(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20643add symbol table from file "/home/user/gdb/mylib.so" at
20644 .text_addr = 0x7ffff7ff9480
20645(y or n) y
0bab6cf1 20646Reading symbols from /home/user/gdb/mylib.so...
98297bf6
NB
20647(gdb) remove-symbol-file -a 0x7ffff7ff9480
20648Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20649(gdb)
20650@end smallexample
20651
20652
20653@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20654
c45da7e6
EZ
20655@kindex add-symbol-file-from-memory
20656@cindex @code{syscall DSO}
20657@cindex load symbols from memory
20658@item add-symbol-file-from-memory @var{address}
20659Load symbols from the given @var{address} in a dynamically loaded
20660object file whose image is mapped directly into the inferior's memory.
20661For example, the Linux kernel maps a @code{syscall DSO} into each
20662process's address space; this DSO provides kernel-specific code for
20663some system calls. The argument can be any expression whose
20664evaluation yields the address of the file's shared object file header.
20665For this command to work, you must have used @code{symbol-file} or
20666@code{exec-file} commands in advance.
20667
c906108c 20668@kindex section
09d4efe1
EZ
20669@item section @var{section} @var{addr}
20670The @code{section} command changes the base address of the named
20671@var{section} of the exec file to @var{addr}. This can be used if the
20672exec file does not contain section addresses, (such as in the
20673@code{a.out} format), or when the addresses specified in the file
20674itself are wrong. Each section must be changed separately. The
20675@code{info files} command, described below, lists all the sections and
20676their addresses.
c906108c
SS
20677
20678@kindex info files
20679@kindex info target
20680@item info files
20681@itemx info target
7a292a7a
SS
20682@code{info files} and @code{info target} are synonymous; both print the
20683current target (@pxref{Targets, ,Specifying a Debugging Target}),
20684including the names of the executable and core dump files currently in
20685use by @value{GDBN}, and the files from which symbols were loaded. The
20686command @code{help target} lists all possible targets rather than
20687current ones.
20688
fe95c787
MS
20689@kindex maint info sections
20690@item maint info sections
20691Another command that can give you extra information about program sections
20692is @code{maint info sections}. In addition to the section information
20693displayed by @code{info files}, this command displays the flags and file
20694offset of each section in the executable and core dump files. In addition,
20695@code{maint info sections} provides the following command options (which
20696may be arbitrarily combined):
20697
20698@table @code
20699@item ALLOBJ
20700Display sections for all loaded object files, including shared libraries.
20701@item @var{sections}
6600abed 20702Display info only for named @var{sections}.
fe95c787
MS
20703@item @var{section-flags}
20704Display info only for sections for which @var{section-flags} are true.
20705The section flags that @value{GDBN} currently knows about are:
20706@table @code
20707@item ALLOC
20708Section will have space allocated in the process when loaded.
20709Set for all sections except those containing debug information.
20710@item LOAD
20711Section will be loaded from the file into the child process memory.
20712Set for pre-initialized code and data, clear for @code{.bss} sections.
20713@item RELOC
20714Section needs to be relocated before loading.
20715@item READONLY
20716Section cannot be modified by the child process.
20717@item CODE
20718Section contains executable code only.
6600abed 20719@item DATA
fe95c787
MS
20720Section contains data only (no executable code).
20721@item ROM
20722Section will reside in ROM.
20723@item CONSTRUCTOR
20724Section contains data for constructor/destructor lists.
20725@item HAS_CONTENTS
20726Section is not empty.
20727@item NEVER_LOAD
20728An instruction to the linker to not output the section.
20729@item COFF_SHARED_LIBRARY
20730A notification to the linker that the section contains
20731COFF shared library information.
20732@item IS_COMMON
20733Section contains common symbols.
20734@end table
20735@end table
6763aef9 20736@kindex set trust-readonly-sections
9c16f35a 20737@cindex read-only sections
6763aef9
MS
20738@item set trust-readonly-sections on
20739Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20740really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20741In that case, @value{GDBN} can fetch values from these sections
20742out of the object file, rather than from the target program.
20743For some targets (notably embedded ones), this can be a significant
20744enhancement to debugging performance.
20745
20746The default is off.
20747
20748@item set trust-readonly-sections off
15110bc3 20749Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20750the contents of the section might change while the program is running,
20751and must therefore be fetched from the target when needed.
9c16f35a
EZ
20752
20753@item show trust-readonly-sections
20754Show the current setting of trusting readonly sections.
c906108c
SS
20755@end table
20756
20757All file-specifying commands allow both absolute and relative file names
20758as arguments. @value{GDBN} always converts the file name to an absolute file
20759name and remembers it that way.
20760
c906108c 20761@cindex shared libraries
9cceb671 20762@anchor{Shared Libraries}
b1236ac3
PA
20763@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20764Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20765DSBT (TIC6X) shared libraries.
53a5351d 20766
9cceb671
DJ
20767On MS-Windows @value{GDBN} must be linked with the Expat library to support
20768shared libraries. @xref{Expat}.
20769
c906108c
SS
20770@value{GDBN} automatically loads symbol definitions from shared libraries
20771when you use the @code{run} command, or when you examine a core file.
20772(Before you issue the @code{run} command, @value{GDBN} does not understand
20773references to a function in a shared library, however---unless you are
20774debugging a core file).
53a5351d 20775
c906108c
SS
20776@c FIXME: some @value{GDBN} release may permit some refs to undef
20777@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20778@c FIXME...lib; check this from time to time when updating manual
20779
b7209cb4
FF
20780There are times, however, when you may wish to not automatically load
20781symbol definitions from shared libraries, such as when they are
20782particularly large or there are many of them.
20783
20784To control the automatic loading of shared library symbols, use the
20785commands:
20786
20787@table @code
20788@kindex set auto-solib-add
20789@item set auto-solib-add @var{mode}
20790If @var{mode} is @code{on}, symbols from all shared object libraries
20791will be loaded automatically when the inferior begins execution, you
20792attach to an independently started inferior, or when the dynamic linker
20793informs @value{GDBN} that a new library has been loaded. If @var{mode}
20794is @code{off}, symbols must be loaded manually, using the
20795@code{sharedlibrary} command. The default value is @code{on}.
20796
dcaf7c2c
EZ
20797@cindex memory used for symbol tables
20798If your program uses lots of shared libraries with debug info that
20799takes large amounts of memory, you can decrease the @value{GDBN}
20800memory footprint by preventing it from automatically loading the
20801symbols from shared libraries. To that end, type @kbd{set
20802auto-solib-add off} before running the inferior, then load each
20803library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20804@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20805the libraries whose symbols you want to be loaded.
20806
b7209cb4
FF
20807@kindex show auto-solib-add
20808@item show auto-solib-add
20809Display the current autoloading mode.
20810@end table
20811
c45da7e6 20812@cindex load shared library
b7209cb4
FF
20813To explicitly load shared library symbols, use the @code{sharedlibrary}
20814command:
20815
c906108c
SS
20816@table @code
20817@kindex info sharedlibrary
20818@kindex info share
55333a84
DE
20819@item info share @var{regex}
20820@itemx info sharedlibrary @var{regex}
20821Print the names of the shared libraries which are currently loaded
20822that match @var{regex}. If @var{regex} is omitted then print
20823all shared libraries that are loaded.
c906108c 20824
b30a0bc3
JB
20825@kindex info dll
20826@item info dll @var{regex}
20827This is an alias of @code{info sharedlibrary}.
20828
c906108c
SS
20829@kindex sharedlibrary
20830@kindex share
20831@item sharedlibrary @var{regex}
20832@itemx share @var{regex}
c906108c
SS
20833Load shared object library symbols for files matching a
20834Unix regular expression.
20835As with files loaded automatically, it only loads shared libraries
20836required by your program for a core file or after typing @code{run}. If
20837@var{regex} is omitted all shared libraries required by your program are
20838loaded.
c45da7e6
EZ
20839
20840@item nosharedlibrary
20841@kindex nosharedlibrary
20842@cindex unload symbols from shared libraries
20843Unload all shared object library symbols. This discards all symbols
20844that have been loaded from all shared libraries. Symbols from shared
20845libraries that were loaded by explicit user requests are not
20846discarded.
c906108c
SS
20847@end table
20848
721c2651 20849Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20850when any of shared library events happen. The best way to do this is
20851to use @code{catch load} and @code{catch unload} (@pxref{Set
20852Catchpoints}).
20853
09f2921c 20854@value{GDBN} also supports the @code{set stop-on-solib-events}
edcc5120
TT
20855command for this. This command exists for historical reasons. It is
20856less useful than setting a catchpoint, because it does not allow for
20857conditions or commands as a catchpoint does.
721c2651
EZ
20858
20859@table @code
20860@item set stop-on-solib-events
20861@kindex set stop-on-solib-events
20862This command controls whether @value{GDBN} should give you control
20863when the dynamic linker notifies it about some shared library event.
20864The most common event of interest is loading or unloading of a new
20865shared library.
20866
20867@item show stop-on-solib-events
20868@kindex show stop-on-solib-events
20869Show whether @value{GDBN} stops and gives you control when shared
20870library events happen.
20871@end table
20872
f5ebfba0 20873Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20874configurations. @value{GDBN} needs to have access to the target's libraries;
20875this can be accomplished either by providing copies of the libraries
20876on the host system, or by asking @value{GDBN} to automatically retrieve the
20877libraries from the target. If copies of the target libraries are
20878provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20879copies on the target can be stripped as long as the copies on the host are
20880not.
20881
59b7b46f
EZ
20882@cindex where to look for shared libraries
20883For remote debugging, you need to tell @value{GDBN} where the target
20884libraries are, so that it can load the correct copies---otherwise, it
20885may try to load the host's libraries. @value{GDBN} has two variables
20886to specify the search directories for target libraries.
f5ebfba0
DJ
20887
20888@table @code
a9a5a3d1 20889@cindex prefix for executable and shared library file names
f822c95b 20890@cindex system root, alternate
f5ebfba0 20891@kindex set solib-absolute-prefix
f822c95b
DJ
20892@kindex set sysroot
20893@item set sysroot @var{path}
20894Use @var{path} as the system root for the program being debugged. Any
20895absolute shared library paths will be prefixed with @var{path}; many
20896runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20897target program's memory. When starting processes remotely, and when
20898attaching to already-running processes (local or remote), their
20899executable filenames will be prefixed with @var{path} if reported to
20900@value{GDBN} as absolute by the operating system. If you use
20901@code{set sysroot} to find executables and shared libraries, they need
20902to be laid out in the same way that they are on the target, with
20903e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20904@var{path}.
f822c95b 20905
599bd15c
GB
20906If @var{path} starts with the sequence @file{target:} and the target
20907system is remote then @value{GDBN} will retrieve the target binaries
20908from the remote system. This is only supported when using a remote
20909target that supports the @code{remote get} command (@pxref{File
20910Transfer,,Sending files to a remote system}). The part of @var{path}
20911following the initial @file{target:} (if present) is used as system
20912root prefix on the remote file system. If @var{path} starts with the
20913sequence @file{remote:} this is converted to the sequence
20914@file{target:} by @code{set sysroot}@footnote{Historically the
20915functionality to retrieve binaries from the remote system was
20916provided by prefixing @var{path} with @file{remote:}}. If you want
20917to specify a local system root using a directory that happens to be
20918named @file{target:} or @file{remote:}, you need to use some
20919equivalent variant of the name like @file{./target:}.
f1838a98 20920
ab38a727
PA
20921For targets with an MS-DOS based filesystem, such as MS-Windows and
20922SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20923absolute file name with @var{path}. But first, on Unix hosts,
20924@value{GDBN} converts all backslash directory separators into forward
20925slashes, because the backslash is not a directory separator on Unix:
20926
20927@smallexample
20928 c:\foo\bar.dll @result{} c:/foo/bar.dll
20929@end smallexample
20930
20931Then, @value{GDBN} attempts prefixing the target file name with
20932@var{path}, and looks for the resulting file name in the host file
20933system:
20934
20935@smallexample
20936 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20937@end smallexample
20938
a9a5a3d1 20939If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20940the @samp{:} character from the drive spec, both for convenience, and,
20941for the case of the host file system not supporting file names with
20942colons:
20943
20944@smallexample
20945 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20946@end smallexample
20947
20948This makes it possible to have a system root that mirrors a target
20949with more than one drive. E.g., you may want to setup your local
20950copies of the target system shared libraries like so (note @samp{c} vs
20951@samp{z}):
20952
20953@smallexample
20954 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20955 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20956 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20957@end smallexample
20958
20959@noindent
20960and point the system root at @file{/path/to/sysroot}, so that
20961@value{GDBN} can find the correct copies of both
20962@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20963
a9a5a3d1 20964If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20965removing the whole drive spec from the target file name:
20966
20967@smallexample
20968 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20969@end smallexample
20970
20971This last lookup makes it possible to not care about the drive name,
20972if you don't want or need to.
20973
f822c95b
DJ
20974The @code{set solib-absolute-prefix} command is an alias for @code{set
20975sysroot}.
20976
20977@cindex default system root
59b7b46f 20978@cindex @samp{--with-sysroot}
f822c95b
DJ
20979You can set the default system root by using the configure-time
20980@samp{--with-sysroot} option. If the system root is inside
20981@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20982@samp{--exec-prefix}), then the default system root will be updated
20983automatically if the installed @value{GDBN} is moved to a new
20984location.
20985
20986@kindex show sysroot
20987@item show sysroot
a9a5a3d1 20988Display the current executable and shared library prefix.
f5ebfba0
DJ
20989
20990@kindex set solib-search-path
20991@item set solib-search-path @var{path}
f822c95b
DJ
20992If this variable is set, @var{path} is a colon-separated list of
20993directories to search for shared libraries. @samp{solib-search-path}
20994is used after @samp{sysroot} fails to locate the library, or if the
20995path to the library is relative instead of absolute. If you want to
20996use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20997@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20998finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20999it to a nonexistent directory may interfere with automatic loading
f822c95b 21000of shared library symbols.
f5ebfba0
DJ
21001
21002@kindex show solib-search-path
21003@item show solib-search-path
21004Display the current shared library search path.
ab38a727
PA
21005
21006@cindex DOS file-name semantics of file names.
21007@kindex set target-file-system-kind (unix|dos-based|auto)
21008@kindex show target-file-system-kind
21009@item set target-file-system-kind @var{kind}
21010Set assumed file system kind for target reported file names.
21011
21012Shared library file names as reported by the target system may not
21013make sense as is on the system @value{GDBN} is running on. For
21014example, when remote debugging a target that has MS-DOS based file
21015system semantics, from a Unix host, the target may be reporting to
21016@value{GDBN} a list of loaded shared libraries with file names such as
21017@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21018drive letters, so the @samp{c:\} prefix is not normally understood as
21019indicating an absolute file name, and neither is the backslash
21020normally considered a directory separator character. In that case,
21021the native file system would interpret this whole absolute file name
21022as a relative file name with no directory components. This would make
21023it impossible to point @value{GDBN} at a copy of the remote target's
21024shared libraries on the host using @code{set sysroot}, and impractical
21025with @code{set solib-search-path}. Setting
21026@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21027to interpret such file names similarly to how the target would, and to
21028map them to file names valid on @value{GDBN}'s native file system
21029semantics. The value of @var{kind} can be @code{"auto"}, in addition
21030to one of the supported file system kinds. In that case, @value{GDBN}
21031tries to determine the appropriate file system variant based on the
21032current target's operating system (@pxref{ABI, ,Configuring the
21033Current ABI}). The supported file system settings are:
21034
21035@table @code
21036@item unix
21037Instruct @value{GDBN} to assume the target file system is of Unix
21038kind. Only file names starting the forward slash (@samp{/}) character
21039are considered absolute, and the directory separator character is also
21040the forward slash.
21041
21042@item dos-based
21043Instruct @value{GDBN} to assume the target file system is DOS based.
21044File names starting with either a forward slash, or a drive letter
21045followed by a colon (e.g., @samp{c:}), are considered absolute, and
21046both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21047considered directory separators.
21048
21049@item auto
21050Instruct @value{GDBN} to use the file system kind associated with the
21051target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21052This is the default.
21053@end table
f5ebfba0
DJ
21054@end table
21055
c011a4f4
DE
21056@cindex file name canonicalization
21057@cindex base name differences
21058When processing file names provided by the user, @value{GDBN}
21059frequently needs to compare them to the file names recorded in the
21060program's debug info. Normally, @value{GDBN} compares just the
21061@dfn{base names} of the files as strings, which is reasonably fast
21062even for very large programs. (The base name of a file is the last
21063portion of its name, after stripping all the leading directories.)
21064This shortcut in comparison is based upon the assumption that files
21065cannot have more than one base name. This is usually true, but
21066references to files that use symlinks or similar filesystem
21067facilities violate that assumption. If your program records files
21068using such facilities, or if you provide file names to @value{GDBN}
21069using symlinks etc., you can set @code{basenames-may-differ} to
21070@code{true} to instruct @value{GDBN} to completely canonicalize each
21071pair of file names it needs to compare. This will make file-name
21072comparisons accurate, but at a price of a significant slowdown.
21073
21074@table @code
21075@item set basenames-may-differ
21076@kindex set basenames-may-differ
21077Set whether a source file may have multiple base names.
21078
21079@item show basenames-may-differ
21080@kindex show basenames-may-differ
21081Show whether a source file may have multiple base names.
21082@end table
5b5d99cf 21083
18989b3c
AB
21084@node File Caching
21085@section File Caching
21086@cindex caching of opened files
21087@cindex caching of bfd objects
21088
21089To speed up file loading, and reduce memory usage, @value{GDBN} will
21090reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21091BFD, bfd, The Binary File Descriptor Library}. The following commands
21092allow visibility and control of the caching behavior.
21093
21094@table @code
21095@kindex maint info bfds
21096@item maint info bfds
21097This prints information about each @code{bfd} object that is known to
21098@value{GDBN}.
21099
21100@kindex maint set bfd-sharing
21101@kindex maint show bfd-sharing
21102@kindex bfd caching
21103@item maint set bfd-sharing
21104@item maint show bfd-sharing
21105Control whether @code{bfd} objects can be shared. When sharing is
21106enabled @value{GDBN} reuses already open @code{bfd} objects rather
21107than reopening the same file. Turning sharing off does not cause
21108already shared @code{bfd} objects to be unshared, but all future files
21109that are opened will create a new @code{bfd} object. Similarly,
21110re-enabling sharing does not cause multiple existing @code{bfd}
21111objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
21112
21113@kindex set debug bfd-cache @var{level}
21114@kindex bfd caching
21115@item set debug bfd-cache @var{level}
21116Turns on debugging of the bfd cache, setting the level to @var{level}.
21117
21118@kindex show debug bfd-cache
21119@kindex bfd caching
21120@item show debug bfd-cache
21121Show the current debugging level of the bfd cache.
18989b3c
AB
21122@end table
21123
5b5d99cf
JB
21124@node Separate Debug Files
21125@section Debugging Information in Separate Files
21126@cindex separate debugging information files
21127@cindex debugging information in separate files
21128@cindex @file{.debug} subdirectories
21129@cindex debugging information directory, global
f307c045 21130@cindex global debugging information directories
c7e83d54
EZ
21131@cindex build ID, and separate debugging files
21132@cindex @file{.build-id} directory
5b5d99cf
JB
21133
21134@value{GDBN} allows you to put a program's debugging information in a
21135file separate from the executable itself, in a way that allows
21136@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
21137Since debugging information can be very large---sometimes larger
21138than the executable code itself---some systems distribute debugging
5b5d99cf
JB
21139information for their executables in separate files, which users can
21140install only when they need to debug a problem.
21141
c7e83d54
EZ
21142@value{GDBN} supports two ways of specifying the separate debug info
21143file:
5b5d99cf
JB
21144
21145@itemize @bullet
21146@item
c7e83d54
EZ
21147The executable contains a @dfn{debug link} that specifies the name of
21148the separate debug info file. The separate debug file's name is
21149usually @file{@var{executable}.debug}, where @var{executable} is the
21150name of the corresponding executable file without leading directories
21151(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
21152debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21153checksum for the debug file, which @value{GDBN} uses to validate that
21154the executable and the debug file came from the same build.
c7e83d54
EZ
21155
21156@item
98c59b52 21157@anchor{build ID}
7e27a47a 21158The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 21159also present in the corresponding debug info file. (This is supported
c74f7d1c 21160only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
21161for binary files and the @sc{gnu} Binutils.) For more details about
21162this feature, see the description of the @option{--build-id}
f5a476a7 21163command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
21164The GNU Linker}. The debug info file's name is not specified
21165explicitly by the build ID, but can be computed from the build ID, see
21166below.
d3750b24
JK
21167@end itemize
21168
c7e83d54
EZ
21169Depending on the way the debug info file is specified, @value{GDBN}
21170uses two different methods of looking for the debug file:
d3750b24
JK
21171
21172@itemize @bullet
21173@item
c7e83d54
EZ
21174For the ``debug link'' method, @value{GDBN} looks up the named file in
21175the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
21176directory named @file{.debug}, and finally under each one of the
21177global debug directories, in a subdirectory whose name is identical to
21178the leading directories of the executable's absolute file name. (On
21179MS-Windows/MS-DOS, the drive letter of the executable's leading
21180directories is converted to a one-letter subdirectory, i.e.@:
21181@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21182filesystems disallow colons in file names.)
c7e83d54
EZ
21183
21184@item
83f83d7f 21185For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
21186@file{.build-id} subdirectory of each one of the global debug directories for
21187a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
21188first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21189are the rest of the bit string. (Real build ID strings are 32 or more
21190hex characters, not 10.)
c7e83d54
EZ
21191@end itemize
21192
21193So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
21194@file{/usr/bin/ls}, which has a debug link that specifies the
21195file @file{ls.debug}, and a build ID whose value in hex is
f307c045 21196@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
21197@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21198debug information files, in the indicated order:
21199
21200@itemize @minus
21201@item
21202@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 21203@item
c7e83d54 21204@file{/usr/bin/ls.debug}
5b5d99cf 21205@item
c7e83d54 21206@file{/usr/bin/.debug/ls.debug}
5b5d99cf 21207@item
c7e83d54 21208@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 21209@end itemize
5b5d99cf 21210
1564a261
JK
21211@anchor{debug-file-directory}
21212Global debugging info directories default to what is set by @value{GDBN}
21213configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21214you can also set the global debugging info directories, and view the list
21215@value{GDBN} is currently using.
5b5d99cf
JB
21216
21217@table @code
21218
21219@kindex set debug-file-directory
24ddea62
JK
21220@item set debug-file-directory @var{directories}
21221Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
21222information files to @var{directory}. Multiple path components can be set
21223concatenating them by a path separator.
5b5d99cf
JB
21224
21225@kindex show debug-file-directory
21226@item show debug-file-directory
24ddea62 21227Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
21228information files.
21229
21230@end table
21231
21232@cindex @code{.gnu_debuglink} sections
c7e83d54 21233@cindex debug link sections
5b5d99cf
JB
21234A debug link is a special section of the executable file named
21235@code{.gnu_debuglink}. The section must contain:
21236
21237@itemize
21238@item
21239A filename, with any leading directory components removed, followed by
21240a zero byte,
21241@item
21242zero to three bytes of padding, as needed to reach the next four-byte
21243boundary within the section, and
21244@item
21245a four-byte CRC checksum, stored in the same endianness used for the
21246executable file itself. The checksum is computed on the debugging
21247information file's full contents by the function given below, passing
21248zero as the @var{crc} argument.
21249@end itemize
21250
21251Any executable file format can carry a debug link, as long as it can
21252contain a section named @code{.gnu_debuglink} with the contents
21253described above.
21254
d3750b24 21255@cindex @code{.note.gnu.build-id} sections
c7e83d54 21256@cindex build ID sections
7e27a47a
EZ
21257The build ID is a special section in the executable file (and in other
21258ELF binary files that @value{GDBN} may consider). This section is
21259often named @code{.note.gnu.build-id}, but that name is not mandatory.
21260It contains unique identification for the built files---the ID remains
21261the same across multiple builds of the same build tree. The default
21262algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21263content for the build ID string. The same section with an identical
21264value is present in the original built binary with symbols, in its
21265stripped variant, and in the separate debugging information file.
d3750b24 21266
5b5d99cf
JB
21267The debugging information file itself should be an ordinary
21268executable, containing a full set of linker symbols, sections, and
21269debugging information. The sections of the debugging information file
c7e83d54
EZ
21270should have the same names, addresses, and sizes as the original file,
21271but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
21272in an ordinary executable.
21273
7e27a47a 21274The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
21275@samp{objcopy} utility that can produce
21276the separated executable / debugging information file pairs using the
21277following commands:
21278
21279@smallexample
21280@kbd{objcopy --only-keep-debug foo foo.debug}
21281@kbd{strip -g foo}
c7e83d54
EZ
21282@end smallexample
21283
21284@noindent
21285These commands remove the debugging
83f83d7f
JK
21286information from the executable file @file{foo} and place it in the file
21287@file{foo.debug}. You can use the first, second or both methods to link the
21288two files:
21289
21290@itemize @bullet
21291@item
21292The debug link method needs the following additional command to also leave
21293behind a debug link in @file{foo}:
21294
21295@smallexample
21296@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21297@end smallexample
21298
21299Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 21300a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
21301foo.debug} has the same functionality as the two @code{objcopy} commands and
21302the @code{ln -s} command above, together.
21303
21304@item
21305Build ID gets embedded into the main executable using @code{ld --build-id} or
21306the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21307compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21308utilities (Binutils) package since version 2.18.
83f83d7f
JK
21309@end itemize
21310
21311@noindent
d3750b24 21312
99e008fe
EZ
21313@cindex CRC algorithm definition
21314The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21315IEEE 802.3 using the polynomial:
21316
21317@c TexInfo requires naked braces for multi-digit exponents for Tex
21318@c output, but this causes HTML output to barf. HTML has to be set using
21319@c raw commands. So we end up having to specify this equation in 2
21320@c different ways!
21321@ifhtml
21322@display
21323@html
21324 <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>
21325 + <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
21326@end html
21327@end display
21328@end ifhtml
21329@ifnothtml
21330@display
21331 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21332 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21333@end display
21334@end ifnothtml
21335
21336The function is computed byte at a time, taking the least
21337significant bit of each byte first. The initial pattern
21338@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21339the final result is inverted to ensure trailing zeros also affect the
21340CRC.
21341
21342@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21343@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21344However in the case of the Remote Serial Protocol, the CRC is computed
21345@emph{most} significant bit first, and the result is not inverted, so
21346trailing zeros have no effect on the CRC value.
99e008fe
EZ
21347
21348To complete the description, we show below the code of the function
21349which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21350initially supplied @code{crc} argument means that an initial call to
21351this function passing in zero will start computing the CRC using
21352@code{0xffffffff}.
5b5d99cf 21353
4644b6e3 21354@kindex gnu_debuglink_crc32
5b5d99cf
JB
21355@smallexample
21356unsigned long
21357gnu_debuglink_crc32 (unsigned long crc,
21358 unsigned char *buf, size_t len)
21359@{
21360 static const unsigned long crc32_table[256] =
21361 @{
21362 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21363 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21364 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21365 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21366 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21367 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21368 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21369 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21370 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21371 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21372 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21373 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21374 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21375 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21376 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21377 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21378 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21379 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21380 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21381 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21382 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21383 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21384 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21385 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21386 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21387 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21388 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21389 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21390 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21391 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21392 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21393 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21394 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21395 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21396 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21397 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21398 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21399 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21400 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21401 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21402 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21403 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21404 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21405 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21406 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21407 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21408 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21409 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21410 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21411 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21412 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21413 0x2d02ef8d
21414 @};
21415 unsigned char *end;
21416
21417 crc = ~crc & 0xffffffff;
21418 for (end = buf + len; buf < end; ++buf)
21419 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21420 return ~crc & 0xffffffff;
5b5d99cf
JB
21421@}
21422@end smallexample
21423
c7e83d54
EZ
21424@noindent
21425This computation does not apply to the ``build ID'' method.
21426
608e2dbb
TT
21427@node MiniDebugInfo
21428@section Debugging information in a special section
21429@cindex separate debug sections
21430@cindex @samp{.gnu_debugdata} section
21431
21432Some systems ship pre-built executables and libraries that have a
21433special @samp{.gnu_debugdata} section. This feature is called
21434@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21435is used to supply extra symbols for backtraces.
21436
21437The intent of this section is to provide extra minimal debugging
21438information for use in simple backtraces. It is not intended to be a
21439replacement for full separate debugging information (@pxref{Separate
21440Debug Files}). The example below shows the intended use; however,
21441@value{GDBN} does not currently put restrictions on what sort of
21442debugging information might be included in the section.
21443
21444@value{GDBN} has support for this extension. If the section exists,
21445then it is used provided that no other source of debugging information
21446can be found, and that @value{GDBN} was configured with LZMA support.
21447
21448This section can be easily created using @command{objcopy} and other
21449standard utilities:
21450
21451@smallexample
21452# Extract the dynamic symbols from the main binary, there is no need
5423b017 21453# to also have these in the normal symbol table.
608e2dbb
TT
21454nm -D @var{binary} --format=posix --defined-only \
21455 | awk '@{ print $1 @}' | sort > dynsyms
21456
5423b017 21457# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21458# (Note that we actually also accept "D" symbols, for the benefit
21459# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21460nm @var{binary} --format=posix --defined-only \
1d236d23 21461 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21462 | sort > funcsyms
21463
21464# Keep all the function symbols not already in the dynamic symbol
21465# table.
21466comm -13 dynsyms funcsyms > keep_symbols
21467
edf9f00c
JK
21468# Separate full debug info into debug binary.
21469objcopy --only-keep-debug @var{binary} debug
21470
608e2dbb
TT
21471# Copy the full debuginfo, keeping only a minimal set of symbols and
21472# removing some unnecessary sections.
21473objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21474 --keep-symbols=keep_symbols debug mini_debuginfo
21475
21476# Drop the full debug info from the original binary.
21477strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21478
21479# Inject the compressed data into the .gnu_debugdata section of the
21480# original binary.
21481xz mini_debuginfo
21482objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21483@end smallexample
5b5d99cf 21484
9291a0cd
TT
21485@node Index Files
21486@section Index Files Speed Up @value{GDBN}
21487@cindex index files
21488@cindex @samp{.gdb_index} section
21489
21490When @value{GDBN} finds a symbol file, it scans the symbols in the
21491file in order to construct an internal symbol table. This lets most
21492@value{GDBN} operations work quickly---at the cost of a delay early
21493on. For large programs, this delay can be quite lengthy, so
21494@value{GDBN} provides a way to build an index, which speeds up
21495startup.
21496
ba643918
SDJ
21497For convenience, @value{GDBN} comes with a program,
21498@command{gdb-add-index}, which can be used to add the index to a
21499symbol file. It takes the symbol file as its only argument:
21500
21501@smallexample
21502$ gdb-add-index symfile
21503@end smallexample
21504
21505@xref{gdb-add-index}.
21506
21507It is also possible to do the work manually. Here is what
21508@command{gdb-add-index} does behind the curtains.
21509
9291a0cd
TT
21510The index is stored as a section in the symbol file. @value{GDBN} can
21511write the index to a file, then you can put it into the symbol file
21512using @command{objcopy}.
21513
21514To create an index file, use the @code{save gdb-index} command:
21515
21516@table @code
437afbb8 21517@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21518@kindex save gdb-index
437afbb8
JK
21519Create index files for all symbol files currently known by
21520@value{GDBN}. For each known @var{symbol-file}, this command by
21521default creates it produces a single file
21522@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21523the @option{-dwarf-5} option, it produces 2 files:
21524@file{@var{symbol-file}.debug_names} and
21525@file{@var{symbol-file}.debug_str}. The files are created in the
21526given @var{directory}.
9291a0cd
TT
21527@end table
21528
21529Once you have created an index file you can merge it into your symbol
21530file, here named @file{symfile}, using @command{objcopy}:
21531
21532@smallexample
21533$ objcopy --add-section .gdb_index=symfile.gdb-index \
21534 --set-section-flags .gdb_index=readonly symfile symfile
21535@end smallexample
21536
437afbb8
JK
21537Or for @code{-dwarf-5}:
21538
21539@smallexample
21540$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21541$ cat symfile.debug_str >>symfile.debug_str.new
21542$ objcopy --add-section .debug_names=symfile.gdb-index \
21543 --set-section-flags .debug_names=readonly \
21544 --update-section .debug_str=symfile.debug_str.new symfile symfile
21545@end smallexample
21546
e615022a
DE
21547@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21548sections that have been deprecated. Usually they are deprecated because
21549they are missing a new feature or have performance issues.
21550To tell @value{GDBN} to use a deprecated index section anyway
21551specify @code{set use-deprecated-index-sections on}.
21552The default is @code{off}.
21553This can speed up startup, but may result in some functionality being lost.
21554@xref{Index Section Format}.
21555
21556@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21557must be done before gdb reads the file. The following will not work:
21558
21559@smallexample
21560$ gdb -ex "set use-deprecated-index-sections on" <program>
21561@end smallexample
21562
21563Instead you must do, for example,
21564
21565@smallexample
21566$ gdb -iex "set use-deprecated-index-sections on" <program>
21567@end smallexample
21568
914592f9 21569Indices only work when using DWARF debugging information, not stabs.
9291a0cd 21570
7d11235d
SM
21571@subsection Automatic symbol index cache
21572
a0a3a1e9 21573@cindex automatic symbol index cache
7d11235d
SM
21574It is possible for @value{GDBN} to automatically save a copy of this index in a
21575cache on disk and retrieve it from there when loading the same binary in the
21576future. This feature can be turned on with @kbd{set index-cache on}. The
21577following commands can be used to tweak the behavior of the index cache.
21578
21579@table @code
21580
a0a3a1e9 21581@kindex set index-cache
7d11235d
SM
21582@item set index-cache on
21583@itemx set index-cache off
21584Enable or disable the use of the symbol index cache.
21585
21586@item set index-cache directory @var{directory}
a0a3a1e9 21587@kindex show index-cache
7d11235d 21588@itemx show index-cache directory
e6cd1dc1
TT
21589Set/show the directory where index files will be saved.
21590
21591The default value for this directory depends on the host platform. On
21592most systems, the index is cached in the @file{gdb} subdirectory of
21593the directory pointed to by the @env{XDG_CACHE_HOME} environment
21594variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21595of your home directory. However, on some systems, the default may
21596differ according to local convention.
7d11235d
SM
21597
21598There is no limit on the disk space used by index cache. It is perfectly safe
21599to delete the content of that directory to free up disk space.
21600
21601@item show index-cache stats
21602Print the number of cache hits and misses since the launch of @value{GDBN}.
21603
21604@end table
21605
6d2ebf8b 21606@node Symbol Errors
79a6e687 21607@section Errors Reading Symbol Files
c906108c
SS
21608
21609While reading a symbol file, @value{GDBN} occasionally encounters problems,
21610such as symbol types it does not recognize, or known bugs in compiler
21611output. By default, @value{GDBN} does not notify you of such problems, since
21612they are relatively common and primarily of interest to people
21613debugging compilers. If you are interested in seeing information
21614about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21615only one message about each such type of problem, no matter how many
21616times the problem occurs; or you can ask @value{GDBN} to print more messages,
21617to see how many times the problems occur, with the @code{set
79a6e687
BW
21618complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21619Messages}).
c906108c
SS
21620
21621The messages currently printed, and their meanings, include:
21622
21623@table @code
21624@item inner block not inside outer block in @var{symbol}
21625
21626The symbol information shows where symbol scopes begin and end
21627(such as at the start of a function or a block of statements). This
21628error indicates that an inner scope block is not fully contained
21629in its outer scope blocks.
21630
21631@value{GDBN} circumvents the problem by treating the inner block as if it had
21632the same scope as the outer block. In the error message, @var{symbol}
21633may be shown as ``@code{(don't know)}'' if the outer block is not a
21634function.
21635
21636@item block at @var{address} out of order
21637
21638The symbol information for symbol scope blocks should occur in
21639order of increasing addresses. This error indicates that it does not
21640do so.
21641
21642@value{GDBN} does not circumvent this problem, and has trouble
21643locating symbols in the source file whose symbols it is reading. (You
21644can often determine what source file is affected by specifying
79a6e687
BW
21645@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21646Messages}.)
c906108c
SS
21647
21648@item bad block start address patched
21649
21650The symbol information for a symbol scope block has a start address
21651smaller than the address of the preceding source line. This is known
21652to occur in the SunOS 4.1.1 (and earlier) C compiler.
21653
21654@value{GDBN} circumvents the problem by treating the symbol scope block as
21655starting on the previous source line.
21656
21657@item bad string table offset in symbol @var{n}
21658
21659@cindex foo
21660Symbol number @var{n} contains a pointer into the string table which is
21661larger than the size of the string table.
21662
21663@value{GDBN} circumvents the problem by considering the symbol to have the
21664name @code{foo}, which may cause other problems if many symbols end up
21665with this name.
21666
21667@item unknown symbol type @code{0x@var{nn}}
21668
7a292a7a
SS
21669The symbol information contains new data types that @value{GDBN} does
21670not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21671uncomprehended information, in hexadecimal.
c906108c 21672
7a292a7a
SS
21673@value{GDBN} circumvents the error by ignoring this symbol information.
21674This usually allows you to debug your program, though certain symbols
c906108c 21675are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21676debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21677on @code{complain}, then go up to the function @code{read_dbx_symtab}
21678and examine @code{*bufp} to see the symbol.
c906108c
SS
21679
21680@item stub type has NULL name
c906108c 21681
7a292a7a 21682@value{GDBN} could not find the full definition for a struct or class.
c906108c 21683
7a292a7a 21684@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21685The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21686information that recent versions of the compiler should have output for
21687it.
c906108c
SS
21688
21689@item info mismatch between compiler and debugger
21690
21691@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21692
c906108c
SS
21693@end table
21694
b14b1491
TT
21695@node Data Files
21696@section GDB Data Files
21697
21698@cindex prefix for data files
21699@value{GDBN} will sometimes read an auxiliary data file. These files
21700are kept in a directory known as the @dfn{data directory}.
21701
21702You can set the data directory's name, and view the name @value{GDBN}
21703is currently using.
21704
21705@table @code
21706@kindex set data-directory
21707@item set data-directory @var{directory}
21708Set the directory which @value{GDBN} searches for auxiliary data files
21709to @var{directory}.
21710
21711@kindex show data-directory
21712@item show data-directory
21713Show the directory @value{GDBN} searches for auxiliary data files.
21714@end table
21715
21716@cindex default data directory
21717@cindex @samp{--with-gdb-datadir}
21718You can set the default data directory by using the configure-time
21719@samp{--with-gdb-datadir} option. If the data directory is inside
21720@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21721@samp{--exec-prefix}), then the default data directory will be updated
21722automatically if the installed @value{GDBN} is moved to a new
21723location.
21724
aae1c79a
DE
21725The data directory may also be specified with the
21726@code{--data-directory} command line option.
21727@xref{Mode Options}.
21728
6d2ebf8b 21729@node Targets
c906108c 21730@chapter Specifying a Debugging Target
7a292a7a 21731
c906108c 21732@cindex debugging target
c906108c 21733A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21734
21735Often, @value{GDBN} runs in the same host environment as your program;
21736in that case, the debugging target is specified as a side effect when
21737you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21738flexibility---for example, running @value{GDBN} on a physically separate
21739host, or controlling a standalone system over a serial port or a
53a5351d
JM
21740realtime system over a TCP/IP connection---you can use the @code{target}
21741command to specify one of the target types configured for @value{GDBN}
79a6e687 21742(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21743
a8f24a35
EZ
21744@cindex target architecture
21745It is possible to build @value{GDBN} for several different @dfn{target
21746architectures}. When @value{GDBN} is built like that, you can choose
21747one of the available architectures with the @kbd{set architecture}
21748command.
21749
21750@table @code
21751@kindex set architecture
21752@kindex show architecture
21753@item set architecture @var{arch}
21754This command sets the current target architecture to @var{arch}. The
21755value of @var{arch} can be @code{"auto"}, in addition to one of the
21756supported architectures.
21757
21758@item show architecture
21759Show the current target architecture.
9c16f35a
EZ
21760
21761@item set processor
21762@itemx processor
21763@kindex set processor
21764@kindex show processor
21765These are alias commands for, respectively, @code{set architecture}
21766and @code{show architecture}.
a8f24a35
EZ
21767@end table
21768
c906108c
SS
21769@menu
21770* Active Targets:: Active targets
21771* Target Commands:: Commands for managing targets
c906108c 21772* Byte Order:: Choosing target byte order
c906108c
SS
21773@end menu
21774
6d2ebf8b 21775@node Active Targets
79a6e687 21776@section Active Targets
7a292a7a 21777
c906108c
SS
21778@cindex stacking targets
21779@cindex active targets
21780@cindex multiple targets
21781
8ea5bce5 21782There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21783recording sessions. Core files belong to the process class, making core file
21784and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21785on multiple active targets, one in each class. This allows you to (for
21786example) start a process and inspect its activity, while still having access to
21787the executable file after the process finishes. Or if you start process
21788recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21789presented a virtual layer of the recording target, while the process target
21790remains stopped at the chronologically last point of the process execution.
21791
21792Use the @code{core-file} and @code{exec-file} commands to select a new core
21793file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21794specify as a target a process that is already running, use the @code{attach}
21795command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21796
6d2ebf8b 21797@node Target Commands
79a6e687 21798@section Commands for Managing Targets
c906108c
SS
21799
21800@table @code
21801@item target @var{type} @var{parameters}
7a292a7a
SS
21802Connects the @value{GDBN} host environment to a target machine or
21803process. A target is typically a protocol for talking to debugging
21804facilities. You use the argument @var{type} to specify the type or
21805protocol of the target machine.
c906108c
SS
21806
21807Further @var{parameters} are interpreted by the target protocol, but
21808typically include things like device names or host names to connect
21809with, process numbers, and baud rates.
c906108c
SS
21810
21811The @code{target} command does not repeat if you press @key{RET} again
21812after executing the command.
21813
21814@kindex help target
21815@item help target
21816Displays the names of all targets available. To display targets
21817currently selected, use either @code{info target} or @code{info files}
79a6e687 21818(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21819
21820@item help target @var{name}
21821Describe a particular target, including any parameters necessary to
21822select it.
21823
21824@kindex set gnutarget
21825@item set gnutarget @var{args}
5d161b24 21826@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21827knows whether it is reading an @dfn{executable},
5d161b24
DB
21828a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21829with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21830with @code{gnutarget} the @code{target} refers to a program, not a machine.
21831
d4f3574e 21832@quotation
c906108c
SS
21833@emph{Warning:} To specify a file format with @code{set gnutarget},
21834you must know the actual BFD name.
d4f3574e 21835@end quotation
c906108c 21836
d4f3574e 21837@noindent
79a6e687 21838@xref{Files, , Commands to Specify Files}.
c906108c 21839
5d161b24 21840@kindex show gnutarget
c906108c
SS
21841@item show gnutarget
21842Use the @code{show gnutarget} command to display what file format
21843@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21844@value{GDBN} will determine the file format for each file automatically,
c4957902 21845and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21846@end table
21847
4644b6e3 21848@cindex common targets
c906108c
SS
21849Here are some common targets (available, or not, depending on the GDB
21850configuration):
c906108c
SS
21851
21852@table @code
4644b6e3 21853@kindex target
c906108c 21854@item target exec @var{program}
4644b6e3 21855@cindex executable file target
c906108c
SS
21856An executable file. @samp{target exec @var{program}} is the same as
21857@samp{exec-file @var{program}}.
21858
c906108c 21859@item target core @var{filename}
4644b6e3 21860@cindex core dump file target
c906108c
SS
21861A core dump file. @samp{target core @var{filename}} is the same as
21862@samp{core-file @var{filename}}.
c906108c 21863
1a10341b 21864@item target remote @var{medium}
4644b6e3 21865@cindex remote target
1a10341b
JB
21866A remote system connected to @value{GDBN} via a serial line or network
21867connection. This command tells @value{GDBN} to use its own remote
21868protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21869
21870For example, if you have a board connected to @file{/dev/ttya} on the
21871machine running @value{GDBN}, you could say:
21872
21873@smallexample
21874target remote /dev/ttya
21875@end smallexample
21876
21877@code{target remote} supports the @code{load} command. This is only
21878useful if you have some other way of getting the stub to the target
21879system, and you can put it somewhere in memory where it won't get
21880clobbered by the download.
c906108c 21881
ee8e71d4 21882@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21883@cindex built-in simulator target
2df3850c 21884Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21885In general,
474c8240 21886@smallexample
104c1213
JM
21887 target sim
21888 load
21889 run
474c8240 21890@end smallexample
d4f3574e 21891@noindent
104c1213 21892works; however, you cannot assume that a specific memory map, device
d4f3574e 21893drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21894provide these. For info about any processor-specific simulator details,
21895see the appropriate section in @ref{Embedded Processors, ,Embedded
21896Processors}.
21897
6a3cb8e8
PA
21898@item target native
21899@cindex native target
21900Setup for local/native process debugging. Useful to make the
21901@code{run} command spawn native processes (likewise @code{attach},
21902etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21903(@pxref{set auto-connect-native-target}).
21904
c906108c
SS
21905@end table
21906
5d161b24 21907Different targets are available on different configurations of @value{GDBN};
c906108c 21908your configuration may have more or fewer targets.
c906108c 21909
721c2651
EZ
21910Many remote targets require you to download the executable's code once
21911you've successfully established a connection. You may wish to control
3d00d119
DJ
21912various aspects of this process.
21913
21914@table @code
721c2651
EZ
21915
21916@item set hash
21917@kindex set hash@r{, for remote monitors}
21918@cindex hash mark while downloading
21919This command controls whether a hash mark @samp{#} is displayed while
21920downloading a file to the remote monitor. If on, a hash mark is
21921displayed after each S-record is successfully downloaded to the
21922monitor.
21923
21924@item show hash
21925@kindex show hash@r{, for remote monitors}
21926Show the current status of displaying the hash mark.
21927
21928@item set debug monitor
21929@kindex set debug monitor
21930@cindex display remote monitor communications
21931Enable or disable display of communications messages between
21932@value{GDBN} and the remote monitor.
21933
21934@item show debug monitor
21935@kindex show debug monitor
21936Show the current status of displaying communications between
21937@value{GDBN} and the remote monitor.
a8f24a35 21938@end table
c906108c
SS
21939
21940@table @code
21941
5cf30ebf
LM
21942@kindex load @var{filename} @var{offset}
21943@item load @var{filename} @var{offset}
8edfe269 21944@anchor{load}
c906108c
SS
21945Depending on what remote debugging facilities are configured into
21946@value{GDBN}, the @code{load} command may be available. Where it exists, it
21947is meant to make @var{filename} (an executable) available for debugging
21948on the remote system---by downloading, or dynamic linking, for example.
21949@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21950the @code{add-symbol-file} command.
21951
21952If your @value{GDBN} does not have a @code{load} command, attempting to
21953execute it gets the error message ``@code{You can't do that when your
21954target is @dots{}}''
c906108c
SS
21955
21956The file is loaded at whatever address is specified in the executable.
21957For some object file formats, you can specify the load address when you
21958link the program; for other formats, like a.out, the object file format
21959specifies a fixed address.
21960@c FIXME! This would be a good place for an xref to the GNU linker doc.
21961
5cf30ebf
LM
21962It is also possible to tell @value{GDBN} to load the executable file at a
21963specific offset described by the optional argument @var{offset}. When
21964@var{offset} is provided, @var{filename} must also be provided.
21965
68437a39
DJ
21966Depending on the remote side capabilities, @value{GDBN} may be able to
21967load programs into flash memory.
21968
c906108c
SS
21969@code{load} does not repeat if you press @key{RET} again after using it.
21970@end table
21971
78cbbba8
LM
21972@table @code
21973
21974@kindex flash-erase
21975@item flash-erase
21976@anchor{flash-erase}
21977
21978Erases all known flash memory regions on the target.
21979
21980@end table
21981
6d2ebf8b 21982@node Byte Order
79a6e687 21983@section Choosing Target Byte Order
7a292a7a 21984
c906108c
SS
21985@cindex choosing target byte order
21986@cindex target byte order
c906108c 21987
eb17f351 21988Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21989offer the ability to run either big-endian or little-endian byte
21990orders. Usually the executable or symbol will include a bit to
21991designate the endian-ness, and you will not need to worry about
21992which to use. However, you may still find it useful to adjust
d4f3574e 21993@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21994
21995@table @code
4644b6e3 21996@kindex set endian
c906108c
SS
21997@item set endian big
21998Instruct @value{GDBN} to assume the target is big-endian.
21999
c906108c
SS
22000@item set endian little
22001Instruct @value{GDBN} to assume the target is little-endian.
22002
c906108c
SS
22003@item set endian auto
22004Instruct @value{GDBN} to use the byte order associated with the
22005executable.
22006
22007@item show endian
22008Display @value{GDBN}'s current idea of the target byte order.
22009
22010@end table
22011
4b2dfa9d
MR
22012If the @code{set endian auto} mode is in effect and no executable has
22013been selected, then the endianness used is the last one chosen either
22014by one of the @code{set endian big} and @code{set endian little}
22015commands or by inferring from the last executable used. If no
22016endianness has been previously chosen, then the default for this mode
22017is inferred from the target @value{GDBN} has been built for, and is
22018@code{little} if the name of the target CPU has an @code{el} suffix
22019and @code{big} otherwise.
22020
c906108c
SS
22021Note that these commands merely adjust interpretation of symbolic
22022data on the host, and that they have absolutely no effect on the
22023target system.
22024
ea35711c
DJ
22025
22026@node Remote Debugging
22027@chapter Debugging Remote Programs
c906108c
SS
22028@cindex remote debugging
22029
22030If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
22031@value{GDBN} in the usual way, it is often useful to use remote debugging.
22032For example, you might use remote debugging on an operating system kernel,
c906108c
SS
22033or on a small system which does not have a general purpose operating system
22034powerful enough to run a full-featured debugger.
22035
22036Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22037to make this work with particular debugging targets. In addition,
5d161b24 22038@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
22039but not specific to any particular target system) which you can use if you
22040write the remote stubs---the code that runs on the remote system to
22041communicate with @value{GDBN}.
22042
22043Other remote targets may be available in your
22044configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 22045
6b2f586d 22046@menu
07f31aa6 22047* Connecting:: Connecting to a remote target
a6b151f1 22048* File Transfer:: Sending files to a remote system
6b2f586d 22049* Server:: Using the gdbserver program
79a6e687
BW
22050* Remote Configuration:: Remote configuration
22051* Remote Stub:: Implementing a remote stub
6b2f586d
AC
22052@end menu
22053
07f31aa6 22054@node Connecting
79a6e687 22055@section Connecting to a Remote Target
19d9d4ef
DB
22056@cindex remote debugging, connecting
22057@cindex @code{gdbserver}, connecting
22058@cindex remote debugging, types of connections
22059@cindex @code{gdbserver}, types of connections
22060@cindex @code{gdbserver}, @code{target remote} mode
22061@cindex @code{gdbserver}, @code{target extended-remote} mode
22062
22063This section describes how to connect to a remote target, including the
22064types of connections and their differences, how to set up executable and
22065symbol files on the host and target, and the commands used for
22066connecting to and disconnecting from the remote target.
22067
22068@subsection Types of Remote Connections
22069
22070@value{GDBN} supports two types of remote connections, @code{target remote}
22071mode and @code{target extended-remote} mode. Note that many remote targets
22072support only @code{target remote} mode. There are several major
22073differences between the two types of connections, enumerated here:
22074
22075@table @asis
22076
22077@cindex remote debugging, detach and program exit
22078@item Result of detach or program exit
22079@strong{With target remote mode:} When the debugged program exits or you
22080detach from it, @value{GDBN} disconnects from the target. When using
22081@code{gdbserver}, @code{gdbserver} will exit.
22082
22083@strong{With target extended-remote mode:} When the debugged program exits or
22084you detach from it, @value{GDBN} remains connected to the target, even
22085though no program is running. You can rerun the program, attach to a
22086running program, or use @code{monitor} commands specific to the target.
22087
22088When using @code{gdbserver} in this case, it does not exit unless it was
22089invoked using the @option{--once} option. If the @option{--once} option
22090was not used, you can ask @code{gdbserver} to exit using the
22091@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22092
22093@item Specifying the program to debug
22094For both connection types you use the @code{file} command to specify the
22095program on the host system. If you are using @code{gdbserver} there are
22096some differences in how to specify the location of the program on the
22097target.
22098
22099@strong{With target remote mode:} You must either specify the program to debug
22100on the @code{gdbserver} command line or use the @option{--attach} option
22101(@pxref{Attaching to a program,,Attaching to a Running Program}).
22102
22103@cindex @option{--multi}, @code{gdbserver} option
22104@strong{With target extended-remote mode:} You may specify the program to debug
22105on the @code{gdbserver} command line, or you can load the program or attach
22106to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22107
22108@anchor{--multi Option in Types of Remote Connnections}
22109You can start @code{gdbserver} without supplying an initial command to run
22110or process ID to attach. To do this, use the @option{--multi} command line
22111option. Then you can connect using @code{target extended-remote} and start
22112the program you want to debug (see below for details on using the
22113@code{run} command in this scenario). Note that the conditions under which
22114@code{gdbserver} terminates depend on how @value{GDBN} connects to it
22115(@code{target remote} or @code{target extended-remote}). The
22116@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 22117
19d9d4ef
DB
22118@item The @code{run} command
22119@strong{With target remote mode:} The @code{run} command is not
22120supported. Once a connection has been established, you can use all
22121the usual @value{GDBN} commands to examine and change data. The
22122remote program is already running, so you can use commands like
22123@kbd{step} and @kbd{continue}.
22124
22125@strong{With target extended-remote mode:} The @code{run} command is
22126supported. The @code{run} command uses the value set by
22127@code{set remote exec-file} (@pxref{set remote exec-file}) to select
22128the program to run. Command line arguments are supported, except for
22129wildcard expansion and I/O redirection (@pxref{Arguments}).
22130
22131If you specify the program to debug on the command line, then the
22132@code{run} command is not required to start execution, and you can
22133resume using commands like @kbd{step} and @kbd{continue} as with
22134@code{target remote} mode.
22135
22136@anchor{Attaching in Types of Remote Connections}
22137@item Attaching
22138@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22139not supported. To attach to a running program using @code{gdbserver}, you
22140must use the @option{--attach} option (@pxref{Running gdbserver}).
22141
22142@strong{With target extended-remote mode:} To attach to a running program,
22143you may use the @code{attach} command after the connection has been
22144established. If you are using @code{gdbserver}, you may also invoke
22145@code{gdbserver} using the @option{--attach} option
22146(@pxref{Running gdbserver}).
22147
e47e48f6
PW
22148Some remote targets allow @value{GDBN} to determine the executable file running
22149in the process the debugger is attaching to. In such a case, @value{GDBN}
22150uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22151between the executable file name running in the process and the name of the
22152current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22153
19d9d4ef
DB
22154@end table
22155
22156@anchor{Host and target files}
22157@subsection Host and Target Files
22158@cindex remote debugging, symbol files
22159@cindex symbol files, remote debugging
22160
22161@value{GDBN}, running on the host, needs access to symbol and debugging
22162information for your program running on the target. This requires
22163access to an unstripped copy of your program, and possibly any associated
22164symbol files. Note that this section applies equally to both @code{target
22165remote} mode and @code{target extended-remote} mode.
22166
22167Some remote targets (@pxref{qXfer executable filename read}, and
22168@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22169the same connection used to communicate with @value{GDBN}. With such a
22170target, if the remote program is unstripped, the only command you need is
22171@code{target remote} (or @code{target extended-remote}).
22172
22173If the remote program is stripped, or the target does not support remote
22174program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 22175unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
22176@code{file} command. Use @code{set sysroot} to specify the location (on
22177the host) of target libraries (unless your @value{GDBN} was compiled with
22178the correct sysroot using @code{--with-sysroot}). Alternatively, you
22179may use @code{set solib-search-path} to specify how @value{GDBN} locates
22180target libraries.
22181
22182The symbol file and target libraries must exactly match the executable
22183and libraries on the target, with one exception: the files on the host
22184system should not be stripped, even if the files on the target system
22185are. Mismatched or missing files will lead to confusing results
22186during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22187files may also prevent @code{gdbserver} from debugging multi-threaded
22188programs.
07f31aa6 22189
19d9d4ef
DB
22190@subsection Remote Connection Commands
22191@cindex remote connection commands
c1168a2f
JD
22192@value{GDBN} can communicate with the target over a serial line, a
22193local Unix domain socket, or
86941c27
JB
22194over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22195each case, @value{GDBN} uses the same protocol for debugging your
22196program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
22197@code{target remote} and @code{target extended-remote} commands
22198establish a connection to the target. Both commands accept the same
22199arguments, which indicate the medium to use:
86941c27
JB
22200
22201@table @code
22202
22203@item target remote @var{serial-device}
19d9d4ef 22204@itemx target extended-remote @var{serial-device}
07f31aa6 22205@cindex serial line, @code{target remote}
86941c27
JB
22206Use @var{serial-device} to communicate with the target. For example,
22207to use a serial line connected to the device named @file{/dev/ttyb}:
22208
22209@smallexample
22210target remote /dev/ttyb
22211@end smallexample
22212
07f31aa6 22213If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 22214@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 22215(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 22216@code{target} command.
07f31aa6 22217
c1168a2f
JD
22218@item target remote @var{local-socket}
22219@itemx target extended-remote @var{local-socket}
22220@cindex local socket, @code{target remote}
22221@cindex Unix domain socket
22222Use @var{local-socket} to communicate with the target. For example,
22223to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22224
22225@smallexample
22226target remote /tmp/gdb-socket0
22227@end smallexample
22228
22229Note that this command has the same form as the command to connect
22230to a serial line. @value{GDBN} will automatically determine which
22231kind of file you have specified and will make the appropriate kind
22232of connection.
22233This feature is not available if the host system does not support
22234Unix domain sockets.
22235
86941c27 22236@item target remote @code{@var{host}:@var{port}}
0ca4866a 22237@itemx target remote @code{[@var{host}]:@var{port}}
86941c27 22238@itemx target remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22239@itemx target remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22240@itemx target remote @code{tcp4:@var{host}:@var{port}}
22241@itemx target remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22242@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
19d9d4ef 22243@itemx target extended-remote @code{@var{host}:@var{port}}
0ca4866a 22244@itemx target extended-remote @code{[@var{host}]:@var{port}}
19d9d4ef 22245@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22246@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22247@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22248@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22249@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
86941c27 22250@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 22251Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
22252The @var{host} may be either a host name, a numeric @acronym{IPv4}
22253address, or a numeric @acronym{IPv6} address (with or without the
22254square brackets to separate the address from the port); @var{port}
22255must be a decimal number. The @var{host} could be the target machine
22256itself, if it is directly connected to the net, or it might be a
22257terminal server which in turn has a serial line to the target.
07f31aa6 22258
86941c27
JB
22259For example, to connect to port 2828 on a terminal server named
22260@code{manyfarms}:
07f31aa6
DJ
22261
22262@smallexample
22263target remote manyfarms:2828
22264@end smallexample
22265
c7ab0aef
SDJ
22266To connect to port 2828 on a terminal server whose address is
22267@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22268square bracket syntax:
22269
22270@smallexample
22271target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22272@end smallexample
22273
22274@noindent
22275or explicitly specify the @acronym{IPv6} protocol:
22276
22277@smallexample
22278target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22279@end smallexample
22280
22281This last example may be confusing to the reader, because there is no
22282visible separation between the hostname and the port number.
22283Therefore, we recommend the user to provide @acronym{IPv6} addresses
22284using square brackets for clarity. However, it is important to
22285mention that for @value{GDBN} there is no ambiguity: the number after
22286the last colon is considered to be the port number.
22287
86941c27
JB
22288If your remote target is actually running on the same machine as your
22289debugger session (e.g.@: a simulator for your target running on the
22290same host), you can omit the hostname. For example, to connect to
22291port 1234 on your local machine:
07f31aa6
DJ
22292
22293@smallexample
22294target remote :1234
22295@end smallexample
22296@noindent
22297
22298Note that the colon is still required here.
22299
86941c27 22300@item target remote @code{udp:@var{host}:@var{port}}
0ca4866a 22301@itemx target remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef 22302@itemx target remote @code{udp4:@var{host}:@var{port}}
0ca4866a 22303@itemx target remote @code{udp6:[@var{host}]:@var{port}}
c7ab0aef 22304@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 22305@itemx target extended-remote @code{udp:@var{host}:@var{port}}
0ca4866a 22306@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22307@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22308@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
0ca4866a 22309@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
86941c27
JB
22310@cindex @acronym{UDP} port, @code{target remote}
22311Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22312connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22313
22314@smallexample
22315target remote udp:manyfarms:2828
22316@end smallexample
22317
86941c27
JB
22318When using a @acronym{UDP} connection for remote debugging, you should
22319keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22320can silently drop packets on busy or unreliable networks, which will
22321cause havoc with your debugging session.
22322
66b8c7f6 22323@item target remote | @var{command}
19d9d4ef 22324@itemx target extended-remote | @var{command}
66b8c7f6
JB
22325@cindex pipe, @code{target remote} to
22326Run @var{command} in the background and communicate with it using a
22327pipe. The @var{command} is a shell command, to be parsed and expanded
22328by the system's command shell, @code{/bin/sh}; it should expect remote
22329protocol packets on its standard input, and send replies on its
22330standard output. You could use this to run a stand-alone simulator
22331that speaks the remote debugging protocol, to make net connections
22332using programs like @code{ssh}, or for other similar tricks.
22333
22334If @var{command} closes its standard output (perhaps by exiting),
22335@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22336program has already exited, this will have no effect.)
22337
86941c27 22338@end table
07f31aa6 22339
07f31aa6
DJ
22340@cindex interrupting remote programs
22341@cindex remote programs, interrupting
22342Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22343interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22344program. This may or may not succeed, depending in part on the hardware
22345and the serial drivers the remote system uses. If you type the
22346interrupt character once again, @value{GDBN} displays this prompt:
22347
22348@smallexample
22349Interrupted while waiting for the program.
22350Give up (and stop debugging it)? (y or n)
22351@end smallexample
22352
19d9d4ef
DB
22353In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22354the remote debugging session. (If you decide you want to try again later,
22355you can use @kbd{target remote} again to connect once more.) If you type
22356@kbd{n}, @value{GDBN} goes back to waiting.
22357
22358In @code{target extended-remote} mode, typing @kbd{n} will leave
22359@value{GDBN} connected to the target.
07f31aa6
DJ
22360
22361@table @code
22362@kindex detach (remote)
22363@item detach
22364When you have finished debugging the remote program, you can use the
22365@code{detach} command to release it from @value{GDBN} control.
22366Detaching from the target normally resumes its execution, but the results
22367will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22368command in @code{target remote} mode, @value{GDBN} is free to connect to
22369another target. In @code{target extended-remote} mode, @value{GDBN} is
22370still connected to the target.
07f31aa6
DJ
22371
22372@kindex disconnect
22373@item disconnect
19d9d4ef 22374The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22375the target is generally not resumed. It will wait for @value{GDBN}
22376(this instance or another one) to connect and continue debugging. After
22377the @code{disconnect} command, @value{GDBN} is again free to connect to
22378another target.
09d4efe1
EZ
22379
22380@cindex send command to remote monitor
fad38dfa
EZ
22381@cindex extend @value{GDBN} for remote targets
22382@cindex add new commands for external monitor
09d4efe1
EZ
22383@kindex monitor
22384@item monitor @var{cmd}
fad38dfa
EZ
22385This command allows you to send arbitrary commands directly to the
22386remote monitor. Since @value{GDBN} doesn't care about the commands it
22387sends like this, this command is the way to extend @value{GDBN}---you
22388can add new commands that only the external monitor will understand
22389and implement.
07f31aa6
DJ
22390@end table
22391
a6b151f1
DJ
22392@node File Transfer
22393@section Sending files to a remote system
22394@cindex remote target, file transfer
22395@cindex file transfer
22396@cindex sending files to remote systems
22397
22398Some remote targets offer the ability to transfer files over the same
22399connection used to communicate with @value{GDBN}. This is convenient
22400for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22401running @code{gdbserver} over a network interface. For other targets,
22402e.g.@: embedded devices with only a single serial port, this may be
22403the only way to upload or download files.
22404
22405Not all remote targets support these commands.
22406
22407@table @code
22408@kindex remote put
22409@item remote put @var{hostfile} @var{targetfile}
22410Copy file @var{hostfile} from the host system (the machine running
22411@value{GDBN}) to @var{targetfile} on the target system.
22412
22413@kindex remote get
22414@item remote get @var{targetfile} @var{hostfile}
22415Copy file @var{targetfile} from the target system to @var{hostfile}
22416on the host system.
22417
22418@kindex remote delete
22419@item remote delete @var{targetfile}
22420Delete @var{targetfile} from the target system.
22421
22422@end table
22423
6f05cf9f 22424@node Server
79a6e687 22425@section Using the @code{gdbserver} Program
6f05cf9f
AC
22426
22427@kindex gdbserver
22428@cindex remote connection without stubs
22429@code{gdbserver} is a control program for Unix-like systems, which
22430allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22431@code{target remote} or @code{target extended-remote}---but without
22432linking in the usual debugging stub.
6f05cf9f
AC
22433
22434@code{gdbserver} is not a complete replacement for the debugging stubs,
22435because it requires essentially the same operating-system facilities
22436that @value{GDBN} itself does. In fact, a system that can run
22437@code{gdbserver} to connect to a remote @value{GDBN} could also run
22438@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22439because it is a much smaller program than @value{GDBN} itself. It is
22440also easier to port than all of @value{GDBN}, so you may be able to get
22441started more quickly on a new system by using @code{gdbserver}.
22442Finally, if you develop code for real-time systems, you may find that
22443the tradeoffs involved in real-time operation make it more convenient to
22444do as much development work as possible on another system, for example
22445by cross-compiling. You can use @code{gdbserver} to make a similar
22446choice for debugging.
22447
22448@value{GDBN} and @code{gdbserver} communicate via either a serial line
22449or a TCP connection, using the standard @value{GDBN} remote serial
22450protocol.
22451
2d717e4f
DJ
22452@quotation
22453@emph{Warning:} @code{gdbserver} does not have any built-in security.
22454Do not run @code{gdbserver} connected to any public network; a
22455@value{GDBN} connection to @code{gdbserver} provides access to the
22456target system with the same privileges as the user running
22457@code{gdbserver}.
22458@end quotation
22459
19d9d4ef 22460@anchor{Running gdbserver}
2d717e4f
DJ
22461@subsection Running @code{gdbserver}
22462@cindex arguments, to @code{gdbserver}
d9b1a651 22463@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22464
22465Run @code{gdbserver} on the target system. You need a copy of the
22466program you want to debug, including any libraries it requires.
6f05cf9f
AC
22467@code{gdbserver} does not need your program's symbol table, so you can
22468strip the program if necessary to save space. @value{GDBN} on the host
22469system does all the symbol handling.
22470
22471To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22472the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22473syntax is:
22474
22475@smallexample
22476target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22477@end smallexample
22478
6cf36756
SM
22479@var{comm} is either a device name (to use a serial line), or a TCP
22480hostname and portnumber, or @code{-} or @code{stdio} to use
22481stdin/stdout of @code{gdbserver}.
e0f9f062 22482For example, to debug Emacs with the argument
6f05cf9f
AC
22483@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22484@file{/dev/com1}:
22485
22486@smallexample
22487target> gdbserver /dev/com1 emacs foo.txt
22488@end smallexample
22489
6cf36756
SM
22490@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22491with it.
6f05cf9f
AC
22492
22493To use a TCP connection instead of a serial line:
22494
22495@smallexample
22496target> gdbserver host:2345 emacs foo.txt
22497@end smallexample
22498
22499The only difference from the previous example is the first argument,
22500specifying that you are communicating with the host @value{GDBN} via
22501TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22502expect a TCP connection from machine @samp{host} to local TCP port 2345.
22503(Currently, the @samp{host} part is ignored.) You can choose any number
22504you want for the port number as long as it does not conflict with any
22505TCP ports already in use on the target system (for example, @code{23} is
22506reserved for @code{telnet}).@footnote{If you choose a port number that
22507conflicts with another service, @code{gdbserver} prints an error message
22508and exits.} You must use the same port number with the host @value{GDBN}
22509@code{target remote} command.
22510
6cf36756
SM
22511The @code{stdio} connection is useful when starting @code{gdbserver}
22512with ssh:
e0f9f062
DE
22513
22514@smallexample
6cf36756 22515(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22516@end smallexample
22517
6cf36756
SM
22518The @samp{-T} option to ssh is provided because we don't need a remote pty,
22519and we don't want escape-character handling. Ssh does this by default when
22520a command is provided, the flag is provided to make it explicit.
22521You could elide it if you want to.
e0f9f062 22522
6cf36756
SM
22523Programs started with stdio-connected gdbserver have @file{/dev/null} for
22524@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22525display through a pipe connected to gdbserver.
22526Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22527
19d9d4ef 22528@anchor{Attaching to a program}
2d717e4f 22529@subsubsection Attaching to a Running Program
d9b1a651
EZ
22530@cindex attach to a program, @code{gdbserver}
22531@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22532
56460a61
DJ
22533On some targets, @code{gdbserver} can also attach to running programs.
22534This is accomplished via the @code{--attach} argument. The syntax is:
22535
22536@smallexample
2d717e4f 22537target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22538@end smallexample
22539
19d9d4ef
DB
22540@var{pid} is the process ID of a currently running process. It isn't
22541necessary to point @code{gdbserver} at a binary for the running process.
22542
22543In @code{target extended-remote} mode, you can also attach using the
22544@value{GDBN} attach command
22545(@pxref{Attaching in Types of Remote Connections}).
56460a61 22546
b1fe9455 22547@pindex pidof
b1fe9455
DJ
22548You can debug processes by name instead of process ID if your target has the
22549@code{pidof} utility:
22550
22551@smallexample
2d717e4f 22552target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22553@end smallexample
22554
f822c95b 22555In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22556has multiple threads, most versions of @code{pidof} support the
22557@code{-s} option to only return the first process ID.
22558
03f2bd59
JK
22559@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22560
19d9d4ef
DB
22561This section applies only when @code{gdbserver} is run to listen on a TCP
22562port.
03f2bd59
JK
22563
22564@code{gdbserver} normally terminates after all of its debugged processes have
22565terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22566extended-remote}, @code{gdbserver} stays running even with no processes left.
22567@value{GDBN} normally terminates the spawned debugged process on its exit,
22568which normally also terminates @code{gdbserver} in the @kbd{target remote}
22569mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22570cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22571stays running even in the @kbd{target remote} mode.
22572
22573When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22574Such reconnecting is useful for features like @ref{disconnected tracing}. For
22575completeness, at most one @value{GDBN} can be connected at a time.
22576
22577@cindex @option{--once}, @code{gdbserver} option
22578By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22579subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22580with the @option{--once} option, it will stop listening for any further
22581connection attempts after connecting to the first @value{GDBN} session. This
22582means no further connections to @code{gdbserver} will be possible after the
22583first one. It also means @code{gdbserver} will terminate after the first
22584connection with remote @value{GDBN} has closed, even for unexpectedly closed
22585connections and even in the @kbd{target extended-remote} mode. The
22586@option{--once} option allows reusing the same port number for connecting to
22587multiple instances of @code{gdbserver} running on the same host, since each
22588instance closes its port after the first connection.
2d717e4f 22589
87ce2a04 22590@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22591@subsubsection Other Command-Line Arguments for @code{gdbserver}
22592
19d9d4ef
DB
22593You can use the @option{--multi} option to start @code{gdbserver} without
22594specifying a program to debug or a process to attach to. Then you can
22595attach in @code{target extended-remote} mode and run or attach to a
22596program. For more information,
22597@pxref{--multi Option in Types of Remote Connnections}.
22598
d9b1a651 22599@cindex @option{--debug}, @code{gdbserver} option
62709adf 22600The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22601status information about the debugging process.
22602@cindex @option{--remote-debug}, @code{gdbserver} option
22603The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22604remote protocol debug output.
22605@cindex @option{--debug-file}, @code{gdbserver} option
22606@cindex @code{gdbserver}, send all debug output to a single file
22607The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22608write any debug output to the given @var{filename}. These options are intended
22609for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22610
87ce2a04
DE
22611@cindex @option{--debug-format}, @code{gdbserver} option
22612The @option{--debug-format=option1[,option2,...]} option tells
22613@code{gdbserver} to include additional information in each output.
22614Possible options are:
22615
22616@table @code
22617@item none
22618Turn off all extra information in debugging output.
22619@item all
22620Turn on all extra information in debugging output.
22621@item timestamps
22622Include a timestamp in each line of debugging output.
22623@end table
22624
22625Options are processed in order. Thus, for example, if @option{none}
22626appears last then no additional information is added to debugging output.
22627
d9b1a651 22628@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22629The @option{--wrapper} option specifies a wrapper to launch programs
22630for debugging. The option should be followed by the name of the
22631wrapper, then any command-line arguments to pass to the wrapper, then
22632@kbd{--} indicating the end of the wrapper arguments.
22633
22634@code{gdbserver} runs the specified wrapper program with a combined
22635command line including the wrapper arguments, then the name of the
22636program to debug, then any arguments to the program. The wrapper
22637runs until it executes your program, and then @value{GDBN} gains control.
22638
22639You can use any program that eventually calls @code{execve} with
22640its arguments as a wrapper. Several standard Unix utilities do
22641this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22642with @code{exec "$@@"} will also work.
22643
22644For example, you can use @code{env} to pass an environment variable to
22645the debugged program, without setting the variable in @code{gdbserver}'s
22646environment:
22647
22648@smallexample
22649$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22650@end smallexample
22651
6d580b63
YQ
22652@cindex @option{--selftest}
22653The @option{--selftest} option runs the self tests in @code{gdbserver}:
22654
22655@smallexample
22656$ gdbserver --selftest
22657Ran 2 unit tests, 0 failed
22658@end smallexample
22659
22660These tests are disabled in release.
2d717e4f
DJ
22661@subsection Connecting to @code{gdbserver}
22662
19d9d4ef
DB
22663The basic procedure for connecting to the remote target is:
22664@itemize
2d717e4f 22665
19d9d4ef
DB
22666@item
22667Run @value{GDBN} on the host system.
f822c95b 22668
19d9d4ef
DB
22669@item
22670Make sure you have the necessary symbol files
22671(@pxref{Host and target files}).
22672Load symbols for your application using the @code{file} command before you
22673connect. Use @code{set sysroot} to locate target libraries (unless your
22674@value{GDBN} was compiled with the correct sysroot using
22675@code{--with-sysroot}).
f822c95b 22676
19d9d4ef 22677@item
79a6e687 22678Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22679For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22680the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22681text depends on the host system, but which usually looks something like
2d717e4f 22682@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22683command in @value{GDBN} when using @code{target remote} mode, since the
22684program is already on the target.
22685
22686@end itemize
07f31aa6 22687
19d9d4ef 22688@anchor{Monitor Commands for gdbserver}
79a6e687 22689@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22690@cindex monitor commands, for @code{gdbserver}
22691
22692During a @value{GDBN} session using @code{gdbserver}, you can use the
22693@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22694Here are the available commands.
c74d0ad8
DJ
22695
22696@table @code
22697@item monitor help
22698List the available monitor commands.
22699
22700@item monitor set debug 0
22701@itemx monitor set debug 1
22702Disable or enable general debugging messages.
22703
22704@item monitor set remote-debug 0
22705@itemx monitor set remote-debug 1
22706Disable or enable specific debugging messages associated with the remote
22707protocol (@pxref{Remote Protocol}).
22708
aeb2e706
AH
22709@item monitor set debug-file filename
22710@itemx monitor set debug-file
22711Send any debug output to the given file, or to stderr.
22712
87ce2a04
DE
22713@item monitor set debug-format option1@r{[},option2,...@r{]}
22714Specify additional text to add to debugging messages.
22715Possible options are:
22716
22717@table @code
22718@item none
22719Turn off all extra information in debugging output.
22720@item all
22721Turn on all extra information in debugging output.
22722@item timestamps
22723Include a timestamp in each line of debugging output.
22724@end table
22725
22726Options are processed in order. Thus, for example, if @option{none}
22727appears last then no additional information is added to debugging output.
22728
cdbfd419
PP
22729@item monitor set libthread-db-search-path [PATH]
22730@cindex gdbserver, search path for @code{libthread_db}
22731When this command is issued, @var{path} is a colon-separated list of
22732directories to search for @code{libthread_db} (@pxref{Threads,,set
22733libthread-db-search-path}). If you omit @var{path},
84e578fb 22734@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22735
98a5dd13
DE
22736The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22737not supported in @code{gdbserver}.
22738
2d717e4f
DJ
22739@item monitor exit
22740Tell gdbserver to exit immediately. This command should be followed by
22741@code{disconnect} to close the debugging session. @code{gdbserver} will
22742detach from any attached processes and kill any processes it created.
22743Use @code{monitor exit} to terminate @code{gdbserver} at the end
22744of a multi-process mode debug session.
22745
c74d0ad8
DJ
22746@end table
22747
fa593d66
PA
22748@subsection Tracepoints support in @code{gdbserver}
22749@cindex tracepoints support in @code{gdbserver}
22750
0fb4aa4b
PA
22751On some targets, @code{gdbserver} supports tracepoints, fast
22752tracepoints and static tracepoints.
fa593d66 22753
0fb4aa4b 22754For fast or static tracepoints to work, a special library called the
fa593d66
PA
22755@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22756This library is built and distributed as an integral part of
0fb4aa4b
PA
22757@code{gdbserver}. In addition, support for static tracepoints
22758requires building the in-process agent library with static tracepoints
22759support. At present, the UST (LTTng Userspace Tracer,
22760@url{http://lttng.org/ust}) tracing engine is supported. This support
22761is automatically available if UST development headers are found in the
22762standard include path when @code{gdbserver} is built, or if
22763@code{gdbserver} was explicitly configured using @option{--with-ust}
22764to point at such headers. You can explicitly disable the support
22765using @option{--with-ust=no}.
fa593d66
PA
22766
22767There are several ways to load the in-process agent in your program:
22768
22769@table @code
22770@item Specifying it as dependency at link time
22771
22772You can link your program dynamically with the in-process agent
22773library. On most systems, this is accomplished by adding
22774@code{-linproctrace} to the link command.
22775
22776@item Using the system's preloading mechanisms
22777
22778You can force loading the in-process agent at startup time by using
22779your system's support for preloading shared libraries. Many Unixes
22780support the concept of preloading user defined libraries. In most
22781cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22782in the environment. See also the description of @code{gdbserver}'s
22783@option{--wrapper} command line option.
22784
22785@item Using @value{GDBN} to force loading the agent at run time
22786
22787On some systems, you can force the inferior to load a shared library,
22788by calling a dynamic loader function in the inferior that takes care
22789of dynamically looking up and loading a shared library. On most Unix
22790systems, the function is @code{dlopen}. You'll use the @code{call}
22791command for that. For example:
22792
22793@smallexample
22794(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22795@end smallexample
22796
22797Note that on most Unix systems, for the @code{dlopen} function to be
22798available, the program needs to be linked with @code{-ldl}.
22799@end table
22800
22801On systems that have a userspace dynamic loader, like most Unix
22802systems, when you connect to @code{gdbserver} using @code{target
22803remote}, you'll find that the program is stopped at the dynamic
22804loader's entry point, and no shared library has been loaded in the
22805program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22806case, before being able to use any of the fast or static tracepoints
22807features, you need to let the loader run and load the shared
22808libraries. The simplest way to do that is to run the program to the
22809main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22810@code{gdbserver} like so:
22811
22812@smallexample
22813$ gdbserver :9999 myprogram
22814@end smallexample
22815
22816Start GDB and connect to @code{gdbserver} like so, and run to main:
22817
22818@smallexample
22819$ gdb myprogram
22820(@value{GDBP}) target remote myhost:9999
228210x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22822(@value{GDBP}) b main
22823(@value{GDBP}) continue
22824@end smallexample
22825
22826The in-process tracing agent library should now be loaded into the
22827process; you can confirm it with the @code{info sharedlibrary}
22828command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22829process. You are now ready to install fast tracepoints, list static
22830tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22831tracing.
22832
79a6e687
BW
22833@node Remote Configuration
22834@section Remote Configuration
501eef12 22835
9c16f35a
EZ
22836@kindex set remote
22837@kindex show remote
22838This section documents the configuration options available when
22839debugging remote programs. For the options related to the File I/O
fc320d37 22840extensions of the remote protocol, see @ref{system,
9c16f35a 22841system-call-allowed}.
501eef12
AC
22842
22843@table @code
9c16f35a 22844@item set remoteaddresssize @var{bits}
d3e8051b 22845@cindex address size for remote targets
9c16f35a
EZ
22846@cindex bits in remote address
22847Set the maximum size of address in a memory packet to the specified
22848number of bits. @value{GDBN} will mask off the address bits above
22849that number, when it passes addresses to the remote target. The
22850default value is the number of bits in the target's address.
22851
22852@item show remoteaddresssize
22853Show the current value of remote address size in bits.
22854
0d12017b 22855@item set serial baud @var{n}
9c16f35a
EZ
22856@cindex baud rate for remote targets
22857Set the baud rate for the remote serial I/O to @var{n} baud. The
22858value is used to set the speed of the serial port used for debugging
22859remote targets.
22860
0d12017b 22861@item show serial baud
9c16f35a
EZ
22862Show the current speed of the remote connection.
22863
236af5e3
YG
22864@item set serial parity @var{parity}
22865Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22866@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22867
22868@item show serial parity
22869Show the current parity of the serial port.
22870
9c16f35a
EZ
22871@item set remotebreak
22872@cindex interrupt remote programs
22873@cindex BREAK signal instead of Ctrl-C
9a6253be 22874@anchor{set remotebreak}
9c16f35a 22875If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22876when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22877on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22878character instead. The default is off, since most remote systems
22879expect to see @samp{Ctrl-C} as the interrupt signal.
22880
22881@item show remotebreak
22882Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22883interrupt the remote program.
22884
23776285
MR
22885@item set remoteflow on
22886@itemx set remoteflow off
22887@kindex set remoteflow
22888Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22889on the serial port used to communicate to the remote target.
22890
22891@item show remoteflow
22892@kindex show remoteflow
22893Show the current setting of hardware flow control.
22894
9c16f35a
EZ
22895@item set remotelogbase @var{base}
22896Set the base (a.k.a.@: radix) of logging serial protocol
22897communications to @var{base}. Supported values of @var{base} are:
22898@code{ascii}, @code{octal}, and @code{hex}. The default is
22899@code{ascii}.
22900
22901@item show remotelogbase
22902Show the current setting of the radix for logging remote serial
22903protocol.
22904
22905@item set remotelogfile @var{file}
22906@cindex record serial communications on file
22907Record remote serial communications on the named @var{file}. The
22908default is not to record at all.
22909
2d8b6830 22910@item show remotelogfile
9c16f35a
EZ
22911Show the current setting of the file name on which to record the
22912serial communications.
22913
22914@item set remotetimeout @var{num}
22915@cindex timeout for serial communications
22916@cindex remote timeout
22917Set the timeout limit to wait for the remote target to respond to
22918@var{num} seconds. The default is 2 seconds.
22919
22920@item show remotetimeout
22921Show the current number of seconds to wait for the remote target
22922responses.
22923
22924@cindex limit hardware breakpoints and watchpoints
22925@cindex remote target, limit break- and watchpoints
501eef12
AC
22926@anchor{set remote hardware-watchpoint-limit}
22927@anchor{set remote hardware-breakpoint-limit}
22928@item set remote hardware-watchpoint-limit @var{limit}
22929@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22930Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22931or breakpoints. The @var{limit} can be set to 0 to disable hardware
22932watchpoints or breakpoints, and @code{unlimited} for unlimited
22933watchpoints or breakpoints.
22934
22935@item show remote hardware-watchpoint-limit
22936@itemx show remote hardware-breakpoint-limit
22937Show the current limit for the number of hardware watchpoints or
22938breakpoints that @value{GDBN} can use.
2d717e4f 22939
480a3f21
PW
22940@cindex limit hardware watchpoints length
22941@cindex remote target, limit watchpoints length
22942@anchor{set remote hardware-watchpoint-length-limit}
22943@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22944Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22945length of a remote hardware watchpoint. A @var{limit} of 0 disables
22946hardware watchpoints and @code{unlimited} allows watchpoints of any
22947length.
480a3f21
PW
22948
22949@item show remote hardware-watchpoint-length-limit
22950Show the current limit (in bytes) of the maximum length of
22951a remote hardware watchpoint.
22952
2d717e4f
DJ
22953@item set remote exec-file @var{filename}
22954@itemx show remote exec-file
22955@anchor{set remote exec-file}
22956@cindex executable file, for remote target
22957Select the file used for @code{run} with @code{target
22958extended-remote}. This should be set to a filename valid on the
22959target system. If it is not set, the target will use a default
22960filename (e.g.@: the last program run).
84603566 22961
9a7071a8
JB
22962@item set remote interrupt-sequence
22963@cindex interrupt remote programs
22964@cindex select Ctrl-C, BREAK or BREAK-g
22965Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22966@samp{BREAK-g} as the
22967sequence to the remote target in order to interrupt the execution.
22968@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22969is high level of serial line for some certain time.
22970Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22971It is @code{BREAK} signal followed by character @code{g}.
22972
22973@item show interrupt-sequence
22974Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22975is sent by @value{GDBN} to interrupt the remote program.
22976@code{BREAK-g} is BREAK signal followed by @code{g} and
22977also known as Magic SysRq g.
22978
22979@item set remote interrupt-on-connect
22980@cindex send interrupt-sequence on start
22981Specify whether interrupt-sequence is sent to remote target when
22982@value{GDBN} connects to it. This is mostly needed when you debug
22983Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22984which is known as Magic SysRq g in order to connect @value{GDBN}.
22985
22986@item show interrupt-on-connect
22987Show whether interrupt-sequence is sent
22988to remote target when @value{GDBN} connects to it.
22989
84603566
SL
22990@kindex set tcp
22991@kindex show tcp
22992@item set tcp auto-retry on
22993@cindex auto-retry, for remote TCP target
22994Enable auto-retry for remote TCP connections. This is useful if the remote
22995debugging agent is launched in parallel with @value{GDBN}; there is a race
22996condition because the agent may not become ready to accept the connection
22997before @value{GDBN} attempts to connect. When auto-retry is
22998enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22999to establish the connection using the timeout specified by
23000@code{set tcp connect-timeout}.
23001
23002@item set tcp auto-retry off
23003Do not auto-retry failed TCP connections.
23004
23005@item show tcp auto-retry
23006Show the current auto-retry setting.
23007
23008@item set tcp connect-timeout @var{seconds}
f81d1120 23009@itemx set tcp connect-timeout unlimited
84603566
SL
23010@cindex connection timeout, for remote TCP target
23011@cindex timeout, for remote target connection
23012Set the timeout for establishing a TCP connection to the remote target to
23013@var{seconds}. The timeout affects both polling to retry failed connections
23014(enabled by @code{set tcp auto-retry on}) and waiting for connections
23015that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
23016value. If @var{seconds} is @code{unlimited}, there is no timeout and
23017@value{GDBN} will keep attempting to establish a connection forever,
23018unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
23019
23020@item show tcp connect-timeout
23021Show the current connection timeout setting.
501eef12
AC
23022@end table
23023
427c3a89
DJ
23024@cindex remote packets, enabling and disabling
23025The @value{GDBN} remote protocol autodetects the packets supported by
23026your debugging stub. If you need to override the autodetection, you
23027can use these commands to enable or disable individual packets. Each
23028packet can be set to @samp{on} (the remote target supports this
23029packet), @samp{off} (the remote target does not support this packet),
23030or @samp{auto} (detect remote target support for this packet). They
23031all default to @samp{auto}. For more information about each packet,
23032see @ref{Remote Protocol}.
23033
23034During normal use, you should not have to use any of these commands.
23035If you do, that may be a bug in your remote debugging stub, or a bug
23036in @value{GDBN}. You may want to report the problem to the
23037@value{GDBN} developers.
23038
cfa9d6d9
DJ
23039For each packet @var{name}, the command to enable or disable the
23040packet is @code{set remote @var{name}-packet}. The available settings
23041are:
427c3a89 23042
cfa9d6d9 23043@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
23044@item Command Name
23045@tab Remote Packet
23046@tab Related Features
23047
cfa9d6d9 23048@item @code{fetch-register}
427c3a89
DJ
23049@tab @code{p}
23050@tab @code{info registers}
23051
cfa9d6d9 23052@item @code{set-register}
427c3a89
DJ
23053@tab @code{P}
23054@tab @code{set}
23055
cfa9d6d9 23056@item @code{binary-download}
427c3a89
DJ
23057@tab @code{X}
23058@tab @code{load}, @code{set}
23059
cfa9d6d9 23060@item @code{read-aux-vector}
427c3a89
DJ
23061@tab @code{qXfer:auxv:read}
23062@tab @code{info auxv}
23063
cfa9d6d9 23064@item @code{symbol-lookup}
427c3a89
DJ
23065@tab @code{qSymbol}
23066@tab Detecting multiple threads
23067
2d717e4f
DJ
23068@item @code{attach}
23069@tab @code{vAttach}
23070@tab @code{attach}
23071
cfa9d6d9 23072@item @code{verbose-resume}
427c3a89
DJ
23073@tab @code{vCont}
23074@tab Stepping or resuming multiple threads
23075
2d717e4f
DJ
23076@item @code{run}
23077@tab @code{vRun}
23078@tab @code{run}
23079
cfa9d6d9 23080@item @code{software-breakpoint}
427c3a89
DJ
23081@tab @code{Z0}
23082@tab @code{break}
23083
cfa9d6d9 23084@item @code{hardware-breakpoint}
427c3a89
DJ
23085@tab @code{Z1}
23086@tab @code{hbreak}
23087
cfa9d6d9 23088@item @code{write-watchpoint}
427c3a89
DJ
23089@tab @code{Z2}
23090@tab @code{watch}
23091
cfa9d6d9 23092@item @code{read-watchpoint}
427c3a89
DJ
23093@tab @code{Z3}
23094@tab @code{rwatch}
23095
cfa9d6d9 23096@item @code{access-watchpoint}
427c3a89
DJ
23097@tab @code{Z4}
23098@tab @code{awatch}
23099
c78fa86a
GB
23100@item @code{pid-to-exec-file}
23101@tab @code{qXfer:exec-file:read}
23102@tab @code{attach}, @code{run}
23103
cfa9d6d9
DJ
23104@item @code{target-features}
23105@tab @code{qXfer:features:read}
23106@tab @code{set architecture}
23107
23108@item @code{library-info}
23109@tab @code{qXfer:libraries:read}
23110@tab @code{info sharedlibrary}
23111
23112@item @code{memory-map}
23113@tab @code{qXfer:memory-map:read}
23114@tab @code{info mem}
23115
0fb4aa4b
PA
23116@item @code{read-sdata-object}
23117@tab @code{qXfer:sdata:read}
23118@tab @code{print $_sdata}
23119
4aa995e1
PA
23120@item @code{read-siginfo-object}
23121@tab @code{qXfer:siginfo:read}
23122@tab @code{print $_siginfo}
23123
23124@item @code{write-siginfo-object}
23125@tab @code{qXfer:siginfo:write}
23126@tab @code{set $_siginfo}
23127
dc146f7c
VP
23128@item @code{threads}
23129@tab @code{qXfer:threads:read}
23130@tab @code{info threads}
23131
cfa9d6d9 23132@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
23133@tab @code{qGetTLSAddr}
23134@tab Displaying @code{__thread} variables
23135
711e434b
PM
23136@item @code{get-thread-information-block-address}
23137@tab @code{qGetTIBAddr}
23138@tab Display MS-Windows Thread Information Block.
23139
08388c79
DE
23140@item @code{search-memory}
23141@tab @code{qSearch:memory}
23142@tab @code{find}
23143
427c3a89
DJ
23144@item @code{supported-packets}
23145@tab @code{qSupported}
23146@tab Remote communications parameters
23147
82075af2
JS
23148@item @code{catch-syscalls}
23149@tab @code{QCatchSyscalls}
23150@tab @code{catch syscall}
23151
cfa9d6d9 23152@item @code{pass-signals}
89be2091
DJ
23153@tab @code{QPassSignals}
23154@tab @code{handle @var{signal}}
23155
9b224c5e
PA
23156@item @code{program-signals}
23157@tab @code{QProgramSignals}
23158@tab @code{handle @var{signal}}
23159
a6b151f1
DJ
23160@item @code{hostio-close-packet}
23161@tab @code{vFile:close}
23162@tab @code{remote get}, @code{remote put}
23163
23164@item @code{hostio-open-packet}
23165@tab @code{vFile:open}
23166@tab @code{remote get}, @code{remote put}
23167
23168@item @code{hostio-pread-packet}
23169@tab @code{vFile:pread}
23170@tab @code{remote get}, @code{remote put}
23171
23172@item @code{hostio-pwrite-packet}
23173@tab @code{vFile:pwrite}
23174@tab @code{remote get}, @code{remote put}
23175
23176@item @code{hostio-unlink-packet}
23177@tab @code{vFile:unlink}
23178@tab @code{remote delete}
a6f3e723 23179
b9e7b9c3
UW
23180@item @code{hostio-readlink-packet}
23181@tab @code{vFile:readlink}
23182@tab Host I/O
23183
0a93529c
GB
23184@item @code{hostio-fstat-packet}
23185@tab @code{vFile:fstat}
23186@tab Host I/O
23187
15a201c8
GB
23188@item @code{hostio-setfs-packet}
23189@tab @code{vFile:setfs}
23190@tab Host I/O
23191
a6f3e723
SL
23192@item @code{noack-packet}
23193@tab @code{QStartNoAckMode}
23194@tab Packet acknowledgment
07e059b5
VP
23195
23196@item @code{osdata}
23197@tab @code{qXfer:osdata:read}
23198@tab @code{info os}
0b16c5cf
PA
23199
23200@item @code{query-attached}
23201@tab @code{qAttached}
23202@tab Querying remote process attach state.
b3b9301e 23203
a46c1e42
PA
23204@item @code{trace-buffer-size}
23205@tab @code{QTBuffer:size}
23206@tab @code{set trace-buffer-size}
23207
bd3eecc3
PA
23208@item @code{trace-status}
23209@tab @code{qTStatus}
23210@tab @code{tstatus}
23211
b3b9301e
PA
23212@item @code{traceframe-info}
23213@tab @code{qXfer:traceframe-info:read}
23214@tab Traceframe info
03583c20 23215
1e4d1764
YQ
23216@item @code{install-in-trace}
23217@tab @code{InstallInTrace}
23218@tab Install tracepoint in tracing
23219
03583c20
UW
23220@item @code{disable-randomization}
23221@tab @code{QDisableRandomization}
23222@tab @code{set disable-randomization}
83364271 23223
aefd8b33
SDJ
23224@item @code{startup-with-shell}
23225@tab @code{QStartupWithShell}
23226@tab @code{set startup-with-shell}
23227
0a2dde4a
SDJ
23228@item @code{environment-hex-encoded}
23229@tab @code{QEnvironmentHexEncoded}
23230@tab @code{set environment}
23231
23232@item @code{environment-unset}
23233@tab @code{QEnvironmentUnset}
23234@tab @code{unset environment}
23235
23236@item @code{environment-reset}
23237@tab @code{QEnvironmentReset}
23238@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23239
bc3b087d
SDJ
23240@item @code{set-working-dir}
23241@tab @code{QSetWorkingDir}
23242@tab @code{set cwd}
23243
83364271
LM
23244@item @code{conditional-breakpoints-packet}
23245@tab @code{Z0 and Z1}
23246@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 23247
73b8c1fd
PA
23248@item @code{multiprocess-extensions}
23249@tab @code{multiprocess extensions}
23250@tab Debug multiple processes and remote process PID awareness
23251
f7e6eed5
PA
23252@item @code{swbreak-feature}
23253@tab @code{swbreak stop reason}
23254@tab @code{break}
23255
23256@item @code{hwbreak-feature}
23257@tab @code{hwbreak stop reason}
23258@tab @code{hbreak}
23259
0d71eef5
DB
23260@item @code{fork-event-feature}
23261@tab @code{fork stop reason}
23262@tab @code{fork}
23263
23264@item @code{vfork-event-feature}
23265@tab @code{vfork stop reason}
23266@tab @code{vfork}
23267
b459a59b
DB
23268@item @code{exec-event-feature}
23269@tab @code{exec stop reason}
23270@tab @code{exec}
23271
65706a29
PA
23272@item @code{thread-events}
23273@tab @code{QThreadEvents}
23274@tab Tracking thread lifetime.
23275
f2faf941
PA
23276@item @code{no-resumed-stop-reply}
23277@tab @code{no resumed thread left stop reply}
23278@tab Tracking thread lifetime.
23279
427c3a89
DJ
23280@end multitable
23281
79a6e687
BW
23282@node Remote Stub
23283@section Implementing a Remote Stub
7a292a7a 23284
8e04817f
AC
23285@cindex debugging stub, example
23286@cindex remote stub, example
23287@cindex stub example, remote debugging
23288The stub files provided with @value{GDBN} implement the target side of the
23289communication protocol, and the @value{GDBN} side is implemented in the
23290@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23291these subroutines to communicate, and ignore the details. (If you're
23292implementing your own stub file, you can still ignore the details: start
23293with one of the existing stub files. @file{sparc-stub.c} is the best
23294organized, and therefore the easiest to read.)
23295
104c1213
JM
23296@cindex remote serial debugging, overview
23297To debug a program running on another machine (the debugging
23298@dfn{target} machine), you must first arrange for all the usual
23299prerequisites for the program to run by itself. For example, for a C
23300program, you need:
c906108c 23301
104c1213
JM
23302@enumerate
23303@item
23304A startup routine to set up the C runtime environment; these usually
23305have a name like @file{crt0}. The startup routine may be supplied by
23306your hardware supplier, or you may have to write your own.
96baa820 23307
5d161b24 23308@item
d4f3574e 23309A C subroutine library to support your program's
104c1213 23310subroutine calls, notably managing input and output.
96baa820 23311
104c1213
JM
23312@item
23313A way of getting your program to the other machine---for example, a
23314download program. These are often supplied by the hardware
23315manufacturer, but you may have to write your own from hardware
23316documentation.
23317@end enumerate
96baa820 23318
104c1213
JM
23319The next step is to arrange for your program to use a serial port to
23320communicate with the machine where @value{GDBN} is running (the @dfn{host}
23321machine). In general terms, the scheme looks like this:
96baa820 23322
104c1213
JM
23323@table @emph
23324@item On the host,
23325@value{GDBN} already understands how to use this protocol; when everything
23326else is set up, you can simply use the @samp{target remote} command
23327(@pxref{Targets,,Specifying a Debugging Target}).
23328
23329@item On the target,
23330you must link with your program a few special-purpose subroutines that
23331implement the @value{GDBN} remote serial protocol. The file containing these
23332subroutines is called a @dfn{debugging stub}.
23333
23334On certain remote targets, you can use an auxiliary program
23335@code{gdbserver} instead of linking a stub into your program.
79a6e687 23336@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23337@end table
96baa820 23338
104c1213
JM
23339The debugging stub is specific to the architecture of the remote
23340machine; for example, use @file{sparc-stub.c} to debug programs on
23341@sc{sparc} boards.
96baa820 23342
104c1213
JM
23343@cindex remote serial stub list
23344These working remote stubs are distributed with @value{GDBN}:
96baa820 23345
104c1213
JM
23346@table @code
23347
23348@item i386-stub.c
41afff9a 23349@cindex @file{i386-stub.c}
104c1213
JM
23350@cindex Intel
23351@cindex i386
23352For Intel 386 and compatible architectures.
23353
23354@item m68k-stub.c
41afff9a 23355@cindex @file{m68k-stub.c}
104c1213
JM
23356@cindex Motorola 680x0
23357@cindex m680x0
23358For Motorola 680x0 architectures.
23359
23360@item sh-stub.c
41afff9a 23361@cindex @file{sh-stub.c}
172c2a43 23362@cindex Renesas
104c1213 23363@cindex SH
172c2a43 23364For Renesas SH architectures.
104c1213
JM
23365
23366@item sparc-stub.c
41afff9a 23367@cindex @file{sparc-stub.c}
104c1213
JM
23368@cindex Sparc
23369For @sc{sparc} architectures.
23370
23371@item sparcl-stub.c
41afff9a 23372@cindex @file{sparcl-stub.c}
104c1213
JM
23373@cindex Fujitsu
23374@cindex SparcLite
23375For Fujitsu @sc{sparclite} architectures.
23376
23377@end table
23378
23379The @file{README} file in the @value{GDBN} distribution may list other
23380recently added stubs.
23381
23382@menu
23383* Stub Contents:: What the stub can do for you
23384* Bootstrapping:: What you must do for the stub
23385* Debug Session:: Putting it all together
104c1213
JM
23386@end menu
23387
6d2ebf8b 23388@node Stub Contents
79a6e687 23389@subsection What the Stub Can Do for You
104c1213
JM
23390
23391@cindex remote serial stub
23392The debugging stub for your architecture supplies these three
23393subroutines:
23394
23395@table @code
23396@item set_debug_traps
4644b6e3 23397@findex set_debug_traps
104c1213
JM
23398@cindex remote serial stub, initialization
23399This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23400program stops. You must call this subroutine explicitly in your
23401program's startup code.
104c1213
JM
23402
23403@item handle_exception
4644b6e3 23404@findex handle_exception
104c1213
JM
23405@cindex remote serial stub, main routine
23406This is the central workhorse, but your program never calls it
23407explicitly---the setup code arranges for @code{handle_exception} to
23408run when a trap is triggered.
23409
23410@code{handle_exception} takes control when your program stops during
23411execution (for example, on a breakpoint), and mediates communications
23412with @value{GDBN} on the host machine. This is where the communications
23413protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23414representative on the target machine. It begins by sending summary
104c1213
JM
23415information on the state of your program, then continues to execute,
23416retrieving and transmitting any information @value{GDBN} needs, until you
23417execute a @value{GDBN} command that makes your program resume; at that point,
23418@code{handle_exception} returns control to your own code on the target
5d161b24 23419machine.
104c1213
JM
23420
23421@item breakpoint
23422@cindex @code{breakpoint} subroutine, remote
23423Use this auxiliary subroutine to make your program contain a
23424breakpoint. Depending on the particular situation, this may be the only
23425way for @value{GDBN} to get control. For instance, if your target
23426machine has some sort of interrupt button, you won't need to call this;
23427pressing the interrupt button transfers control to
23428@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23429simply receiving characters on the serial port may also trigger a trap;
23430again, in that situation, you don't need to call @code{breakpoint} from
23431your own program---simply running @samp{target remote} from the host
5d161b24 23432@value{GDBN} session gets control.
104c1213
JM
23433
23434Call @code{breakpoint} if none of these is true, or if you simply want
23435to make certain your program stops at a predetermined point for the
23436start of your debugging session.
23437@end table
23438
6d2ebf8b 23439@node Bootstrapping
79a6e687 23440@subsection What You Must Do for the Stub
104c1213
JM
23441
23442@cindex remote stub, support routines
23443The debugging stubs that come with @value{GDBN} are set up for a particular
23444chip architecture, but they have no information about the rest of your
23445debugging target machine.
23446
23447First of all you need to tell the stub how to communicate with the
23448serial port.
23449
23450@table @code
23451@item int getDebugChar()
4644b6e3 23452@findex getDebugChar
104c1213
JM
23453Write this subroutine to read a single character from the serial port.
23454It may be identical to @code{getchar} for your target system; a
23455different name is used to allow you to distinguish the two if you wish.
23456
23457@item void putDebugChar(int)
4644b6e3 23458@findex putDebugChar
104c1213 23459Write this subroutine to write a single character to the serial port.
5d161b24 23460It may be identical to @code{putchar} for your target system; a
104c1213
JM
23461different name is used to allow you to distinguish the two if you wish.
23462@end table
23463
23464@cindex control C, and remote debugging
23465@cindex interrupting remote targets
23466If you want @value{GDBN} to be able to stop your program while it is
23467running, you need to use an interrupt-driven serial driver, and arrange
23468for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23469character). That is the character which @value{GDBN} uses to tell the
23470remote system to stop.
23471
23472Getting the debugging target to return the proper status to @value{GDBN}
23473probably requires changes to the standard stub; one quick and dirty way
23474is to just execute a breakpoint instruction (the ``dirty'' part is that
23475@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23476
23477Other routines you need to supply are:
23478
23479@table @code
23480@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23481@findex exceptionHandler
104c1213
JM
23482Write this function to install @var{exception_address} in the exception
23483handling tables. You need to do this because the stub does not have any
23484way of knowing what the exception handling tables on your target system
23485are like (for example, the processor's table might be in @sc{rom},
23486containing entries which point to a table in @sc{ram}).
697aa1b7 23487The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23488its meaning is architecture-dependent (for example, different numbers
23489might represent divide by zero, misaligned access, etc). When this
23490exception occurs, control should be transferred directly to
23491@var{exception_address}, and the processor state (stack, registers,
23492and so on) should be just as it is when a processor exception occurs. So if
23493you want to use a jump instruction to reach @var{exception_address}, it
23494should be a simple jump, not a jump to subroutine.
23495
23496For the 386, @var{exception_address} should be installed as an interrupt
23497gate so that interrupts are masked while the handler runs. The gate
23498should be at privilege level 0 (the most privileged level). The
23499@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23500help from @code{exceptionHandler}.
23501
23502@item void flush_i_cache()
4644b6e3 23503@findex flush_i_cache
d4f3574e 23504On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23505instruction cache, if any, on your target machine. If there is no
23506instruction cache, this subroutine may be a no-op.
23507
23508On target machines that have instruction caches, @value{GDBN} requires this
23509function to make certain that the state of your program is stable.
23510@end table
23511
23512@noindent
23513You must also make sure this library routine is available:
23514
23515@table @code
23516@item void *memset(void *, int, int)
4644b6e3 23517@findex memset
104c1213
JM
23518This is the standard library function @code{memset} that sets an area of
23519memory to a known value. If you have one of the free versions of
23520@code{libc.a}, @code{memset} can be found there; otherwise, you must
23521either obtain it from your hardware manufacturer, or write your own.
23522@end table
23523
23524If you do not use the GNU C compiler, you may need other standard
23525library subroutines as well; this varies from one stub to another,
23526but in general the stubs are likely to use any of the common library
e22ea452 23527subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23528
23529
6d2ebf8b 23530@node Debug Session
79a6e687 23531@subsection Putting it All Together
104c1213
JM
23532
23533@cindex remote serial debugging summary
23534In summary, when your program is ready to debug, you must follow these
23535steps.
23536
23537@enumerate
23538@item
6d2ebf8b 23539Make sure you have defined the supporting low-level routines
79a6e687 23540(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23541@display
23542@code{getDebugChar}, @code{putDebugChar},
23543@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23544@end display
23545
23546@item
2fb860fc
PA
23547Insert these lines in your program's startup code, before the main
23548procedure is called:
104c1213 23549
474c8240 23550@smallexample
104c1213
JM
23551set_debug_traps();
23552breakpoint();
474c8240 23553@end smallexample
104c1213 23554
2fb860fc
PA
23555On some machines, when a breakpoint trap is raised, the hardware
23556automatically makes the PC point to the instruction after the
23557breakpoint. If your machine doesn't do that, you may need to adjust
23558@code{handle_exception} to arrange for it to return to the instruction
23559after the breakpoint on this first invocation, so that your program
23560doesn't keep hitting the initial breakpoint instead of making
23561progress.
23562
104c1213
JM
23563@item
23564For the 680x0 stub only, you need to provide a variable called
23565@code{exceptionHook}. Normally you just use:
23566
474c8240 23567@smallexample
104c1213 23568void (*exceptionHook)() = 0;
474c8240 23569@end smallexample
104c1213 23570
d4f3574e 23571@noindent
104c1213 23572but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23573function in your program, that function is called when
104c1213
JM
23574@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23575error). The function indicated by @code{exceptionHook} is called with
23576one parameter: an @code{int} which is the exception number.
23577
23578@item
23579Compile and link together: your program, the @value{GDBN} debugging stub for
23580your target architecture, and the supporting subroutines.
23581
23582@item
23583Make sure you have a serial connection between your target machine and
23584the @value{GDBN} host, and identify the serial port on the host.
23585
23586@item
23587@c The "remote" target now provides a `load' command, so we should
23588@c document that. FIXME.
23589Download your program to your target machine (or get it there by
23590whatever means the manufacturer provides), and start it.
23591
23592@item
07f31aa6 23593Start @value{GDBN} on the host, and connect to the target
79a6e687 23594(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23595
104c1213
JM
23596@end enumerate
23597
8e04817f
AC
23598@node Configurations
23599@chapter Configuration-Specific Information
104c1213 23600
8e04817f
AC
23601While nearly all @value{GDBN} commands are available for all native and
23602cross versions of the debugger, there are some exceptions. This chapter
23603describes things that are only available in certain configurations.
104c1213 23604
8e04817f
AC
23605There are three major categories of configurations: native
23606configurations, where the host and target are the same, embedded
23607operating system configurations, which are usually the same for several
23608different processor architectures, and bare embedded processors, which
23609are quite different from each other.
104c1213 23610
8e04817f
AC
23611@menu
23612* Native::
23613* Embedded OS::
23614* Embedded Processors::
23615* Architectures::
23616@end menu
104c1213 23617
8e04817f
AC
23618@node Native
23619@section Native
104c1213 23620
8e04817f
AC
23621This section describes details specific to particular native
23622configurations.
6cf7e474 23623
8e04817f 23624@menu
7561d450 23625* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23626* Process Information:: Process information
8e04817f 23627* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23628* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23629* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23630* Darwin:: Features specific to Darwin
e9076973 23631* FreeBSD:: Features specific to FreeBSD
8e04817f 23632@end menu
6cf7e474 23633
7561d450
MK
23634@node BSD libkvm Interface
23635@subsection BSD libkvm Interface
23636
23637@cindex libkvm
23638@cindex kernel memory image
23639@cindex kernel crash dump
23640
23641BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23642interface that provides a uniform interface for accessing kernel virtual
23643memory images, including live systems and crash dumps. @value{GDBN}
23644uses this interface to allow you to debug live kernels and kernel crash
23645dumps on many native BSD configurations. This is implemented as a
23646special @code{kvm} debugging target. For debugging a live system, load
23647the currently running kernel into @value{GDBN} and connect to the
23648@code{kvm} target:
23649
23650@smallexample
23651(@value{GDBP}) @b{target kvm}
23652@end smallexample
23653
23654For debugging crash dumps, provide the file name of the crash dump as an
23655argument:
23656
23657@smallexample
23658(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23659@end smallexample
23660
23661Once connected to the @code{kvm} target, the following commands are
23662available:
23663
23664@table @code
23665@kindex kvm
23666@item kvm pcb
721c2651 23667Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23668
23669@item kvm proc
23670Set current context from proc address. This command isn't available on
23671modern FreeBSD systems.
23672@end table
23673
2d97a5d9
JB
23674@node Process Information
23675@subsection Process Information
60bf7e09
EZ
23676@cindex /proc
23677@cindex examine process image
23678@cindex process info via @file{/proc}
104c1213 23679
2d97a5d9
JB
23680Some operating systems provide interfaces to fetch additional
23681information about running processes beyond memory and per-thread
23682register state. If @value{GDBN} is configured for an operating system
23683with a supported interface, the command @code{info proc} is available
23684to report information about the process running your program, or about
23685any process running on your system.
451b7c33 23686
2d97a5d9
JB
23687One supported interface is a facility called @samp{/proc} that can be
23688used to examine the image of a running process using file-system
23689subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23690systems.
451b7c33 23691
aa8509b4
KR
23692On FreeBSD and NetBSD systems, system control nodes are used to query
23693process information.
2d97a5d9
JB
23694
23695In addition, some systems may provide additional process information
23696in core files. Note that a core file may include a subset of the
23697information available from a live process. Process information is
6b92c0d3 23698currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23699systems.
104c1213 23700
8e04817f
AC
23701@table @code
23702@kindex info proc
60bf7e09 23703@cindex process ID
8e04817f 23704@item info proc
60bf7e09 23705@itemx info proc @var{process-id}
73f1bd76 23706Summarize available information about a process. If a
60bf7e09
EZ
23707process ID is specified by @var{process-id}, display information about
23708that process; otherwise display information about the program being
23709debugged. The summary includes the debugged process ID, the command
23710line used to invoke it, its current working directory, and its
23711executable file's absolute file name.
23712
23713On some systems, @var{process-id} can be of the form
23714@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23715within a process. If the optional @var{pid} part is missing, it means
23716a thread from the process being debugged (the leading @samp{/} still
23717needs to be present, or else @value{GDBN} will interpret the number as
23718a process ID rather than a thread ID).
6cf7e474 23719
0c631110
TT
23720@item info proc cmdline
23721@cindex info proc cmdline
23722Show the original command line of the process. This command is
aa8509b4 23723supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23724
23725@item info proc cwd
23726@cindex info proc cwd
23727Show the current working directory of the process. This command is
aa8509b4 23728supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23729
23730@item info proc exe
23731@cindex info proc exe
2d97a5d9 23732Show the name of executable of the process. This command is supported
aa8509b4 23733on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110 23734
8b113111
JB
23735@item info proc files
23736@cindex info proc files
23737Show the file descriptors open by the process. For each open file
23738descriptor, @value{GDBN} shows its number, type (file, directory,
23739character device, socket), file pointer offset, and the name of the
23740resource open on the descriptor. The resource name can be a file name
23741(for files, directories, and devices) or a protocol followed by socket
23742address (for network connections). This command is supported on
23743FreeBSD.
23744
23745This example shows the open file descriptors for a process using a
23746tty for standard input and output as well as two network sockets:
23747
23748@smallexample
23749(gdb) info proc files 22136
23750process 22136
23751Open files:
23752
23753 FD Type Offset Flags Name
23754 text file - r-------- /usr/bin/ssh
23755 ctty chr - rw------- /dev/pts/20
23756 cwd dir - r-------- /usr/home/john
23757 root dir - r-------- /
23758 0 chr 0x32933a4 rw------- /dev/pts/20
23759 1 chr 0x32933a4 rw------- /dev/pts/20
23760 2 chr 0x32933a4 rw------- /dev/pts/20
23761 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23762 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23763@end smallexample
23764
8e04817f 23765@item info proc mappings
60bf7e09 23766@cindex memory address space mappings
73f1bd76 23767Report the memory address space ranges accessible in a process. On
aa8509b4
KR
23768Solaris, FreeBSD and NetBSD systems, each memory range includes information
23769on whether the process has read, write, or execute access rights to each
23770range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
2d97a5d9 23771includes the object file which is mapped to that range.
60bf7e09
EZ
23772
23773@item info proc stat
23774@itemx info proc status
23775@cindex process detailed status information
2d97a5d9
JB
23776Show additional process-related information, including the user ID and
23777group ID; virtual memory usage; the signals that are pending, blocked,
23778and ignored; its TTY; its consumption of system and user time; its
23779stack size; its @samp{nice} value; etc. These commands are supported
aa8509b4 23780on @sc{gnu}/Linux, FreeBSD and NetBSD.
2d97a5d9
JB
23781
23782For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23783information (type @kbd{man 5 proc} from your shell prompt).
23784
aa8509b4
KR
23785For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23786@code{info proc status}.
60bf7e09
EZ
23787
23788@item info proc all
23789Show all the information about the process described under all of the
23790above @code{info proc} subcommands.
23791
8e04817f
AC
23792@ignore
23793@comment These sub-options of 'info proc' were not included when
23794@comment procfs.c was re-written. Keep their descriptions around
23795@comment against the day when someone finds the time to put them back in.
23796@kindex info proc times
23797@item info proc times
23798Starting time, user CPU time, and system CPU time for your program and
23799its children.
6cf7e474 23800
8e04817f
AC
23801@kindex info proc id
23802@item info proc id
23803Report on the process IDs related to your program: its own process ID,
23804the ID of its parent, the process group ID, and the session ID.
8e04817f 23805@end ignore
721c2651
EZ
23806
23807@item set procfs-trace
23808@kindex set procfs-trace
23809@cindex @code{procfs} API calls
23810This command enables and disables tracing of @code{procfs} API calls.
23811
23812@item show procfs-trace
23813@kindex show procfs-trace
23814Show the current state of @code{procfs} API call tracing.
23815
23816@item set procfs-file @var{file}
23817@kindex set procfs-file
23818Tell @value{GDBN} to write @code{procfs} API trace to the named
23819@var{file}. @value{GDBN} appends the trace info to the previous
23820contents of the file. The default is to display the trace on the
23821standard output.
23822
23823@item show procfs-file
23824@kindex show procfs-file
23825Show the file to which @code{procfs} API trace is written.
23826
23827@item proc-trace-entry
23828@itemx proc-trace-exit
23829@itemx proc-untrace-entry
23830@itemx proc-untrace-exit
23831@kindex proc-trace-entry
23832@kindex proc-trace-exit
23833@kindex proc-untrace-entry
23834@kindex proc-untrace-exit
23835These commands enable and disable tracing of entries into and exits
23836from the @code{syscall} interface.
23837
23838@item info pidlist
23839@kindex info pidlist
23840@cindex process list, QNX Neutrino
23841For QNX Neutrino only, this command displays the list of all the
23842processes and all the threads within each process.
23843
23844@item info meminfo
23845@kindex info meminfo
23846@cindex mapinfo list, QNX Neutrino
23847For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23848@end table
104c1213 23849
8e04817f
AC
23850@node DJGPP Native
23851@subsection Features for Debugging @sc{djgpp} Programs
23852@cindex @sc{djgpp} debugging
23853@cindex native @sc{djgpp} debugging
23854@cindex MS-DOS-specific commands
104c1213 23855
514c4d71
EZ
23856@cindex DPMI
23857@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23858MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23859that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23860top of real-mode DOS systems and their emulations.
104c1213 23861
8e04817f
AC
23862@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23863defines a few commands specific to the @sc{djgpp} port. This
23864subsection describes those commands.
104c1213 23865
8e04817f
AC
23866@table @code
23867@kindex info dos
23868@item info dos
23869This is a prefix of @sc{djgpp}-specific commands which print
23870information about the target system and important OS structures.
f1251bdd 23871
8e04817f
AC
23872@kindex sysinfo
23873@cindex MS-DOS system info
23874@cindex free memory information (MS-DOS)
23875@item info dos sysinfo
23876This command displays assorted information about the underlying
23877platform: the CPU type and features, the OS version and flavor, the
23878DPMI version, and the available conventional and DPMI memory.
104c1213 23879
8e04817f
AC
23880@cindex GDT
23881@cindex LDT
23882@cindex IDT
23883@cindex segment descriptor tables
23884@cindex descriptor tables display
23885@item info dos gdt
23886@itemx info dos ldt
23887@itemx info dos idt
23888These 3 commands display entries from, respectively, Global, Local,
23889and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23890tables are data structures which store a descriptor for each segment
23891that is currently in use. The segment's selector is an index into a
23892descriptor table; the table entry for that index holds the
23893descriptor's base address and limit, and its attributes and access
23894rights.
104c1213 23895
8e04817f
AC
23896A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23897segment (used for both data and the stack), and a DOS segment (which
23898allows access to DOS/BIOS data structures and absolute addresses in
23899conventional memory). However, the DPMI host will usually define
23900additional segments in order to support the DPMI environment.
d4f3574e 23901
8e04817f
AC
23902@cindex garbled pointers
23903These commands allow to display entries from the descriptor tables.
23904Without an argument, all entries from the specified table are
23905displayed. An argument, which should be an integer expression, means
23906display a single entry whose index is given by the argument. For
23907example, here's a convenient way to display information about the
23908debugged program's data segment:
104c1213 23909
8e04817f
AC
23910@smallexample
23911@exdent @code{(@value{GDBP}) info dos ldt $ds}
23912@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23913@end smallexample
104c1213 23914
8e04817f
AC
23915@noindent
23916This comes in handy when you want to see whether a pointer is outside
23917the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23918
8e04817f
AC
23919@cindex page tables display (MS-DOS)
23920@item info dos pde
23921@itemx info dos pte
23922These two commands display entries from, respectively, the Page
23923Directory and the Page Tables. Page Directories and Page Tables are
23924data structures which control how virtual memory addresses are mapped
23925into physical addresses. A Page Table includes an entry for every
23926page of memory that is mapped into the program's address space; there
23927may be several Page Tables, each one holding up to 4096 entries. A
23928Page Directory has up to 4096 entries, one each for every Page Table
23929that is currently in use.
104c1213 23930
8e04817f
AC
23931Without an argument, @kbd{info dos pde} displays the entire Page
23932Directory, and @kbd{info dos pte} displays all the entries in all of
23933the Page Tables. An argument, an integer expression, given to the
23934@kbd{info dos pde} command means display only that entry from the Page
23935Directory table. An argument given to the @kbd{info dos pte} command
23936means display entries from a single Page Table, the one pointed to by
23937the specified entry in the Page Directory.
104c1213 23938
8e04817f
AC
23939@cindex direct memory access (DMA) on MS-DOS
23940These commands are useful when your program uses @dfn{DMA} (Direct
23941Memory Access), which needs physical addresses to program the DMA
23942controller.
104c1213 23943
8e04817f 23944These commands are supported only with some DPMI servers.
104c1213 23945
8e04817f
AC
23946@cindex physical address from linear address
23947@item info dos address-pte @var{addr}
23948This command displays the Page Table entry for a specified linear
514c4d71
EZ
23949address. The argument @var{addr} is a linear address which should
23950already have the appropriate segment's base address added to it,
23951because this command accepts addresses which may belong to @emph{any}
23952segment. For example, here's how to display the Page Table entry for
23953the page where a variable @code{i} is stored:
104c1213 23954
b383017d 23955@smallexample
8e04817f
AC
23956@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23957@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23958@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23959@end smallexample
104c1213 23960
8e04817f
AC
23961@noindent
23962This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23963whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23964attributes of that page.
104c1213 23965
8e04817f
AC
23966Note that you must cast the addresses of variables to a @code{char *},
23967since otherwise the value of @code{__djgpp_base_address}, the base
23968address of all variables and functions in a @sc{djgpp} program, will
23969be added using the rules of C pointer arithmetics: if @code{i} is
23970declared an @code{int}, @value{GDBN} will add 4 times the value of
23971@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23972
8e04817f
AC
23973Here's another example, it displays the Page Table entry for the
23974transfer buffer:
104c1213 23975
8e04817f
AC
23976@smallexample
23977@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23978@exdent @code{Page Table entry for address 0x29110:}
23979@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23980@end smallexample
104c1213 23981
8e04817f
AC
23982@noindent
23983(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
239843rd member of the @code{_go32_info_block} structure.) The output
23985clearly shows that this DPMI server maps the addresses in conventional
23986memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23987linear (@code{0x29110}) addresses are identical.
104c1213 23988
8e04817f
AC
23989This command is supported only with some DPMI servers.
23990@end table
104c1213 23991
c45da7e6 23992@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23993In addition to native debugging, the DJGPP port supports remote
23994debugging via a serial data link. The following commands are specific
23995to remote serial debugging in the DJGPP port of @value{GDBN}.
23996
23997@table @code
23998@kindex set com1base
23999@kindex set com1irq
24000@kindex set com2base
24001@kindex set com2irq
24002@kindex set com3base
24003@kindex set com3irq
24004@kindex set com4base
24005@kindex set com4irq
24006@item set com1base @var{addr}
24007This command sets the base I/O port address of the @file{COM1} serial
24008port.
24009
24010@item set com1irq @var{irq}
24011This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24012for the @file{COM1} serial port.
24013
24014There are similar commands @samp{set com2base}, @samp{set com3irq},
24015etc.@: for setting the port address and the @code{IRQ} lines for the
24016other 3 COM ports.
24017
24018@kindex show com1base
24019@kindex show com1irq
24020@kindex show com2base
24021@kindex show com2irq
24022@kindex show com3base
24023@kindex show com3irq
24024@kindex show com4base
24025@kindex show com4irq
24026The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24027display the current settings of the base address and the @code{IRQ}
24028lines used by the COM ports.
c45da7e6
EZ
24029
24030@item info serial
24031@kindex info serial
24032@cindex DOS serial port status
24033This command prints the status of the 4 DOS serial ports. For each
24034port, it prints whether it's active or not, its I/O base address and
24035IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24036counts of various errors encountered so far.
a8f24a35
EZ
24037@end table
24038
24039
78c47bea 24040@node Cygwin Native
79a6e687 24041@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
24042@cindex MS Windows debugging
24043@cindex native Cygwin debugging
24044@cindex Cygwin-specific commands
24045
be448670 24046@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
24047DLLs with and without symbolic debugging information.
24048
24049@cindex Ctrl-BREAK, MS-Windows
24050@cindex interrupt debuggee on MS-Windows
24051MS-Windows programs that call @code{SetConsoleMode} to switch off the
24052special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24053by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24054supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24055sequence, which can be used to interrupt the debuggee even if it
24056ignores @kbd{C-c}.
24057
24058There are various additional Cygwin-specific commands, described in
24059this section. Working with DLLs that have no debugging symbols is
24060described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
24061
24062@table @code
24063@kindex info w32
24064@item info w32
db2e3e2e 24065This is a prefix of MS Windows-specific commands which print
78c47bea
PM
24066information about the target system and important OS structures.
24067
24068@item info w32 selector
24069This command displays information returned by
24070the Win32 API @code{GetThreadSelectorEntry} function.
24071It takes an optional argument that is evaluated to
24072a long value to give the information about this given selector.
24073Without argument, this command displays information
d3e8051b 24074about the six segment registers.
78c47bea 24075
711e434b
PM
24076@item info w32 thread-information-block
24077This command displays thread specific information stored in the
24078Thread Information Block (readable on the X86 CPU family using @code{$fs}
24079selector for 32-bit programs and @code{$gs} for 64-bit programs).
24080
463888ab
РИ
24081@kindex signal-event
24082@item signal-event @var{id}
24083This command signals an event with user-provided @var{id}. Used to resume
24084crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24085
24086To use it, create or edit the following keys in
24087@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24088@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24089(for x86_64 versions):
24090
24091@itemize @minus
24092@item
24093@code{Debugger} (REG_SZ) --- a command to launch the debugger.
24094Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24095"attach %ld" -ex "signal-event %ld" -ex "continue"}.
24096
24097The first @code{%ld} will be replaced by the process ID of the
24098crashing process, the second @code{%ld} will be replaced by the ID of
24099the event that blocks the crashing process, waiting for @value{GDBN}
24100to attach.
24101
24102@item
24103@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24104make the system run debugger specified by the Debugger key
24105automatically, @code{0} will cause a dialog box with ``OK'' and
24106``Cancel'' buttons to appear, which allows the user to either
24107terminate the crashing process (OK) or debug it (Cancel).
24108@end itemize
24109
be90c084 24110@kindex set cygwin-exceptions
e16b02ee
EZ
24111@cindex debugging the Cygwin DLL
24112@cindex Cygwin DLL, debugging
be90c084 24113@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
24114If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24115happen inside the Cygwin DLL. If @var{mode} is @code{off},
24116@value{GDBN} will delay recognition of exceptions, and may ignore some
24117exceptions which seem to be caused by internal Cygwin DLL
24118``bookkeeping''. This option is meant primarily for debugging the
24119Cygwin DLL itself; the default value is @code{off} to avoid annoying
24120@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
24121
24122@kindex show cygwin-exceptions
24123@item show cygwin-exceptions
e16b02ee
EZ
24124Displays whether @value{GDBN} will break on exceptions that happen
24125inside the Cygwin DLL itself.
be90c084 24126
b383017d 24127@kindex set new-console
78c47bea 24128@item set new-console @var{mode}
b383017d 24129If @var{mode} is @code{on} the debuggee will
78c47bea 24130be started in a new console on next start.
e03e5e7b 24131If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
24132be started in the same console as the debugger.
24133
24134@kindex show new-console
24135@item show new-console
24136Displays whether a new console is used
24137when the debuggee is started.
24138
24139@kindex set new-group
24140@item set new-group @var{mode}
24141This boolean value controls whether the debuggee should
24142start a new group or stay in the same group as the debugger.
24143This affects the way the Windows OS handles
c8aa23ab 24144@samp{Ctrl-C}.
78c47bea
PM
24145
24146@kindex show new-group
24147@item show new-group
24148Displays current value of new-group boolean.
24149
24150@kindex set debugevents
24151@item set debugevents
219eec71
EZ
24152This boolean value adds debug output concerning kernel events related
24153to the debuggee seen by the debugger. This includes events that
24154signal thread and process creation and exit, DLL loading and
24155unloading, console interrupts, and debugging messages produced by the
24156Windows @code{OutputDebugString} API call.
78c47bea
PM
24157
24158@kindex set debugexec
24159@item set debugexec
b383017d 24160This boolean value adds debug output concerning execute events
219eec71 24161(such as resume thread) seen by the debugger.
78c47bea
PM
24162
24163@kindex set debugexceptions
24164@item set debugexceptions
219eec71
EZ
24165This boolean value adds debug output concerning exceptions in the
24166debuggee seen by the debugger.
78c47bea
PM
24167
24168@kindex set debugmemory
24169@item set debugmemory
219eec71
EZ
24170This boolean value adds debug output concerning debuggee memory reads
24171and writes by the debugger.
78c47bea
PM
24172
24173@kindex set shell
24174@item set shell
24175This boolean values specifies whether the debuggee is called
24176via a shell or directly (default value is on).
24177
24178@kindex show shell
24179@item show shell
24180Displays if the debuggee will be started with a shell.
24181
24182@end table
24183
be448670 24184@menu
79a6e687 24185* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
24186@end menu
24187
79a6e687
BW
24188@node Non-debug DLL Symbols
24189@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
24190@cindex DLLs with no debugging symbols
24191@cindex Minimal symbols and DLLs
24192
24193Very often on windows, some of the DLLs that your program relies on do
24194not include symbolic debugging information (for example,
db2e3e2e 24195@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 24196symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 24197information contained in the DLL's export table. This section
be448670
CF
24198describes working with such symbols, known internally to @value{GDBN} as
24199``minimal symbols''.
24200
24201Note that before the debugged program has started execution, no DLLs
db2e3e2e 24202will have been loaded. The easiest way around this problem is simply to
be448670 24203start the program --- either by setting a breakpoint or letting the
95060284 24204program run once to completion.
be448670 24205
79a6e687 24206@subsubsection DLL Name Prefixes
be448670
CF
24207
24208In keeping with the naming conventions used by the Microsoft debugging
24209tools, DLL export symbols are made available with a prefix based on the
24210DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24211also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 24212sufficient. In some cases there will be name clashes within a program
be448670
CF
24213(particularly if the executable itself includes full debugging symbols)
24214necessitating the use of the fully qualified name when referring to the
99e008fe 24215contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
24216exclamation mark (``!'') being interpreted as a language operator.
24217
24218Note that the internal name of the DLL may be all upper-case, even
99e008fe 24219though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
24220symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24221some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
24222@code{info variables} commands or even @code{maint print msymbols}
24223(@pxref{Symbols}). Here's an example:
be448670
CF
24224
24225@smallexample
f7dc1244 24226(@value{GDBP}) info function CreateFileA
be448670
CF
24227All functions matching regular expression "CreateFileA":
24228
24229Non-debugging symbols:
242300x77e885f4 CreateFileA
242310x77e885f4 KERNEL32!CreateFileA
24232@end smallexample
24233
24234@smallexample
f7dc1244 24235(@value{GDBP}) info function !
be448670
CF
24236All functions matching regular expression "!":
24237
24238Non-debugging symbols:
242390x6100114c cygwin1!__assert
242400x61004034 cygwin1!_dll_crt0@@0
242410x61004240 cygwin1!dll_crt0(per_process *)
24242[etc...]
24243@end smallexample
24244
79a6e687 24245@subsubsection Working with Minimal Symbols
be448670
CF
24246
24247Symbols extracted from a DLL's export table do not contain very much
24248type information. All that @value{GDBN} can do is guess whether a symbol
24249refers to a function or variable depending on the linker section that
24250contains the symbol. Also note that the actual contents of the memory
24251contained in a DLL are not available unless the program is running. This
24252means that you cannot examine the contents of a variable or disassemble
24253a function within a DLL without a running program.
24254
24255Variables are generally treated as pointers and dereferenced
24256automatically. For this reason, it is often necessary to prefix a
24257variable name with the address-of operator (``&'') and provide explicit
24258type information in the command. Here's an example of the type of
24259problem:
24260
24261@smallexample
f7dc1244 24262(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 24263'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24264@end smallexample
24265
24266@smallexample
f7dc1244 24267(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 24268'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24269@end smallexample
24270
24271And two possible solutions:
24272
24273@smallexample
f7dc1244 24274(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
24275$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24276@end smallexample
24277
24278@smallexample
f7dc1244 24279(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 242800x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 24281(@value{GDBP}) x/x 0x10021608
be448670 242820x10021608: 0x0022fd98
f7dc1244 24283(@value{GDBP}) x/s 0x0022fd98
be448670
CF
242840x22fd98: "/cygdrive/c/mydirectory/myprogram"
24285@end smallexample
24286
24287Setting a break point within a DLL is possible even before the program
24288starts execution. However, under these circumstances, @value{GDBN} can't
24289examine the initial instructions of the function in order to skip the
24290function's frame set-up code. You can work around this by using ``*&''
24291to set the breakpoint at a raw memory address:
24292
24293@smallexample
f7dc1244 24294(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
24295Breakpoint 1 at 0x1e04eff0
24296@end smallexample
24297
24298The author of these extensions is not entirely convinced that setting a
24299break point within a shared DLL like @file{kernel32.dll} is completely
24300safe.
24301
14d6dd68 24302@node Hurd Native
79a6e687 24303@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
24304@cindex @sc{gnu} Hurd debugging
24305
24306This subsection describes @value{GDBN} commands specific to the
24307@sc{gnu} Hurd native debugging.
24308
24309@table @code
24310@item set signals
24311@itemx set sigs
24312@kindex set signals@r{, Hurd command}
24313@kindex set sigs@r{, Hurd command}
24314This command toggles the state of inferior signal interception by
24315@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24316affected by this command. @code{sigs} is a shorthand alias for
24317@code{signals}.
24318
24319@item show signals
24320@itemx show sigs
24321@kindex show signals@r{, Hurd command}
24322@kindex show sigs@r{, Hurd command}
24323Show the current state of intercepting inferior's signals.
24324
24325@item set signal-thread
24326@itemx set sigthread
24327@kindex set signal-thread
24328@kindex set sigthread
24329This command tells @value{GDBN} which thread is the @code{libc} signal
24330thread. That thread is run when a signal is delivered to a running
24331process. @code{set sigthread} is the shorthand alias of @code{set
24332signal-thread}.
24333
24334@item show signal-thread
24335@itemx show sigthread
24336@kindex show signal-thread
24337@kindex show sigthread
24338These two commands show which thread will run when the inferior is
24339delivered a signal.
24340
24341@item set stopped
24342@kindex set stopped@r{, Hurd command}
24343This commands tells @value{GDBN} that the inferior process is stopped,
24344as with the @code{SIGSTOP} signal. The stopped process can be
24345continued by delivering a signal to it.
24346
24347@item show stopped
24348@kindex show stopped@r{, Hurd command}
24349This command shows whether @value{GDBN} thinks the debuggee is
24350stopped.
24351
24352@item set exceptions
24353@kindex set exceptions@r{, Hurd command}
24354Use this command to turn off trapping of exceptions in the inferior.
24355When exception trapping is off, neither breakpoints nor
24356single-stepping will work. To restore the default, set exception
24357trapping on.
24358
24359@item show exceptions
24360@kindex show exceptions@r{, Hurd command}
24361Show the current state of trapping exceptions in the inferior.
24362
24363@item set task pause
24364@kindex set task@r{, Hurd commands}
24365@cindex task attributes (@sc{gnu} Hurd)
24366@cindex pause current task (@sc{gnu} Hurd)
24367This command toggles task suspension when @value{GDBN} has control.
24368Setting it to on takes effect immediately, and the task is suspended
24369whenever @value{GDBN} gets control. Setting it to off will take
24370effect the next time the inferior is continued. If this option is set
24371to off, you can use @code{set thread default pause on} or @code{set
24372thread pause on} (see below) to pause individual threads.
24373
24374@item show task pause
24375@kindex show task@r{, Hurd commands}
24376Show the current state of task suspension.
24377
24378@item set task detach-suspend-count
24379@cindex task suspend count
24380@cindex detach from task, @sc{gnu} Hurd
24381This command sets the suspend count the task will be left with when
24382@value{GDBN} detaches from it.
24383
24384@item show task detach-suspend-count
24385Show the suspend count the task will be left with when detaching.
24386
24387@item set task exception-port
24388@itemx set task excp
24389@cindex task exception port, @sc{gnu} Hurd
24390This command sets the task exception port to which @value{GDBN} will
24391forward exceptions. The argument should be the value of the @dfn{send
24392rights} of the task. @code{set task excp} is a shorthand alias.
24393
24394@item set noninvasive
24395@cindex noninvasive task options
24396This command switches @value{GDBN} to a mode that is the least
24397invasive as far as interfering with the inferior is concerned. This
24398is the same as using @code{set task pause}, @code{set exceptions}, and
24399@code{set signals} to values opposite to the defaults.
24400
24401@item info send-rights
24402@itemx info receive-rights
24403@itemx info port-rights
24404@itemx info port-sets
24405@itemx info dead-names
24406@itemx info ports
24407@itemx info psets
24408@cindex send rights, @sc{gnu} Hurd
24409@cindex receive rights, @sc{gnu} Hurd
24410@cindex port rights, @sc{gnu} Hurd
24411@cindex port sets, @sc{gnu} Hurd
24412@cindex dead names, @sc{gnu} Hurd
24413These commands display information about, respectively, send rights,
24414receive rights, port rights, port sets, and dead names of a task.
24415There are also shorthand aliases: @code{info ports} for @code{info
24416port-rights} and @code{info psets} for @code{info port-sets}.
24417
24418@item set thread pause
24419@kindex set thread@r{, Hurd command}
24420@cindex thread properties, @sc{gnu} Hurd
24421@cindex pause current thread (@sc{gnu} Hurd)
24422This command toggles current thread suspension when @value{GDBN} has
24423control. Setting it to on takes effect immediately, and the current
24424thread is suspended whenever @value{GDBN} gets control. Setting it to
24425off will take effect the next time the inferior is continued.
24426Normally, this command has no effect, since when @value{GDBN} has
24427control, the whole task is suspended. However, if you used @code{set
24428task pause off} (see above), this command comes in handy to suspend
24429only the current thread.
24430
24431@item show thread pause
24432@kindex show thread@r{, Hurd command}
24433This command shows the state of current thread suspension.
24434
24435@item set thread run
d3e8051b 24436This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24437
24438@item show thread run
24439Show whether the current thread is allowed to run.
24440
24441@item set thread detach-suspend-count
24442@cindex thread suspend count, @sc{gnu} Hurd
24443@cindex detach from thread, @sc{gnu} Hurd
24444This command sets the suspend count @value{GDBN} will leave on a
24445thread when detaching. This number is relative to the suspend count
24446found by @value{GDBN} when it notices the thread; use @code{set thread
24447takeover-suspend-count} to force it to an absolute value.
24448
24449@item show thread detach-suspend-count
24450Show the suspend count @value{GDBN} will leave on the thread when
24451detaching.
24452
24453@item set thread exception-port
24454@itemx set thread excp
24455Set the thread exception port to which to forward exceptions. This
24456overrides the port set by @code{set task exception-port} (see above).
24457@code{set thread excp} is the shorthand alias.
24458
24459@item set thread takeover-suspend-count
24460Normally, @value{GDBN}'s thread suspend counts are relative to the
24461value @value{GDBN} finds when it notices each thread. This command
24462changes the suspend counts to be absolute instead.
24463
24464@item set thread default
24465@itemx show thread default
24466@cindex thread default settings, @sc{gnu} Hurd
24467Each of the above @code{set thread} commands has a @code{set thread
24468default} counterpart (e.g., @code{set thread default pause}, @code{set
24469thread default exception-port}, etc.). The @code{thread default}
24470variety of commands sets the default thread properties for all
24471threads; you can then change the properties of individual threads with
24472the non-default commands.
24473@end table
24474
a80b95ba
TG
24475@node Darwin
24476@subsection Darwin
24477@cindex Darwin
24478
24479@value{GDBN} provides the following commands specific to the Darwin target:
24480
24481@table @code
24482@item set debug darwin @var{num}
24483@kindex set debug darwin
24484When set to a non zero value, enables debugging messages specific to
24485the Darwin support. Higher values produce more verbose output.
24486
24487@item show debug darwin
24488@kindex show debug darwin
24489Show the current state of Darwin messages.
24490
24491@item set debug mach-o @var{num}
24492@kindex set debug mach-o
24493When set to a non zero value, enables debugging messages while
24494@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24495file format used on Darwin for object and executable files.) Higher
24496values produce more verbose output. This is a command to diagnose
24497problems internal to @value{GDBN} and should not be needed in normal
24498usage.
24499
24500@item show debug mach-o
24501@kindex show debug mach-o
24502Show the current state of Mach-O file messages.
24503
24504@item set mach-exceptions on
24505@itemx set mach-exceptions off
24506@kindex set mach-exceptions
24507On Darwin, faults are first reported as a Mach exception and are then
24508mapped to a Posix signal. Use this command to turn on trapping of
24509Mach exceptions in the inferior. This might be sometimes useful to
24510better understand the cause of a fault. The default is off.
24511
24512@item show mach-exceptions
24513@kindex show mach-exceptions
24514Show the current state of exceptions trapping.
24515@end table
24516
e9076973
JB
24517@node FreeBSD
24518@subsection FreeBSD
24519@cindex FreeBSD
24520
24521When the ABI of a system call is changed in the FreeBSD kernel, this
24522is implemented by leaving a compatibility system call using the old
24523ABI at the existing number and allocating a new system call number for
24524the version using the new ABI. As a convenience, when a system call
24525is caught by name (@pxref{catch syscall}), compatibility system calls
24526are also caught.
24527
24528For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24529system call and catching the @code{kevent} system call by name catches
24530both variants:
24531
24532@smallexample
24533(@value{GDBP}) catch syscall kevent
24534Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24535(@value{GDBP})
24536@end smallexample
24537
a64548ea 24538
8e04817f
AC
24539@node Embedded OS
24540@section Embedded Operating Systems
104c1213 24541
8e04817f
AC
24542This section describes configurations involving the debugging of
24543embedded operating systems that are available for several different
24544architectures.
d4f3574e 24545
8e04817f
AC
24546@value{GDBN} includes the ability to debug programs running on
24547various real-time operating systems.
104c1213 24548
6d2ebf8b 24549@node Embedded Processors
104c1213
JM
24550@section Embedded Processors
24551
24552This section goes into details specific to particular embedded
24553configurations.
24554
c45da7e6
EZ
24555@cindex send command to simulator
24556Whenever a specific embedded processor has a simulator, @value{GDBN}
24557allows to send an arbitrary command to the simulator.
24558
24559@table @code
24560@item sim @var{command}
24561@kindex sim@r{, a command}
24562Send an arbitrary @var{command} string to the simulator. Consult the
24563documentation for the specific simulator in use for information about
24564acceptable commands.
24565@end table
24566
7d86b5d5 24567
104c1213 24568@menu
ad0a504f 24569* ARC:: Synopsys ARC
bb615428 24570* ARM:: ARM
39791af2 24571* BPF:: eBPF
104c1213 24572* M68K:: Motorola M68K
08be9d71 24573* MicroBlaze:: Xilinx MicroBlaze
104c1213 24574* MIPS Embedded:: MIPS Embedded
a994fec4 24575* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24576* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24577* AVR:: Atmel AVR
24578* CRIS:: CRIS
24579* Super-H:: Renesas Super-H
104c1213
JM
24580@end menu
24581
ad0a504f
AK
24582@node ARC
24583@subsection Synopsys ARC
24584@cindex Synopsys ARC
24585@cindex ARC specific commands
24586@cindex ARC600
24587@cindex ARC700
24588@cindex ARC EM
24589@cindex ARC HS
24590
24591@value{GDBN} provides the following ARC-specific commands:
24592
24593@table @code
24594@item set debug arc
24595@kindex set debug arc
24596Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24597default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24598
24599@item show debug arc
24600@kindex show debug arc
24601Show the level of ARC specific debugging in operation.
24602
eea78757
AK
24603@item maint print arc arc-instruction @var{address}
24604@kindex maint print arc arc-instruction
24605Print internal disassembler information about instruction at a given address.
24606
ad0a504f
AK
24607@end table
24608
6d2ebf8b 24609@node ARM
104c1213 24610@subsection ARM
8e04817f 24611
e2f4edfd
EZ
24612@value{GDBN} provides the following ARM-specific commands:
24613
24614@table @code
24615@item set arm disassembler
24616@kindex set arm
24617This commands selects from a list of disassembly styles. The
24618@code{"std"} style is the standard style.
24619
24620@item show arm disassembler
24621@kindex show arm
24622Show the current disassembly style.
24623
24624@item set arm apcs32
24625@cindex ARM 32-bit mode
24626This command toggles ARM operation mode between 32-bit and 26-bit.
24627
24628@item show arm apcs32
24629Display the current usage of the ARM 32-bit mode.
24630
24631@item set arm fpu @var{fputype}
24632This command sets the ARM floating-point unit (FPU) type. The
24633argument @var{fputype} can be one of these:
24634
24635@table @code
24636@item auto
24637Determine the FPU type by querying the OS ABI.
24638@item softfpa
24639Software FPU, with mixed-endian doubles on little-endian ARM
24640processors.
24641@item fpa
24642GCC-compiled FPA co-processor.
24643@item softvfp
24644Software FPU with pure-endian doubles.
24645@item vfp
24646VFP co-processor.
24647@end table
24648
24649@item show arm fpu
24650Show the current type of the FPU.
24651
24652@item set arm abi
24653This command forces @value{GDBN} to use the specified ABI.
24654
24655@item show arm abi
24656Show the currently used ABI.
24657
0428b8f5
DJ
24658@item set arm fallback-mode (arm|thumb|auto)
24659@value{GDBN} uses the symbol table, when available, to determine
24660whether instructions are ARM or Thumb. This command controls
24661@value{GDBN}'s default behavior when the symbol table is not
24662available. The default is @samp{auto}, which causes @value{GDBN} to
24663use the current execution mode (from the @code{T} bit in the @code{CPSR}
24664register).
24665
24666@item show arm fallback-mode
24667Show the current fallback instruction mode.
24668
24669@item set arm force-mode (arm|thumb|auto)
24670This command overrides use of the symbol table to determine whether
24671instructions are ARM or Thumb. The default is @samp{auto}, which
24672causes @value{GDBN} to use the symbol table and then the setting
24673of @samp{set arm fallback-mode}.
24674
24675@item show arm force-mode
24676Show the current forced instruction mode.
24677
e2f4edfd
EZ
24678@item set debug arm
24679Toggle whether to display ARM-specific debugging messages from the ARM
24680target support subsystem.
24681
24682@item show debug arm
24683Show whether ARM-specific debugging messages are enabled.
24684@end table
24685
ee8e71d4
EZ
24686@table @code
24687@item target sim @r{[}@var{simargs}@r{]} @dots{}
24688The @value{GDBN} ARM simulator accepts the following optional arguments.
24689
24690@table @code
24691@item --swi-support=@var{type}
697aa1b7 24692Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24693@var{type} may be a comma separated list of the following values.
24694The default value is @code{all}.
24695
24696@table @code
24697@item none
24698@item demon
24699@item angel
24700@item redboot
24701@item all
24702@end table
24703@end table
24704@end table
e2f4edfd 24705
39791af2
JM
24706@node BPF
24707@subsection BPF
24708
24709@table @code
24710@item target sim @r{[}@var{simargs}@r{]} @dots{}
24711The @value{GDBN} BPF simulator accepts the following optional arguments.
24712
24713@table @code
24714@item --skb-data-offset=@var{offset}
24715Tell the simulator the offset, measured in bytes, of the
24716@code{skb_data} field in the kernel @code{struct sk_buff} structure.
24717This offset is used by some BPF specific-purpose load/store
24718instructions. Defaults to 0.
24719@end table
24720@end table
24721
8e04817f
AC
24722@node M68K
24723@subsection M68k
24724
bb615428 24725The Motorola m68k configuration includes ColdFire support.
8e04817f 24726
08be9d71
ME
24727@node MicroBlaze
24728@subsection MicroBlaze
24729@cindex Xilinx MicroBlaze
24730@cindex XMD, Xilinx Microprocessor Debugger
24731
24732The MicroBlaze is a soft-core processor supported on various Xilinx
24733FPGAs, such as Spartan or Virtex series. Boards with these processors
24734usually have JTAG ports which connect to a host system running the Xilinx
24735Embedded Development Kit (EDK) or Software Development Kit (SDK).
24736This host system is used to download the configuration bitstream to
24737the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24738communicates with the target board using the JTAG interface and
24739presents a @code{gdbserver} interface to the board. By default
24740@code{xmd} uses port @code{1234}. (While it is possible to change
24741this default port, it requires the use of undocumented @code{xmd}
24742commands. Contact Xilinx support if you need to do this.)
24743
24744Use these GDB commands to connect to the MicroBlaze target processor.
24745
24746@table @code
24747@item target remote :1234
24748Use this command to connect to the target if you are running @value{GDBN}
24749on the same system as @code{xmd}.
24750
24751@item target remote @var{xmd-host}:1234
24752Use this command to connect to the target if it is connected to @code{xmd}
24753running on a different system named @var{xmd-host}.
24754
24755@item load
24756Use this command to download a program to the MicroBlaze target.
24757
24758@item set debug microblaze @var{n}
24759Enable MicroBlaze-specific debugging messages if non-zero.
24760
24761@item show debug microblaze @var{n}
24762Show MicroBlaze-specific debugging level.
24763@end table
24764
8e04817f 24765@node MIPS Embedded
eb17f351 24766@subsection @acronym{MIPS} Embedded
8e04817f 24767
8e04817f 24768@noindent
f7c38292 24769@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24770
8e04817f 24771@table @code
8e04817f
AC
24772@item set mipsfpu double
24773@itemx set mipsfpu single
24774@itemx set mipsfpu none
a64548ea 24775@itemx set mipsfpu auto
8e04817f
AC
24776@itemx show mipsfpu
24777@kindex set mipsfpu
24778@kindex show mipsfpu
eb17f351
EZ
24779@cindex @acronym{MIPS} remote floating point
24780@cindex floating point, @acronym{MIPS} remote
24781If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24782coprocessor, you should use the command @samp{set mipsfpu none} (if you
24783need this, you may wish to put the command in your @value{GDBN} init
24784file). This tells @value{GDBN} how to find the return value of
24785functions which return floating point values. It also allows
24786@value{GDBN} to avoid saving the floating point registers when calling
24787functions on the board. If you are using a floating point coprocessor
24788with only single precision floating point support, as on the @sc{r4650}
24789processor, use the command @samp{set mipsfpu single}. The default
24790double precision floating point coprocessor may be selected using
24791@samp{set mipsfpu double}.
104c1213 24792
8e04817f
AC
24793In previous versions the only choices were double precision or no
24794floating point, so @samp{set mipsfpu on} will select double precision
24795and @samp{set mipsfpu off} will select no floating point.
104c1213 24796
8e04817f
AC
24797As usual, you can inquire about the @code{mipsfpu} variable with
24798@samp{show mipsfpu}.
8e04817f 24799@end table
104c1213 24800
a994fec4
FJ
24801@node OpenRISC 1000
24802@subsection OpenRISC 1000
24803@cindex OpenRISC 1000
24804
24805@noindent
24806The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24807mainly provided as a soft-core which can run on Xilinx, Altera and other
24808FPGA's.
24809
24810@value{GDBN} for OpenRISC supports the below commands when connecting to
24811a target:
24812
24813@table @code
24814
24815@kindex target sim
24816@item target sim
24817
24818Runs the builtin CPU simulator which can run very basic
24819programs but does not support most hardware functions like MMU.
24820For more complex use cases the user is advised to run an external
24821target, and connect using @samp{target remote}.
24822
24823Example: @code{target sim}
24824
24825@item set debug or1k
24826Toggle whether to display OpenRISC-specific debugging messages from the
24827OpenRISC target support subsystem.
24828
24829@item show debug or1k
24830Show whether OpenRISC-specific debugging messages are enabled.
24831@end table
24832
4acd40f3
TJB
24833@node PowerPC Embedded
24834@subsection PowerPC Embedded
104c1213 24835
66b73624
TJB
24836@cindex DVC register
24837@value{GDBN} supports using the DVC (Data Value Compare) register to
24838implement in hardware simple hardware watchpoint conditions of the form:
24839
24840@smallexample
24841(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24842 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24843@end smallexample
24844
e09342b5
TJB
24845The DVC register will be automatically used when @value{GDBN} detects
24846such pattern in a condition expression, and the created watchpoint uses one
24847debug register (either the @code{exact-watchpoints} option is on and the
24848variable is scalar, or the variable has a length of one byte). This feature
24849is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24850or newer.
24851
24852When running on PowerPC embedded processors, @value{GDBN} automatically uses
24853ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24854in which case watchpoints using only one debug register are created when
24855watching variables of scalar types.
24856
24857You can create an artificial array to watch an arbitrary memory
24858region using one of the following commands (@pxref{Expressions}):
24859
24860@smallexample
24861(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24862(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24863@end smallexample
66b73624 24864
9c06b0b4
TJB
24865PowerPC embedded processors support masked watchpoints. See the discussion
24866about the @code{mask} argument in @ref{Set Watchpoints}.
24867
f1310107
TJB
24868@cindex ranged breakpoint
24869PowerPC embedded processors support hardware accelerated
24870@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24871the inferior whenever it executes an instruction at any address within
24872the range it specifies. To set a ranged breakpoint in @value{GDBN},
24873use the @code{break-range} command.
24874
55eddb0f
DJ
24875@value{GDBN} provides the following PowerPC-specific commands:
24876
104c1213 24877@table @code
f1310107
TJB
24878@kindex break-range
24879@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24880Set a breakpoint for an address range given by
24881@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24882a line number, an offset of lines from the current line or from the start
24883location, or an address of an instruction (see @ref{Specify Location},
24884for a list of all the possible ways to specify a @var{location}.)
24885The breakpoint will stop execution of the inferior whenever it
24886executes an instruction at any address within the specified range,
24887(including @var{start-location} and @var{end-location}.)
24888
55eddb0f
DJ
24889@kindex set powerpc
24890@item set powerpc soft-float
24891@itemx show powerpc soft-float
24892Force @value{GDBN} to use (or not use) a software floating point calling
24893convention. By default, @value{GDBN} selects the calling convention based
24894on the selected architecture and the provided executable file.
24895
24896@item set powerpc vector-abi
24897@itemx show powerpc vector-abi
24898Force @value{GDBN} to use the specified calling convention for vector
24899arguments and return values. The valid options are @samp{auto};
24900@samp{generic}, to avoid vector registers even if they are present;
24901@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24902registers. By default, @value{GDBN} selects the calling convention
24903based on the selected architecture and the provided executable file.
24904
e09342b5
TJB
24905@item set powerpc exact-watchpoints
24906@itemx show powerpc exact-watchpoints
24907Allow @value{GDBN} to use only one debug register when watching a variable
24908of scalar type, thus assuming that the variable is accessed through the
24909address of its first byte.
24910
104c1213
JM
24911@end table
24912
a64548ea
EZ
24913@node AVR
24914@subsection Atmel AVR
24915@cindex AVR
24916
24917When configured for debugging the Atmel AVR, @value{GDBN} supports the
24918following AVR-specific commands:
24919
24920@table @code
24921@item info io_registers
24922@kindex info io_registers@r{, AVR}
24923@cindex I/O registers (Atmel AVR)
24924This command displays information about the AVR I/O registers. For
24925each register, @value{GDBN} prints its number and value.
24926@end table
24927
24928@node CRIS
24929@subsection CRIS
24930@cindex CRIS
24931
24932When configured for debugging CRIS, @value{GDBN} provides the
24933following CRIS-specific commands:
24934
24935@table @code
24936@item set cris-version @var{ver}
24937@cindex CRIS version
e22e55c9
OF
24938Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24939The CRIS version affects register names and sizes. This command is useful in
24940case autodetection of the CRIS version fails.
a64548ea
EZ
24941
24942@item show cris-version
24943Show the current CRIS version.
24944
24945@item set cris-dwarf2-cfi
24946@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24947Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24948Change to @samp{off} when using @code{gcc-cris} whose version is below
24949@code{R59}.
a64548ea
EZ
24950
24951@item show cris-dwarf2-cfi
24952Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24953
24954@item set cris-mode @var{mode}
24955@cindex CRIS mode
24956Set the current CRIS mode to @var{mode}. It should only be changed when
24957debugging in guru mode, in which case it should be set to
24958@samp{guru} (the default is @samp{normal}).
24959
24960@item show cris-mode
24961Show the current CRIS mode.
a64548ea
EZ
24962@end table
24963
24964@node Super-H
24965@subsection Renesas Super-H
24966@cindex Super-H
24967
24968For the Renesas Super-H processor, @value{GDBN} provides these
24969commands:
24970
24971@table @code
c055b101
CV
24972@item set sh calling-convention @var{convention}
24973@kindex set sh calling-convention
24974Set the calling-convention used when calling functions from @value{GDBN}.
24975Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24976With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24977convention. If the DWARF-2 information of the called function specifies
24978that the function follows the Renesas calling convention, the function
24979is called using the Renesas calling convention. If the calling convention
24980is set to @samp{renesas}, the Renesas calling convention is always used,
24981regardless of the DWARF-2 information. This can be used to override the
24982default of @samp{gcc} if debug information is missing, or the compiler
24983does not emit the DWARF-2 calling convention entry for a function.
24984
24985@item show sh calling-convention
24986@kindex show sh calling-convention
24987Show the current calling convention setting.
24988
a64548ea
EZ
24989@end table
24990
24991
8e04817f
AC
24992@node Architectures
24993@section Architectures
104c1213 24994
8e04817f
AC
24995This section describes characteristics of architectures that affect
24996all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24997
8e04817f 24998@menu
430ed3f0 24999* AArch64::
9c16f35a 25000* i386::
8e04817f
AC
25001* Alpha::
25002* MIPS::
a64548ea 25003* HPPA:: HP PA architecture
4acd40f3 25004* PowerPC::
a1217d97 25005* Nios II::
58afddc6 25006* Sparc64::
51d21d60 25007* S12Z::
8e04817f 25008@end menu
104c1213 25009
430ed3f0
MS
25010@node AArch64
25011@subsection AArch64
25012@cindex AArch64 support
25013
25014When @value{GDBN} is debugging the AArch64 architecture, it provides the
25015following special commands:
25016
25017@table @code
25018@item set debug aarch64
25019@kindex set debug aarch64
25020This command determines whether AArch64 architecture-specific debugging
25021messages are to be displayed.
25022
25023@item show debug aarch64
25024Show whether AArch64 debugging messages are displayed.
25025
25026@end table
25027
1461bdac
AH
25028@subsubsection AArch64 SVE.
25029@cindex AArch64 SVE.
25030
25031When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25032Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25033@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25034@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25035@code{$vg} will be provided. This is the vector granule for the current thread
25036and represents the number of 64-bit chunks in an SVE @code{z} register.
25037
25038If the vector length changes, then the @code{$vg} register will be updated,
25039but the lengths of the @code{z} and @code{p} registers will not change. This
25040is a known limitation of @value{GDBN} and does not affect the execution of the
25041target process.
25042
3d31bc39
AH
25043@subsubsection AArch64 Pointer Authentication.
25044@cindex AArch64 Pointer Authentication.
25045
25046When @value{GDBN} is debugging the AArch64 architecture, and the program is
25047using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 25048register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 25049When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
25050postfixed with the marker [PAC]. When using the MI, this is printed as part
25051of the @code{addr_flags} field.
1461bdac 25052
9c16f35a 25053@node i386
db2e3e2e 25054@subsection x86 Architecture-specific Issues
9c16f35a
EZ
25055
25056@table @code
25057@item set struct-convention @var{mode}
25058@kindex set struct-convention
25059@cindex struct return convention
25060@cindex struct/union returned in registers
25061Set the convention used by the inferior to return @code{struct}s and
25062@code{union}s from functions to @var{mode}. Possible values of
25063@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25064default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25065are returned on the stack, while @code{"reg"} means that a
25066@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25067be returned in a register.
25068
25069@item show struct-convention
25070@kindex show struct-convention
25071Show the current setting of the convention to return @code{struct}s
25072from functions.
966f0aef 25073@end table
29c1c244 25074
ca8941bb 25075
bc504a31
PA
25076@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25077@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 25078
ca8941bb
WT
25079Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25080@footnote{The register named with capital letters represent the architecture
25081registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25082which are the lower bound and upper bound. Bounds are effective addresses or
25083memory locations. The upper bounds are architecturally represented in 1's
25084complement form. A bound having lower bound = 0, and upper bound = 0
25085(1's complement of all bits set) will allow access to the entire address space.
25086
25087@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25088through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25089display the upper bound performing the complement of one operation on the
25090upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25091@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25092can also be noted that the upper bounds are inclusive.
25093
25094As an example, assume that the register BND0 holds bounds for a pointer having
25095access allowed for the range between 0x32 and 0x71. The values present on
25096bnd0raw and bnd registers are presented as follows:
25097
25098@smallexample
25099 bnd0raw = @{0x32, 0xffffffff8e@}
25100 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25101@end smallexample
25102
22f25c9d
EZ
25103This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25104change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25105counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25106Python, the display includes the memory size, in bits, accessible to
25107the pointer.
9c16f35a 25108
29c1c244
WT
25109Bounds can also be stored in bounds tables, which are stored in
25110application memory. These tables store bounds for pointers by specifying
25111the bounds pointer's value along with its bounds. Evaluating and changing
25112bounds located in bound tables is therefore interesting while investigating
25113bugs on MPX context. @value{GDBN} provides commands for this purpose:
25114
966f0aef 25115@table @code
29c1c244
WT
25116@item show mpx bound @var{pointer}
25117@kindex show mpx bound
25118Display bounds of the given @var{pointer}.
25119
25120@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25121@kindex set mpx bound
25122Set the bounds of a pointer in the bound table.
25123This command takes three parameters: @var{pointer} is the pointers
25124whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25125for lower and upper bounds respectively.
25126@end table
25127
4a612d6f
WT
25128When you call an inferior function on an Intel MPX enabled program,
25129GDB sets the inferior's bound registers to the init (disabled) state
25130before calling the function. As a consequence, bounds checks for the
25131pointer arguments passed to the function will always pass.
25132
25133This is necessary because when you call an inferior function, the
25134program is usually in the middle of the execution of other function.
25135Since at that point bound registers are in an arbitrary state, not
25136clearing them would lead to random bound violations in the called
25137function.
25138
25139You can still examine the influence of the bound registers on the
25140execution of the called function by stopping the execution of the
25141called function at its prologue, setting bound registers, and
25142continuing the execution. For example:
25143
25144@smallexample
25145 $ break *upper
25146 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25147 $ print upper (a, b, c, d, 1)
25148 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25149 $ print $bnd0
5cf70512 25150 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
25151@end smallexample
25152
25153At this last step the value of bnd0 can be changed for investigation of bound
25154violations caused along the execution of the call. In order to know how to
25155set the bound registers or bound table for the call consult the ABI.
25156
8e04817f
AC
25157@node Alpha
25158@subsection Alpha
104c1213 25159
8e04817f 25160See the following section.
104c1213 25161
8e04817f 25162@node MIPS
eb17f351 25163@subsection @acronym{MIPS}
104c1213 25164
8e04817f 25165@cindex stack on Alpha
eb17f351 25166@cindex stack on @acronym{MIPS}
8e04817f 25167@cindex Alpha stack
eb17f351
EZ
25168@cindex @acronym{MIPS} stack
25169Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
25170sometimes requires @value{GDBN} to search backward in the object code to
25171find the beginning of a function.
104c1213 25172
eb17f351 25173@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
25174To improve response time (especially for embedded applications, where
25175@value{GDBN} may be restricted to a slow serial line for this search)
25176you may want to limit the size of this search, using one of these
25177commands:
104c1213 25178
8e04817f 25179@table @code
eb17f351 25180@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
25181@item set heuristic-fence-post @var{limit}
25182Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25183search for the beginning of a function. A value of @var{0} (the
25184default) means there is no limit. However, except for @var{0}, the
25185larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
25186and therefore the longer it takes to run. You should only need to use
25187this command when debugging a stripped executable.
104c1213 25188
8e04817f
AC
25189@item show heuristic-fence-post
25190Display the current limit.
25191@end table
104c1213
JM
25192
25193@noindent
8e04817f 25194These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 25195for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 25196
eb17f351 25197Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
25198programs:
25199
25200@table @code
a64548ea
EZ
25201@item set mips abi @var{arg}
25202@kindex set mips abi
eb17f351
EZ
25203@cindex set ABI for @acronym{MIPS}
25204Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
25205values of @var{arg} are:
25206
25207@table @samp
25208@item auto
25209The default ABI associated with the current binary (this is the
25210default).
25211@item o32
25212@item o64
25213@item n32
25214@item n64
25215@item eabi32
25216@item eabi64
a64548ea
EZ
25217@end table
25218
25219@item show mips abi
25220@kindex show mips abi
eb17f351 25221Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 25222
4cc0665f
MR
25223@item set mips compression @var{arg}
25224@kindex set mips compression
25225@cindex code compression, @acronym{MIPS}
25226Tell @value{GDBN} which @acronym{MIPS} compressed
25227@acronym{ISA, Instruction Set Architecture} encoding is used by the
25228inferior. @value{GDBN} uses this for code disassembly and other
25229internal interpretation purposes. This setting is only referred to
25230when no executable has been associated with the debugging session or
25231the executable does not provide information about the encoding it uses.
25232Otherwise this setting is automatically updated from information
25233provided by the executable.
25234
25235Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25236The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25237executables containing @acronym{MIPS16} code frequently are not
25238identified as such.
25239
25240This setting is ``sticky''; that is, it retains its value across
25241debugging sessions until reset either explicitly with this command or
25242implicitly from an executable.
25243
25244The compiler and/or assembler typically add symbol table annotations to
25245identify functions compiled for the @acronym{MIPS16} or
25246@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25247are present, @value{GDBN} uses them in preference to the global
25248compressed @acronym{ISA} encoding setting.
25249
25250@item show mips compression
25251@kindex show mips compression
25252Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25253@value{GDBN} to debug the inferior.
25254
a64548ea
EZ
25255@item set mipsfpu
25256@itemx show mipsfpu
25257@xref{MIPS Embedded, set mipsfpu}.
25258
25259@item set mips mask-address @var{arg}
25260@kindex set mips mask-address
eb17f351 25261@cindex @acronym{MIPS} addresses, masking
a64548ea 25262This command determines whether the most-significant 32 bits of 64-bit
eb17f351 25263@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
25264@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25265setting, which lets @value{GDBN} determine the correct value.
25266
25267@item show mips mask-address
25268@kindex show mips mask-address
eb17f351 25269Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
25270not.
25271
25272@item set remote-mips64-transfers-32bit-regs
25273@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
25274This command controls compatibility with 64-bit @acronym{MIPS} targets that
25275transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
25276that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25277and 64 bits for other registers, set this option to @samp{on}.
25278
25279@item show remote-mips64-transfers-32bit-regs
25280@kindex show remote-mips64-transfers-32bit-regs
eb17f351 25281Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
25282
25283@item set debug mips
25284@kindex set debug mips
eb17f351 25285This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
25286target code in @value{GDBN}.
25287
25288@item show debug mips
25289@kindex show debug mips
eb17f351 25290Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
25291@end table
25292
25293
25294@node HPPA
25295@subsection HPPA
25296@cindex HPPA support
25297
d3e8051b 25298When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
25299following special commands:
25300
25301@table @code
25302@item set debug hppa
25303@kindex set debug hppa
db2e3e2e 25304This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
25305messages are to be displayed.
25306
25307@item show debug hppa
25308Show whether HPPA debugging messages are displayed.
25309
25310@item maint print unwind @var{address}
25311@kindex maint print unwind@r{, HPPA}
25312This command displays the contents of the unwind table entry at the
25313given @var{address}.
25314
25315@end table
25316
104c1213 25317
4acd40f3
TJB
25318@node PowerPC
25319@subsection PowerPC
25320@cindex PowerPC architecture
25321
25322When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25323pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25324numbers stored in the floating point registers. These values must be stored
25325in two consecutive registers, always starting at an even register like
25326@code{f0} or @code{f2}.
25327
25328The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25329by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25330@code{f2} and @code{f3} for @code{$dl1} and so on.
25331
aeac0ff9 25332For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25333wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25334
a1217d97
SL
25335@node Nios II
25336@subsection Nios II
25337@cindex Nios II architecture
25338
25339When @value{GDBN} is debugging the Nios II architecture,
25340it provides the following special commands:
25341
25342@table @code
25343
25344@item set debug nios2
25345@kindex set debug nios2
25346This command turns on and off debugging messages for the Nios II
25347target code in @value{GDBN}.
25348
25349@item show debug nios2
25350@kindex show debug nios2
25351Show the current setting of Nios II debugging messages.
25352@end table
23d964e7 25353
58afddc6
WP
25354@node Sparc64
25355@subsection Sparc64
25356@cindex Sparc64 support
25357@cindex Application Data Integrity
25358@subsubsection ADI Support
25359
25360The M7 processor supports an Application Data Integrity (ADI) feature that
25361detects invalid data accesses. When software allocates memory and enables
25362ADI on the allocated memory, it chooses a 4-bit version number, sets the
25363version in the upper 4 bits of the 64-bit pointer to that data, and stores
25364the 4-bit version in every cacheline of that data. Hardware saves the latter
25365in spare bits in the cache and memory hierarchy. On each load and store,
25366the processor compares the upper 4 VA (virtual address) bits to the
25367cacheline's version. If there is a mismatch, the processor generates a
25368version mismatch trap which can be either precise or disrupting. The trap
25369is an error condition which the kernel delivers to the process as a SIGSEGV
25370signal.
25371
25372Note that only 64-bit applications can use ADI and need to be built with
25373ADI-enabled.
25374
25375Values of the ADI version tags, which are in granularity of a
25376cacheline (64 bytes), can be viewed or modified.
25377
25378
25379@table @code
25380@kindex adi examine
25381@item adi (examine | x) [ / @var{n} ] @var{addr}
25382
25383The @code{adi examine} command displays the value of one ADI version tag per
25384cacheline.
25385
25386@var{n} is a decimal integer specifying the number in bytes; the default
25387is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25388block size, to display.
25389
25390@var{addr} is the address in user address space where you want @value{GDBN}
25391to begin displaying the ADI version tags.
25392
25393Below is an example of displaying ADI versions of variable "shmaddr".
25394
25395@smallexample
25396(@value{GDBP}) adi x/100 shmaddr
25397 0xfff800010002c000: 0 0
25398@end smallexample
25399
25400@kindex adi assign
25401@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25402
25403The @code{adi assign} command is used to assign new ADI version tag
25404to an address.
25405
25406@var{n} is a decimal integer specifying the number in bytes;
25407the default is 1. It specifies how much ADI version information, at the
25408ratio of 1:ADI block size, to modify.
25409
25410@var{addr} is the address in user address space where you want @value{GDBN}
25411to begin modifying the ADI version tags.
25412
25413@var{tag} is the new ADI version tag.
25414
25415For example, do the following to modify then verify ADI versions of
25416variable "shmaddr":
25417
25418@smallexample
25419(@value{GDBP}) adi a/100 shmaddr = 7
25420(@value{GDBP}) adi x/100 shmaddr
25421 0xfff800010002c000: 7 7
25422@end smallexample
25423
25424@end table
25425
51d21d60
JD
25426@node S12Z
25427@subsection S12Z
25428@cindex S12Z support
25429
25430When @value{GDBN} is debugging the S12Z architecture,
25431it provides the following special command:
25432
25433@table @code
25434@item maint info bdccsr
25435@kindex maint info bdccsr@r{, S12Z}
25436This command displays the current value of the microprocessor's
25437BDCCSR register.
25438@end table
25439
25440
8e04817f
AC
25441@node Controlling GDB
25442@chapter Controlling @value{GDBN}
25443
25444You can alter the way @value{GDBN} interacts with you by using the
25445@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25446data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25447described here.
25448
25449@menu
25450* Prompt:: Prompt
25451* Editing:: Command editing
d620b259 25452* Command History:: Command history
8e04817f 25453* Screen Size:: Screen size
140a4bc0 25454* Output Styling:: Output styling
8e04817f 25455* Numbers:: Numbers
1e698235 25456* ABI:: Configuring the current ABI
bf88dd68 25457* Auto-loading:: Automatically loading associated files
8e04817f
AC
25458* Messages/Warnings:: Optional warnings and messages
25459* Debugging Output:: Optional messages about internal happenings
14fb1bac 25460* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25461@end menu
25462
25463@node Prompt
25464@section Prompt
104c1213 25465
8e04817f 25466@cindex prompt
104c1213 25467
8e04817f
AC
25468@value{GDBN} indicates its readiness to read a command by printing a string
25469called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25470can change the prompt string with the @code{set prompt} command. For
25471instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25472the prompt in one of the @value{GDBN} sessions so that you can always tell
25473which one you are talking to.
104c1213 25474
8e04817f
AC
25475@emph{Note:} @code{set prompt} does not add a space for you after the
25476prompt you set. This allows you to set a prompt which ends in a space
25477or a prompt that does not.
104c1213 25478
8e04817f
AC
25479@table @code
25480@kindex set prompt
25481@item set prompt @var{newprompt}
25482Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25483
8e04817f
AC
25484@kindex show prompt
25485@item show prompt
25486Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25487@end table
25488
fa3a4f15
PM
25489Versions of @value{GDBN} that ship with Python scripting enabled have
25490prompt extensions. The commands for interacting with these extensions
25491are:
25492
25493@table @code
25494@kindex set extended-prompt
25495@item set extended-prompt @var{prompt}
25496Set an extended prompt that allows for substitutions.
25497@xref{gdb.prompt}, for a list of escape sequences that can be used for
25498substitution. Any escape sequences specified as part of the prompt
25499string are replaced with the corresponding strings each time the prompt
25500is displayed.
25501
25502For example:
25503
25504@smallexample
25505set extended-prompt Current working directory: \w (gdb)
25506@end smallexample
25507
25508Note that when an extended-prompt is set, it takes control of the
25509@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25510
25511@kindex show extended-prompt
25512@item show extended-prompt
25513Prints the extended prompt. Any escape sequences specified as part of
25514the prompt string with @code{set extended-prompt}, are replaced with the
25515corresponding strings each time the prompt is displayed.
25516@end table
25517
8e04817f 25518@node Editing
79a6e687 25519@section Command Editing
8e04817f
AC
25520@cindex readline
25521@cindex command line editing
104c1213 25522
703663ab 25523@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25524@sc{gnu} library provides consistent behavior for programs which provide a
25525command line interface to the user. Advantages are @sc{gnu} Emacs-style
25526or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25527substitution, and a storage and recall of command history across
25528debugging sessions.
104c1213 25529
8e04817f
AC
25530You may control the behavior of command line editing in @value{GDBN} with the
25531command @code{set}.
104c1213 25532
8e04817f
AC
25533@table @code
25534@kindex set editing
25535@cindex editing
25536@item set editing
25537@itemx set editing on
25538Enable command line editing (enabled by default).
104c1213 25539
8e04817f
AC
25540@item set editing off
25541Disable command line editing.
104c1213 25542
8e04817f
AC
25543@kindex show editing
25544@item show editing
25545Show whether command line editing is enabled.
104c1213
JM
25546@end table
25547
39037522
TT
25548@ifset SYSTEM_READLINE
25549@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25550@end ifset
25551@ifclear SYSTEM_READLINE
25552@xref{Command Line Editing},
25553@end ifclear
25554for more details about the Readline
703663ab
EZ
25555interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25556encouraged to read that chapter.
25557
11061048
TT
25558@cindex Readline application name
25559@value{GDBN} sets the Readline application name to @samp{gdb}. This
25560is useful for conditions in @file{.inputrc}.
25561
c71acd15
TT
25562@cindex operate-and-get-next
25563@value{GDBN} defines a bindable Readline command,
25564@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25565This command accepts the current line for execution and fetches the
25566next line relative to the current line from the history for editing.
25567Any argument is ignored.
25568
d620b259 25569@node Command History
79a6e687 25570@section Command History
703663ab 25571@cindex command history
8e04817f
AC
25572
25573@value{GDBN} can keep track of the commands you type during your
25574debugging sessions, so that you can be certain of precisely what
25575happened. Use these commands to manage the @value{GDBN} command
25576history facility.
104c1213 25577
703663ab 25578@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25579package, to provide the history facility.
25580@ifset SYSTEM_READLINE
25581@xref{Using History Interactively, , , history, GNU History Library},
25582@end ifset
25583@ifclear SYSTEM_READLINE
25584@xref{Using History Interactively},
25585@end ifclear
25586for the detailed description of the History library.
703663ab 25587
d620b259 25588To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25589the state which is seen by users, prefix it with @samp{server }
25590(@pxref{Server Prefix}). This
d620b259
NR
25591means that this command will not affect the command history, nor will it
25592affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25593pressed on a line by itself.
25594
25595@cindex @code{server}, command prefix
25596The server prefix does not affect the recording of values into the value
25597history; to print a value without recording it into the value history,
25598use the @code{output} command instead of the @code{print} command.
25599
703663ab
EZ
25600Here is the description of @value{GDBN} commands related to command
25601history.
25602
104c1213 25603@table @code
8e04817f
AC
25604@cindex history substitution
25605@cindex history file
25606@kindex set history filename
4644b6e3 25607@cindex @env{GDBHISTFILE}, environment variable
63e163f2 25608@item set history filename @r{[}@var{fname}@r{]}
8e04817f
AC
25609Set the name of the @value{GDBN} command history file to @var{fname}.
25610This is the file where @value{GDBN} reads an initial command history
25611list, and where it writes the command history from this session when it
25612exits. You can access this list through history expansion or through
25613the history command editing characters listed below. This file defaults
25614to the value of the environment variable @code{GDBHISTFILE}, or to
25615@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25616is not set.
104c1213 25617
63e163f2
AB
25618The @code{GDBHISTFILE} environment variable is read after processing
25619any @value{GDBN} initialization files (@pxref{Startup}) and after
25620processing any commands passed using command line options (for
25621example, @code{-ex}).
25622
25623If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25624is the empty string then @value{GDBN} will neither try to load an
25625existing history file, nor will it try to save the history on exit.
25626
9c16f35a
EZ
25627@cindex save command history
25628@kindex set history save
8e04817f
AC
25629@item set history save
25630@itemx set history save on
25631Record command history in a file, whose name may be specified with the
63e163f2
AB
25632@code{set history filename} command. By default, this option is
25633disabled. The command history will be recorded when @value{GDBN}
25634exits. If @code{set history filename} is set to the empty string then
25635history saving is disabled, even when @code{set history save} is
25636@code{on}.
104c1213 25637
8e04817f 25638@item set history save off
63e163f2
AB
25639Don't record the command history into the file specified by @code{set
25640history filename} when @value{GDBN} exits.
104c1213 25641
8e04817f 25642@cindex history size
9c16f35a 25643@kindex set history size
b58c513b 25644@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25645@item set history size @var{size}
f81d1120 25646@itemx set history size unlimited
8e04817f 25647Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25648This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25649to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25650are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25651either a negative number or the empty string, then the number of commands
25652@value{GDBN} keeps in the history list is unlimited.
fc637f04 25653
63e163f2
AB
25654The @code{GDBHISTSIZE} environment variable is read after processing
25655any @value{GDBN} initialization files (@pxref{Startup}) and after
25656processing any commands passed using command line options (for
25657example, @code{-ex}).
25658
fc637f04
PP
25659@cindex remove duplicate history
25660@kindex set history remove-duplicates
25661@item set history remove-duplicates @var{count}
25662@itemx set history remove-duplicates unlimited
25663Control the removal of duplicate history entries in the command history list.
25664If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25665history entries and remove the first entry that is a duplicate of the current
25666entry being added to the command history list. If @var{count} is
25667@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25668removal of duplicate history entries is disabled.
25669
25670Only history entries added during the current session are considered for
25671removal. This option is set to 0 by default.
25672
104c1213
JM
25673@end table
25674
8e04817f 25675History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25676@ifset SYSTEM_READLINE
25677@xref{Event Designators, , , history, GNU History Library},
25678@end ifset
25679@ifclear SYSTEM_READLINE
25680@xref{Event Designators},
25681@end ifclear
25682for more details.
8e04817f 25683
703663ab 25684@cindex history expansion, turn on/off
8e04817f
AC
25685Since @kbd{!} is also the logical not operator in C, history expansion
25686is off by default. If you decide to enable history expansion with the
25687@code{set history expansion on} command, you may sometimes need to
25688follow @kbd{!} (when it is used as logical not, in an expression) with
25689a space or a tab to prevent it from being expanded. The readline
25690history facilities do not attempt substitution on the strings
25691@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25692
25693The commands to control history expansion are:
104c1213
JM
25694
25695@table @code
8e04817f
AC
25696@item set history expansion on
25697@itemx set history expansion
703663ab 25698@kindex set history expansion
8e04817f 25699Enable history expansion. History expansion is off by default.
104c1213 25700
8e04817f
AC
25701@item set history expansion off
25702Disable history expansion.
104c1213 25703
8e04817f
AC
25704@c @group
25705@kindex show history
25706@item show history
25707@itemx show history filename
25708@itemx show history save
25709@itemx show history size
25710@itemx show history expansion
25711These commands display the state of the @value{GDBN} history parameters.
25712@code{show history} by itself displays all four states.
25713@c @end group
25714@end table
25715
25716@table @code
9c16f35a
EZ
25717@kindex show commands
25718@cindex show last commands
25719@cindex display command history
8e04817f
AC
25720@item show commands
25721Display the last ten commands in the command history.
104c1213 25722
8e04817f
AC
25723@item show commands @var{n}
25724Print ten commands centered on command number @var{n}.
25725
25726@item show commands +
25727Print ten commands just after the commands last printed.
104c1213
JM
25728@end table
25729
8e04817f 25730@node Screen Size
79a6e687 25731@section Screen Size
8e04817f 25732@cindex size of screen
f179cf97
EZ
25733@cindex screen size
25734@cindex pagination
25735@cindex page size
8e04817f 25736@cindex pauses in output
104c1213 25737
8e04817f
AC
25738Certain commands to @value{GDBN} may produce large amounts of
25739information output to the screen. To help you read all of it,
25740@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25741output. Type @key{RET} when you want to see one more page of output,
25742@kbd{q} to discard the remaining output, or @kbd{c} to continue
25743without paging for the rest of the current command. Also, the screen
25744width setting determines when to wrap lines of output. Depending on
25745what is being printed, @value{GDBN} tries to break the line at a
25746readable place, rather than simply letting it overflow onto the
25747following line.
8e04817f
AC
25748
25749Normally @value{GDBN} knows the size of the screen from the terminal
25750driver software. For example, on Unix @value{GDBN} uses the termcap data base
25751together with the value of the @code{TERM} environment variable and the
25752@code{stty rows} and @code{stty cols} settings. If this is not correct,
25753you can override it with the @code{set height} and @code{set
25754width} commands:
25755
25756@table @code
25757@kindex set height
25758@kindex set width
25759@kindex show width
25760@kindex show height
25761@item set height @var{lpp}
f81d1120 25762@itemx set height unlimited
8e04817f
AC
25763@itemx show height
25764@itemx set width @var{cpl}
f81d1120 25765@itemx set width unlimited
8e04817f
AC
25766@itemx show width
25767These @code{set} commands specify a screen height of @var{lpp} lines and
25768a screen width of @var{cpl} characters. The associated @code{show}
25769commands display the current settings.
104c1213 25770
f81d1120
PA
25771If you specify a height of either @code{unlimited} or zero lines,
25772@value{GDBN} does not pause during output no matter how long the
25773output is. This is useful if output is to a file or to an editor
25774buffer.
104c1213 25775
f81d1120
PA
25776Likewise, you can specify @samp{set width unlimited} or @samp{set
25777width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25778
25779@item set pagination on
25780@itemx set pagination off
25781@kindex set pagination
25782Turn the output pagination on or off; the default is on. Turning
f81d1120 25783pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25784running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25785Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25786
25787@item show pagination
25788@kindex show pagination
25789Show the current pagination mode.
104c1213
JM
25790@end table
25791
140a4bc0
TT
25792@node Output Styling
25793@section Output Styling
25794@cindex styling
25795@cindex colors
25796
25797@kindex set style
25798@kindex show style
25799@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25800enabled by default on most systems, but disabled by default when in
25801batch mode (@pxref{Mode Options}). Various style settings are available;
25802and styles can also be disabled entirely.
140a4bc0
TT
25803
25804@table @code
25805@item set style enabled @samp{on|off}
25806Enable or disable all styling. The default is host-dependent, with
25807most hosts defaulting to @samp{on}.
25808
25809@item show style enabled
25810Show the current state of styling.
d085f989
TT
25811
25812@item set style sources @samp{on|off}
25813Enable or disable source code styling. This affects whether source
25814code, such as the output of the @code{list} command, is styled. Note
25815that source styling only works if styling in general is enabled, and
25816if @value{GDBN} was linked with the GNU Source Highlight library. The
25817default is @samp{on}.
25818
25819@item show style sources
25820Show the current state of source code styling.
140a4bc0
TT
25821@end table
25822
25823Subcommands of @code{set style} control specific forms of styling.
25824These subcommands all follow the same pattern: each style-able object
25825can be styled with a foreground color, a background color, and an
25826intensity.
25827
25828For example, the style of file names can be controlled using the
25829@code{set style filename} group of commands:
25830
25831@table @code
25832@item set style filename background @var{color}
25833Set the background to @var{color}. Valid colors are @samp{none}
25834(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25835@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25836and@samp{white}.
25837
25838@item set style filename foreground @var{color}
25839Set the foreground to @var{color}. Valid colors are @samp{none}
25840(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25841@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25842and@samp{white}.
25843
25844@item set style filename intensity @var{value}
25845Set the intensity to @var{value}. Valid intensities are @samp{normal}
25846(the default), @samp{bold}, and @samp{dim}.
25847@end table
25848
e664d728
PW
25849The @code{show style} command and its subcommands are styling
25850a style name in their output using its own style.
25851So, use @command{show style} to see the complete list of styles,
25852their characteristics and the visual aspect of each style.
25853
140a4bc0
TT
25854The style-able objects are:
25855@table @code
25856@item filename
e3624a40
EZ
25857Control the styling of file names. By default, this style's
25858foreground color is green.
140a4bc0
TT
25859
25860@item function
25861Control the styling of function names. These are managed with the
e3624a40
EZ
25862@code{set style function} family of commands. By default, this
25863style's foreground color is yellow.
140a4bc0
TT
25864
25865@item variable
25866Control the styling of variable names. These are managed with the
e3624a40
EZ
25867@code{set style variable} family of commands. By default, this style's
25868foreground color is cyan.
140a4bc0
TT
25869
25870@item address
25871Control the styling of addresses. These are managed with the
e3624a40
EZ
25872@code{set style address} family of commands. By default, this style's
25873foreground color is blue.
e664d728
PW
25874
25875@item title
25876Control the styling of titles. These are managed with the
25877@code{set style title} family of commands. By default, this style's
25878intensity is bold. Commands are using the title style to improve
6b92c0d3 25879the readability of large output. For example, the commands
e664d728
PW
25880@command{apropos} and @command{help} are using the title style
25881for the command names.
25882
25883@item highlight
25884Control the styling of highlightings. These are managed with the
25885@code{set style highlight} family of commands. By default, this style's
25886foreground color is red. Commands are using the highlight style to draw
25887the user attention to some specific parts of their output. For example,
25888the command @command{apropos -v REGEXP} uses the highlight style to
25889mark the documentation parts matching @var{regexp}.
25890
a2a7af0c
TT
25891@item tui-border
25892Control the styling of the TUI border. Note that, unlike other
25893styling options, only the color of the border can be controlled via
25894@code{set style}. This was done for compatibility reasons, as TUI
25895controls to set the border's intensity predated the addition of
25896general styling to @value{GDBN}. @xref{TUI Configuration}.
25897
25898@item tui-active-border
25899Control the styling of the active TUI border; that is, the TUI window
25900that has the focus.
25901
140a4bc0
TT
25902@end table
25903
8e04817f
AC
25904@node Numbers
25905@section Numbers
25906@cindex number representation
25907@cindex entering numbers
104c1213 25908
8e04817f
AC
25909You can always enter numbers in octal, decimal, or hexadecimal in
25910@value{GDBN} by the usual conventions: octal numbers begin with
25911@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25912begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25913@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2591410; likewise, the default display for numbers---when no particular
25915format is specified---is base 10. You can change the default base for
25916both input and output with the commands described below.
104c1213 25917
8e04817f
AC
25918@table @code
25919@kindex set input-radix
25920@item set input-radix @var{base}
25921Set the default base for numeric input. Supported choices
697aa1b7 25922for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25923specified either unambiguously or using the current input radix; for
8e04817f 25924example, any of
104c1213 25925
8e04817f 25926@smallexample
9c16f35a
EZ
25927set input-radix 012
25928set input-radix 10.
25929set input-radix 0xa
8e04817f 25930@end smallexample
104c1213 25931
8e04817f 25932@noindent
9c16f35a 25933sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25934leaves the input radix unchanged, no matter what it was, since
25935@samp{10}, being without any leading or trailing signs of its base, is
25936interpreted in the current radix. Thus, if the current radix is 16,
25937@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25938change the radix.
104c1213 25939
8e04817f
AC
25940@kindex set output-radix
25941@item set output-radix @var{base}
25942Set the default base for numeric display. Supported choices
697aa1b7 25943for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25944specified either unambiguously or using the current input radix.
104c1213 25945
8e04817f
AC
25946@kindex show input-radix
25947@item show input-radix
25948Display the current default base for numeric input.
104c1213 25949
8e04817f
AC
25950@kindex show output-radix
25951@item show output-radix
25952Display the current default base for numeric display.
9c16f35a
EZ
25953
25954@item set radix @r{[}@var{base}@r{]}
25955@itemx show radix
25956@kindex set radix
25957@kindex show radix
25958These commands set and show the default base for both input and output
25959of numbers. @code{set radix} sets the radix of input and output to
25960the same base; without an argument, it resets the radix back to its
25961default value of 10.
25962
8e04817f 25963@end table
104c1213 25964
1e698235 25965@node ABI
79a6e687 25966@section Configuring the Current ABI
1e698235
DJ
25967
25968@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25969application automatically. However, sometimes you need to override its
25970conclusions. Use these commands to manage @value{GDBN}'s view of the
25971current ABI.
25972
98b45e30
DJ
25973@cindex OS ABI
25974@kindex set osabi
b4e9345d 25975@kindex show osabi
430ed3f0 25976@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25977
25978One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25979system targets, either via remote debugging or native emulation.
98b45e30
DJ
25980@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25981but you can override its conclusion using the @code{set osabi} command.
25982One example where this is useful is in debugging of binaries which use
25983an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25984not have the same identifying marks that the standard C library for your
25985platform provides.
25986
430ed3f0
MS
25987When @value{GDBN} is debugging the AArch64 architecture, it provides a
25988``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25989@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25990The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25991
98b45e30
DJ
25992@table @code
25993@item show osabi
25994Show the OS ABI currently in use.
25995
25996@item set osabi
25997With no argument, show the list of registered available OS ABI's.
25998
25999@item set osabi @var{abi}
26000Set the current OS ABI to @var{abi}.
26001@end table
26002
1e698235 26003@cindex float promotion
1e698235
DJ
26004
26005Generally, the way that an argument of type @code{float} is passed to a
26006function depends on whether the function is prototyped. For a prototyped
26007(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26008according to the architecture's convention for @code{float}. For unprototyped
26009(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26010@code{double} and then passed.
26011
26012Unfortunately, some forms of debug information do not reliably indicate whether
26013a function is prototyped. If @value{GDBN} calls a function that is not marked
26014as prototyped, it consults @kbd{set coerce-float-to-double}.
26015
26016@table @code
a8f24a35 26017@kindex set coerce-float-to-double
1e698235
DJ
26018@item set coerce-float-to-double
26019@itemx set coerce-float-to-double on
26020Arguments of type @code{float} will be promoted to @code{double} when passed
26021to an unprototyped function. This is the default setting.
26022
26023@item set coerce-float-to-double off
26024Arguments of type @code{float} will be passed directly to unprototyped
26025functions.
9c16f35a
EZ
26026
26027@kindex show coerce-float-to-double
26028@item show coerce-float-to-double
26029Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
26030@end table
26031
f1212245
DJ
26032@kindex set cp-abi
26033@kindex show cp-abi
26034@value{GDBN} needs to know the ABI used for your program's C@t{++}
26035objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26036used to build your application. @value{GDBN} only fully supports
26037programs with a single C@t{++} ABI; if your program contains code using
26038multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26039program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26040Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26041before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26042``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26043use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26044``auto''.
26045
26046@table @code
26047@item show cp-abi
26048Show the C@t{++} ABI currently in use.
26049
26050@item set cp-abi
26051With no argument, show the list of supported C@t{++} ABI's.
26052
26053@item set cp-abi @var{abi}
26054@itemx set cp-abi auto
26055Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26056@end table
26057
bf88dd68
JK
26058@node Auto-loading
26059@section Automatically loading associated files
26060@cindex auto-loading
26061
26062@value{GDBN} sometimes reads files with commands and settings automatically,
26063without being explicitly told so by the user. We call this feature
26064@dfn{auto-loading}. While auto-loading is useful for automatically adapting
26065@value{GDBN} to the needs of your project, it can sometimes produce unexpected
26066results or introduce security risks (e.g., if the file comes from untrusted
26067sources).
26068
71b8c845
DE
26069@menu
26070* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26071* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26072
26073* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26074* Auto-loading verbose mode:: @samp{set/show debug auto-load}
26075@end menu
26076
26077There are various kinds of files @value{GDBN} can automatically load.
26078In addition to these files, @value{GDBN} supports auto-loading code written
26079in various extension languages. @xref{Auto-loading extensions}.
26080
c1668e4e
JK
26081Note that loading of these associated files (including the local @file{.gdbinit}
26082file) requires accordingly configured @code{auto-load safe-path}
26083(@pxref{Auto-loading safe path}).
26084
bf88dd68
JK
26085For these reasons, @value{GDBN} includes commands and options to let you
26086control when to auto-load files and which files should be auto-loaded.
26087
26088@table @code
26089@anchor{set auto-load off}
26090@kindex set auto-load off
26091@item set auto-load off
26092Globally disable loading of all auto-loaded files.
26093You may want to use this command with the @samp{-iex} option
26094(@pxref{Option -init-eval-command}) such as:
26095@smallexample
26096$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26097@end smallexample
26098
26099Be aware that system init file (@pxref{System-wide configuration})
26100and init files from your home directory (@pxref{Home Directory Init File})
26101still get read (as they come from generally trusted directories).
26102To prevent @value{GDBN} from auto-loading even those init files, use the
26103@option{-nx} option (@pxref{Mode Options}), in addition to
26104@code{set auto-load no}.
26105
26106@anchor{show auto-load}
26107@kindex show auto-load
26108@item show auto-load
26109Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26110or disabled.
26111
26112@smallexample
26113(gdb) show auto-load
26114gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26115libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
26116local-gdbinit: Auto-loading of .gdbinit script from current directory
26117 is on.
bf88dd68 26118python-scripts: Auto-loading of Python scripts is on.
bccbefd2 26119safe-path: List of directories from which it is safe to auto-load files
1564a261 26120 is $debugdir:$datadir/auto-load.
7349ff92 26121scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 26122 is $debugdir:$datadir/auto-load.
bf88dd68
JK
26123@end smallexample
26124
26125@anchor{info auto-load}
26126@kindex info auto-load
26127@item info auto-load
26128Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26129not.
26130
26131@smallexample
26132(gdb) info auto-load
26133gdb-scripts:
26134Loaded Script
26135Yes /home/user/gdb/gdb-gdb.gdb
26136libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
26137local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26138 loaded.
bf88dd68
JK
26139python-scripts:
26140Loaded Script
26141Yes /home/user/gdb/gdb-gdb.py
26142@end smallexample
26143@end table
26144
bf88dd68
JK
26145These are @value{GDBN} control commands for the auto-loading:
26146
26147@multitable @columnfractions .5 .5
26148@item @xref{set auto-load off}.
26149@tab Disable auto-loading globally.
26150@item @xref{show auto-load}.
26151@tab Show setting of all kinds of files.
26152@item @xref{info auto-load}.
26153@tab Show state of all kinds of files.
26154@item @xref{set auto-load gdb-scripts}.
26155@tab Control for @value{GDBN} command scripts.
26156@item @xref{show auto-load gdb-scripts}.
26157@tab Show setting of @value{GDBN} command scripts.
26158@item @xref{info auto-load gdb-scripts}.
26159@tab Show state of @value{GDBN} command scripts.
26160@item @xref{set auto-load python-scripts}.
26161@tab Control for @value{GDBN} Python scripts.
26162@item @xref{show auto-load python-scripts}.
26163@tab Show setting of @value{GDBN} Python scripts.
26164@item @xref{info auto-load python-scripts}.
26165@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
26166@item @xref{set auto-load guile-scripts}.
26167@tab Control for @value{GDBN} Guile scripts.
26168@item @xref{show auto-load guile-scripts}.
26169@tab Show setting of @value{GDBN} Guile scripts.
26170@item @xref{info auto-load guile-scripts}.
26171@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
26172@item @xref{set auto-load scripts-directory}.
26173@tab Control for @value{GDBN} auto-loaded scripts location.
26174@item @xref{show auto-load scripts-directory}.
26175@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
26176@item @xref{add-auto-load-scripts-directory}.
26177@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
26178@item @xref{set auto-load local-gdbinit}.
26179@tab Control for init file in the current directory.
26180@item @xref{show auto-load local-gdbinit}.
26181@tab Show setting of init file in the current directory.
26182@item @xref{info auto-load local-gdbinit}.
26183@tab Show state of init file in the current directory.
26184@item @xref{set auto-load libthread-db}.
26185@tab Control for thread debugging library.
26186@item @xref{show auto-load libthread-db}.
26187@tab Show setting of thread debugging library.
26188@item @xref{info auto-load libthread-db}.
26189@tab Show state of thread debugging library.
bccbefd2
JK
26190@item @xref{set auto-load safe-path}.
26191@tab Control directories trusted for automatic loading.
26192@item @xref{show auto-load safe-path}.
26193@tab Show directories trusted for automatic loading.
26194@item @xref{add-auto-load-safe-path}.
26195@tab Add directory trusted for automatic loading.
bf88dd68
JK
26196@end multitable
26197
bf88dd68
JK
26198@node Init File in the Current Directory
26199@subsection Automatically loading init file in the current directory
26200@cindex auto-loading init file in the current directory
26201
26202By default, @value{GDBN} reads and executes the canned sequences of commands
26203from init file (if any) in the current working directory,
26204see @ref{Init File in the Current Directory during Startup}.
26205
c1668e4e
JK
26206Note that loading of this local @file{.gdbinit} file also requires accordingly
26207configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26208
bf88dd68
JK
26209@table @code
26210@anchor{set auto-load local-gdbinit}
26211@kindex set auto-load local-gdbinit
26212@item set auto-load local-gdbinit [on|off]
26213Enable or disable the auto-loading of canned sequences of commands
26214(@pxref{Sequences}) found in init file in the current directory.
26215
26216@anchor{show auto-load local-gdbinit}
26217@kindex show auto-load local-gdbinit
26218@item show auto-load local-gdbinit
26219Show whether auto-loading of canned sequences of commands from init file in the
26220current directory is enabled or disabled.
26221
26222@anchor{info auto-load local-gdbinit}
26223@kindex info auto-load local-gdbinit
26224@item info auto-load local-gdbinit
26225Print whether canned sequences of commands from init file in the
26226current directory have been auto-loaded.
26227@end table
26228
26229@node libthread_db.so.1 file
26230@subsection Automatically loading thread debugging library
26231@cindex auto-loading libthread_db.so.1
26232
26233This feature is currently present only on @sc{gnu}/Linux native hosts.
26234
26235@value{GDBN} reads in some cases thread debugging library from places specific
26236to the inferior (@pxref{set libthread-db-search-path}).
26237
26238The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26239without checking this @samp{set auto-load libthread-db} switch as system
26240libraries have to be trusted in general. In all other cases of
26241@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26242auto-load libthread-db} is enabled before trying to open such thread debugging
26243library.
26244
c1668e4e
JK
26245Note that loading of this debugging library also requires accordingly configured
26246@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26247
bf88dd68
JK
26248@table @code
26249@anchor{set auto-load libthread-db}
26250@kindex set auto-load libthread-db
26251@item set auto-load libthread-db [on|off]
26252Enable or disable the auto-loading of inferior specific thread debugging library.
26253
26254@anchor{show auto-load libthread-db}
26255@kindex show auto-load libthread-db
26256@item show auto-load libthread-db
26257Show whether auto-loading of inferior specific thread debugging library is
26258enabled or disabled.
26259
26260@anchor{info auto-load libthread-db}
26261@kindex info auto-load libthread-db
26262@item info auto-load libthread-db
26263Print the list of all loaded inferior specific thread debugging libraries and
26264for each such library print list of inferior @var{pid}s using it.
26265@end table
26266
bccbefd2
JK
26267@node Auto-loading safe path
26268@subsection Security restriction for auto-loading
26269@cindex auto-loading safe-path
26270
26271As the files of inferior can come from untrusted source (such as submitted by
26272an application user) @value{GDBN} does not always load any files automatically.
26273@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26274directories trusted for loading files not explicitly requested by user.
202cbf1c 26275Each directory can also be a shell wildcard pattern.
bccbefd2
JK
26276
26277If the path is not set properly you will see a warning and the file will not
26278get loaded:
26279
26280@smallexample
26281$ ./gdb -q ./gdb
0bab6cf1 26282Reading symbols from /home/user/gdb/gdb...
bccbefd2 26283warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
26284 declined by your `auto-load safe-path' set
26285 to "$debugdir:$datadir/auto-load".
bccbefd2 26286warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
26287 declined by your `auto-load safe-path' set
26288 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
26289@end smallexample
26290
2c91021c
JK
26291@noindent
26292To instruct @value{GDBN} to go ahead and use the init files anyway,
26293invoke @value{GDBN} like this:
26294
26295@smallexample
26296$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26297@end smallexample
26298
bccbefd2
JK
26299The list of trusted directories is controlled by the following commands:
26300
26301@table @code
26302@anchor{set auto-load safe-path}
26303@kindex set auto-load safe-path
af2c1515 26304@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
26305Set the list of directories (and their subdirectories) trusted for automatic
26306loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
26307Each directory can also be a shell wildcard pattern; wildcards do not match
26308directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26309(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
26310If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26311its default value as specified during @value{GDBN} compilation.
26312
d9242c17 26313The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
26314systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26315to the @env{PATH} environment variable.
26316
26317@anchor{show auto-load safe-path}
26318@kindex show auto-load safe-path
26319@item show auto-load safe-path
26320Show the list of directories trusted for automatic loading and execution of
26321scripts.
26322
26323@anchor{add-auto-load-safe-path}
26324@kindex add-auto-load-safe-path
26325@item add-auto-load-safe-path
413b59ae
JK
26326Add an entry (or list of entries) to the list of directories trusted for
26327automatic loading and execution of scripts. Multiple entries may be delimited
26328by the host platform path separator in use.
bccbefd2
JK
26329@end table
26330
7349ff92 26331This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
26332to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26333substitution applies the same as for @ref{set auto-load scripts-directory}.
26334The default @code{set auto-load safe-path} value can be also overriden by
26335@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 26336
6dea1fbd
JK
26337Setting this variable to @file{/} disables this security protection,
26338corresponding @value{GDBN} configuration option is
26339@option{--without-auto-load-safe-path}.
bccbefd2
JK
26340This variable is supposed to be set to the system directories writable by the
26341system superuser only. Users can add their source directories in init files in
26342their home directories (@pxref{Home Directory Init File}). See also deprecated
26343init file in the current directory
26344(@pxref{Init File in the Current Directory during Startup}).
26345
26346To force @value{GDBN} to load the files it declined to load in the previous
26347example, you could use one of the following ways:
26348
0511cc75
JK
26349@table @asis
26350@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26351Specify this trusted directory (or a file) as additional component of the list.
26352You have to specify also any existing directories displayed by
26353by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26354
174bb630 26355@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26356Specify this directory as in the previous case but just for a single
26357@value{GDBN} session.
26358
af2c1515 26359@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26360Disable auto-loading safety for a single @value{GDBN} session.
26361This assumes all the files you debug during this @value{GDBN} session will come
26362from trusted sources.
26363
26364@item @kbd{./configure --without-auto-load-safe-path}
26365During compilation of @value{GDBN} you may disable any auto-loading safety.
26366This assumes all the files you will ever debug with this @value{GDBN} come from
26367trusted sources.
0511cc75 26368@end table
bccbefd2
JK
26369
26370On the other hand you can also explicitly forbid automatic files loading which
26371also suppresses any such warning messages:
26372
0511cc75 26373@table @asis
174bb630 26374@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26375You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26376
0511cc75 26377@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26378Disable auto-loading globally for the user
26379(@pxref{Home Directory Init File}). While it is improbable, you could also
26380use system init file instead (@pxref{System-wide configuration}).
0511cc75 26381@end table
bccbefd2
JK
26382
26383This setting applies to the file names as entered by user. If no entry matches
26384@value{GDBN} tries as a last resort to also resolve all the file names into
26385their canonical form (typically resolving symbolic links) and compare the
26386entries again. @value{GDBN} already canonicalizes most of the filenames on its
26387own before starting the comparison so a canonical form of directories is
26388recommended to be entered.
26389
4dc84fd1
JK
26390@node Auto-loading verbose mode
26391@subsection Displaying files tried for auto-load
26392@cindex auto-loading verbose mode
26393
26394For better visibility of all the file locations where you can place scripts to
26395be auto-loaded with inferior --- or to protect yourself against accidental
26396execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26397all the files attempted to be loaded. Both existing and non-existing files may
26398be printed.
26399
26400For example the list of directories from which it is safe to auto-load files
26401(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26402may not be too obvious while setting it up.
26403
26404@smallexample
0070f25a 26405(gdb) set debug auto-load on
4dc84fd1
JK
26406(gdb) file ~/src/t/true
26407auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26408 for objfile "/tmp/true".
26409auto-load: Updating directories of "/usr:/opt".
26410auto-load: Using directory "/usr".
26411auto-load: Using directory "/opt".
26412warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26413 by your `auto-load safe-path' set to "/usr:/opt".
26414@end smallexample
26415
26416@table @code
26417@anchor{set debug auto-load}
26418@kindex set debug auto-load
26419@item set debug auto-load [on|off]
26420Set whether to print the filenames attempted to be auto-loaded.
26421
26422@anchor{show debug auto-load}
26423@kindex show debug auto-load
26424@item show debug auto-load
26425Show whether printing of the filenames attempted to be auto-loaded is turned
26426on or off.
26427@end table
26428
8e04817f 26429@node Messages/Warnings
79a6e687 26430@section Optional Warnings and Messages
104c1213 26431
9c16f35a
EZ
26432@cindex verbose operation
26433@cindex optional warnings
8e04817f
AC
26434By default, @value{GDBN} is silent about its inner workings. If you are
26435running on a slow machine, you may want to use the @code{set verbose}
26436command. This makes @value{GDBN} tell you when it does a lengthy
26437internal operation, so you will not think it has crashed.
104c1213 26438
8e04817f
AC
26439Currently, the messages controlled by @code{set verbose} are those
26440which announce that the symbol table for a source file is being read;
79a6e687 26441see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26442
8e04817f
AC
26443@table @code
26444@kindex set verbose
26445@item set verbose on
26446Enables @value{GDBN} output of certain informational messages.
104c1213 26447
8e04817f
AC
26448@item set verbose off
26449Disables @value{GDBN} output of certain informational messages.
104c1213 26450
8e04817f
AC
26451@kindex show verbose
26452@item show verbose
26453Displays whether @code{set verbose} is on or off.
26454@end table
104c1213 26455
8e04817f
AC
26456By default, if @value{GDBN} encounters bugs in the symbol table of an
26457object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26458find this information useful (@pxref{Symbol Errors, ,Errors Reading
26459Symbol Files}).
104c1213 26460
8e04817f 26461@table @code
104c1213 26462
8e04817f
AC
26463@kindex set complaints
26464@item set complaints @var{limit}
26465Permits @value{GDBN} to output @var{limit} complaints about each type of
26466unusual symbols before becoming silent about the problem. Set
26467@var{limit} to zero to suppress all complaints; set it to a large number
26468to prevent complaints from being suppressed.
104c1213 26469
8e04817f
AC
26470@kindex show complaints
26471@item show complaints
26472Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26473
8e04817f 26474@end table
104c1213 26475
d837706a 26476@anchor{confirmation requests}
8e04817f
AC
26477By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26478lot of stupid questions to confirm certain commands. For example, if
26479you try to run a program which is already running:
104c1213 26480
474c8240 26481@smallexample
8e04817f
AC
26482(@value{GDBP}) run
26483The program being debugged has been started already.
26484Start it from the beginning? (y or n)
474c8240 26485@end smallexample
104c1213 26486
8e04817f
AC
26487If you are willing to unflinchingly face the consequences of your own
26488commands, you can disable this ``feature'':
104c1213 26489
8e04817f 26490@table @code
104c1213 26491
8e04817f
AC
26492@kindex set confirm
26493@cindex flinching
26494@cindex confirmation
26495@cindex stupid questions
26496@item set confirm off
7c953934
TT
26497Disables confirmation requests. Note that running @value{GDBN} with
26498the @option{--batch} option (@pxref{Mode Options, -batch}) also
26499automatically disables confirmation requests.
104c1213 26500
8e04817f
AC
26501@item set confirm on
26502Enables confirmation requests (the default).
104c1213 26503
8e04817f
AC
26504@kindex show confirm
26505@item show confirm
26506Displays state of confirmation requests.
26507
26508@end table
104c1213 26509
16026cd7
AS
26510@cindex command tracing
26511If you need to debug user-defined commands or sourced files you may find it
26512useful to enable @dfn{command tracing}. In this mode each command will be
26513printed as it is executed, prefixed with one or more @samp{+} symbols, the
26514quantity denoting the call depth of each command.
26515
26516@table @code
26517@kindex set trace-commands
26518@cindex command scripts, debugging
26519@item set trace-commands on
26520Enable command tracing.
26521@item set trace-commands off
26522Disable command tracing.
26523@item show trace-commands
26524Display the current state of command tracing.
26525@end table
26526
8e04817f 26527@node Debugging Output
79a6e687 26528@section Optional Messages about Internal Happenings
4644b6e3
EZ
26529@cindex optional debugging messages
26530
da316a69
EZ
26531@value{GDBN} has commands that enable optional debugging messages from
26532various @value{GDBN} subsystems; normally these commands are of
26533interest to @value{GDBN} maintainers, or when reporting a bug. This
26534section documents those commands.
26535
104c1213 26536@table @code
a8f24a35
EZ
26537@kindex set exec-done-display
26538@item set exec-done-display
26539Turns on or off the notification of asynchronous commands'
26540completion. When on, @value{GDBN} will print a message when an
26541asynchronous command finishes its execution. The default is off.
26542@kindex show exec-done-display
26543@item show exec-done-display
26544Displays the current setting of asynchronous command completion
26545notification.
7b085b1c 26546
4644b6e3 26547@kindex set debug
be9a8770
PA
26548@cindex ARM AArch64
26549@item set debug aarch64
26550Turns on or off display of debugging messages related to ARM AArch64.
26551The default is off.
26552@kindex show debug
26553@item show debug aarch64
26554Displays the current state of displaying debugging messages related to
26555ARM AArch64.
7b085b1c 26556
4644b6e3 26557@cindex gdbarch debugging info
a8f24a35 26558@cindex architecture debugging info
8e04817f 26559@item set debug arch
a8f24a35 26560Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26561@item show debug arch
26562Displays the current state of displaying gdbarch debugging info.
7b085b1c 26563
9a005eb9
JB
26564@item set debug aix-solib
26565@cindex AIX shared library debugging
26566Control display of debugging messages from the AIX shared library
26567support module. The default is off.
7b085b1c 26568@item show debug aix-solib
9a005eb9 26569Show the current state of displaying AIX shared library debugging messages.
7b085b1c 26570
721c2651
EZ
26571@item set debug aix-thread
26572@cindex AIX threads
26573Display debugging messages about inner workings of the AIX thread
26574module.
26575@item show debug aix-thread
26576Show the current state of AIX thread debugging info display.
7b085b1c 26577
900e11f9
JK
26578@item set debug check-physname
26579@cindex physname
26580Check the results of the ``physname'' computation. When reading DWARF
26581debugging information for C@t{++}, @value{GDBN} attempts to compute
26582each entity's name. @value{GDBN} can do this computation in two
26583different ways, depending on exactly what information is present.
26584When enabled, this setting causes @value{GDBN} to compute the names
26585both ways and display any discrepancies.
26586@item show debug check-physname
26587Show the current state of ``physname'' checking.
7b085b1c 26588
be9a8770
PA
26589@item set debug coff-pe-read
26590@cindex COFF/PE exported symbols
26591Control display of debugging messages related to reading of COFF/PE
26592exported symbols. The default is off.
26593@item show debug coff-pe-read
26594Displays the current state of displaying debugging messages related to
26595reading of COFF/PE exported symbols.
7b085b1c 26596
b4f54984
DE
26597@item set debug dwarf-die
26598@cindex DWARF DIEs
26599Dump DWARF DIEs after they are read in.
d97bc12b
DE
26600The value is the number of nesting levels to print.
26601A value of zero turns off the display.
b4f54984
DE
26602@item show debug dwarf-die
26603Show the current state of DWARF DIE debugging.
7b085b1c 26604
27e0867f
DE
26605@item set debug dwarf-line
26606@cindex DWARF Line Tables
26607Turns on or off display of debugging messages related to reading
26608DWARF line tables. The default is 0 (off).
26609A value of 1 provides basic information.
26610A value greater than 1 provides more verbose information.
26611@item show debug dwarf-line
26612Show the current state of DWARF line table debugging.
7b085b1c 26613
b4f54984
DE
26614@item set debug dwarf-read
26615@cindex DWARF Reading
45cfd468 26616Turns on or off display of debugging messages related to reading
73be47f5
DE
26617DWARF debug info. The default is 0 (off).
26618A value of 1 provides basic information.
26619A value greater than 1 provides more verbose information.
b4f54984
DE
26620@item show debug dwarf-read
26621Show the current state of DWARF reader debugging.
7b085b1c 26622
237fc4c9
PA
26623@item set debug displaced
26624@cindex displaced stepping debugging info
26625Turns on or off display of @value{GDBN} debugging info for the
26626displaced stepping support. The default is off.
26627@item show debug displaced
26628Displays the current state of displaying @value{GDBN} debugging info
26629related to displaced stepping.
7b085b1c 26630
8e04817f 26631@item set debug event
4644b6e3 26632@cindex event debugging info
a8f24a35 26633Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26634default is off.
8e04817f
AC
26635@item show debug event
26636Displays the current state of displaying @value{GDBN} event debugging
26637info.
7b085b1c 26638
8d378f27
SM
26639@item set debug event-loop
26640@cindex event-loop debugging
26641Controls output of debugging info about the event loop. The possible
26642values are @samp{off}, @samp{all} (shows all debugging info) and
26643@samp{all-except-ui} (shows all debugging info except those about
26644UI-related events).
26645@item show debug event-loop
26646Shows the current state of displaying debugging info about the event
26647loop.
26648
8e04817f 26649@item set debug expression
4644b6e3 26650@cindex expression debugging info
721c2651
EZ
26651Turns on or off display of debugging info about @value{GDBN}
26652expression parsing. The default is off.
8e04817f 26653@item show debug expression
721c2651
EZ
26654Displays the current state of displaying debugging info about
26655@value{GDBN} expression parsing.
7b085b1c 26656
6e9567fe
JB
26657@item set debug fbsd-lwp
26658@cindex FreeBSD LWP debug messages
26659Turns on or off debugging messages from the FreeBSD LWP debug support.
26660@item show debug fbsd-lwp
26661Show the current state of FreeBSD LWP debugging messages.
7b085b1c 26662
386a8676
JB
26663@item set debug fbsd-nat
26664@cindex FreeBSD native target debug messages
26665Turns on or off debugging messages from the FreeBSD native target.
26666@item show debug fbsd-nat
26667Show the current state of FreeBSD native target debugging messages.
7b085b1c 26668
a5c641b5
AB
26669@item set debug fortran-array-slicing
26670@cindex fortran array slicing debugging info
26671Turns on or off display of @value{GDBN} Fortran array slicing
26672debugging info. The default is off.
26673
26674@item show debug fortran-array-slicing
26675Displays the current state of displaying @value{GDBN} Fortran array
26676slicing debugging info.
26677
7453dc06 26678@item set debug frame
4644b6e3 26679@cindex frame debugging info
7453dc06
AC
26680Turns on or off display of @value{GDBN} frame debugging info. The
26681default is off.
7453dc06
AC
26682@item show debug frame
26683Displays the current state of displaying @value{GDBN} frame debugging
26684info.
7b085b1c 26685
cbe54154
PA
26686@item set debug gnu-nat
26687@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26688Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26689@item show debug gnu-nat
26690Show the current state of @sc{gnu}/Hurd debugging messages.
7b085b1c 26691
30e91e0b
RC
26692@item set debug infrun
26693@cindex inferior debugging info
26694Turns on or off display of @value{GDBN} debugging info for running the inferior.
26695The default is off. @file{infrun.c} contains GDB's runtime state machine used
26696for implementing operations such as single-stepping the inferior.
26697@item show debug infrun
26698Displays the current state of @value{GDBN} inferior debugging.
7b085b1c 26699
a255712f
PP
26700@item set debug jit
26701@cindex just-in-time compilation, debugging messages
67ebd9cb 26702Turn on or off debugging messages from JIT debug support.
a255712f
PP
26703@item show debug jit
26704Displays the current state of @value{GDBN} JIT debugging.
7b085b1c 26705
da316a69
EZ
26706@item set debug lin-lwp
26707@cindex @sc{gnu}/Linux LWP debug messages
26708@cindex Linux lightweight processes
67ebd9cb 26709Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26710@item show debug lin-lwp
26711Show the current state of Linux LWP debugging messages.
7b085b1c 26712
7a6a1731
GB
26713@item set debug linux-namespaces
26714@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26715Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26716@item show debug linux-namespaces
26717Show the current state of Linux namespaces debugging messages.
7b085b1c 26718
be9a8770
PA
26719@item set debug mach-o
26720@cindex Mach-O symbols processing
26721Control display of debugging messages related to Mach-O symbols
26722processing. The default is off.
26723@item show debug mach-o
26724Displays the current state of displaying debugging messages related to
26725reading of COFF/PE exported symbols.
7b085b1c 26726
c9b6281a
YQ
26727@item set debug notification
26728@cindex remote async notification debugging info
67ebd9cb 26729Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26730The default is off.
26731@item show debug notification
26732Displays the current state of remote async notification debugging messages.
7b085b1c 26733
2b4855ab 26734@item set debug observer
4644b6e3 26735@cindex observer debugging info
2b4855ab
AC
26736Turns on or off display of @value{GDBN} observer debugging. This
26737includes info such as the notification of observable events.
2b4855ab
AC
26738@item show debug observer
26739Displays the current state of observer debugging.
7b085b1c 26740
8e04817f 26741@item set debug overload
4644b6e3 26742@cindex C@t{++} overload debugging info
8e04817f 26743Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26744info. This includes info such as ranking of functions, etc. The default
8e04817f 26745is off.
8e04817f
AC
26746@item show debug overload
26747Displays the current state of displaying @value{GDBN} C@t{++} overload
26748debugging info.
7b085b1c 26749
92981e24
TT
26750@cindex expression parser, debugging info
26751@cindex debug expression parser
26752@item set debug parser
26753Turns on or off the display of expression parser debugging output.
26754Internally, this sets the @code{yydebug} variable in the expression
26755parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26756details. The default is off.
26757@item show debug parser
26758Show the current state of expression parser debugging.
7b085b1c 26759
8e04817f
AC
26760@cindex packets, reporting on stdout
26761@cindex serial connections, debugging
605a56cb
DJ
26762@cindex debug remote protocol
26763@cindex remote protocol debugging
26764@cindex display remote packets
8e04817f
AC
26765@item set debug remote
26766Turns on or off display of reports on all packets sent back and forth across
26767the serial line to the remote machine. The info is printed on the
26768@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26769@item show debug remote
26770Displays the state of display of remote packets.
c4dcb155 26771
6cc8564b
LM
26772@item set debug remote-packet-max-chars
26773Sets the maximum number of characters to display for each remote packet when
26774@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26775displaying lengthy remote packets and polluting the console.
26776
26777The default value is @code{512}, which means @value{GDBN} will truncate each
26778remote packet after 512 bytes.
26779
26780Setting this option to @code{unlimited} will disable truncation and will output
26781the full length of the remote packets.
26782@item show debug remote-packet-max-chars
26783Displays the number of bytes to output for remote packet debugging.
26784
c4dcb155
SM
26785@item set debug separate-debug-file
26786Turns on or off display of debug output about separate debug file search.
26787@item show debug separate-debug-file
26788Displays the state of separate debug file search debug output.
26789
8e04817f
AC
26790@item set debug serial
26791Turns on or off display of @value{GDBN} serial debugging info. The
26792default is off.
8e04817f
AC
26793@item show debug serial
26794Displays the current state of displaying @value{GDBN} serial debugging
26795info.
7b085b1c 26796
c45da7e6
EZ
26797@item set debug solib-frv
26798@cindex FR-V shared-library debugging
67ebd9cb 26799Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26800@item show debug solib-frv
26801Display the current state of FR-V shared-library code debugging
26802messages.
7b085b1c 26803
cc485e62
DE
26804@item set debug symbol-lookup
26805@cindex symbol lookup
26806Turns on or off display of debugging messages related to symbol lookup.
26807The default is 0 (off).
26808A value of 1 provides basic information.
26809A value greater than 1 provides more verbose information.
26810@item show debug symbol-lookup
26811Show the current state of symbol lookup debugging messages.
7b085b1c 26812
8fb8eb5c
DE
26813@item set debug symfile
26814@cindex symbol file functions
26815Turns on or off display of debugging messages related to symbol file functions.
26816The default is off. @xref{Files}.
26817@item show debug symfile
26818Show the current state of symbol file debugging messages.
7b085b1c 26819
45cfd468
DE
26820@item set debug symtab-create
26821@cindex symbol table creation
26822Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26823The default is 0 (off).
26824A value of 1 provides basic information.
26825A value greater than 1 provides more verbose information.
45cfd468
DE
26826@item show debug symtab-create
26827Show the current state of symbol table creation debugging.
7b085b1c 26828
8e04817f 26829@item set debug target
4644b6e3 26830@cindex target debugging info
8e04817f
AC
26831Turns on or off display of @value{GDBN} target debugging info. This info
26832includes what is going on at the target level of GDB, as it happens. The
701b08bb 26833default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26834value of large memory transfers.
8e04817f
AC
26835@item show debug target
26836Displays the current state of displaying @value{GDBN} target debugging
26837info.
7b085b1c 26838
75feb17d 26839@item set debug timestamp
6b92c0d3 26840@cindex timestamping debugging info
75feb17d
DJ
26841Turns on or off display of timestamps with @value{GDBN} debugging info.
26842When enabled, seconds and microseconds are displayed before each debugging
26843message.
26844@item show debug timestamp
26845Displays the current state of displaying timestamps with @value{GDBN}
26846debugging info.
7b085b1c 26847
f989a1c8 26848@item set debug varobj
4644b6e3 26849@cindex variable object debugging info
8e04817f
AC
26850Turns on or off display of @value{GDBN} variable object debugging
26851info. The default is off.
f989a1c8 26852@item show debug varobj
8e04817f
AC
26853Displays the current state of displaying @value{GDBN} variable object
26854debugging info.
7b085b1c 26855
e776119f
DJ
26856@item set debug xml
26857@cindex XML parser debugging
67ebd9cb 26858Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26859@item show debug xml
26860Displays the current state of XML debugging messages.
8e04817f 26861@end table
104c1213 26862
14fb1bac
JB
26863@node Other Misc Settings
26864@section Other Miscellaneous Settings
26865@cindex miscellaneous settings
26866
26867@table @code
26868@kindex set interactive-mode
26869@item set interactive-mode
7bfc9434
JB
26870If @code{on}, forces @value{GDBN} to assume that GDB was started
26871in a terminal. In practice, this means that @value{GDBN} should wait
26872for the user to answer queries generated by commands entered at
26873the command prompt. If @code{off}, forces @value{GDBN} to operate
26874in the opposite mode, and it uses the default answers to all queries.
26875If @code{auto} (the default), @value{GDBN} tries to determine whether
26876its standard input is a terminal, and works in interactive-mode if it
26877is, non-interactively otherwise.
14fb1bac
JB
26878
26879In the vast majority of cases, the debugger should be able to guess
26880correctly which mode should be used. But this setting can be useful
26881in certain specific cases, such as running a MinGW @value{GDBN}
26882inside a cygwin window.
26883
26884@kindex show interactive-mode
26885@item show interactive-mode
26886Displays whether the debugger is operating in interactive mode or not.
26887@end table
26888
d57a3c85
TJB
26889@node Extending GDB
26890@chapter Extending @value{GDBN}
26891@cindex extending GDB
26892
71b8c845
DE
26893@value{GDBN} provides several mechanisms for extension.
26894@value{GDBN} also provides the ability to automatically load
26895extensions when it reads a file for debugging. This allows the
26896user to automatically customize @value{GDBN} for the program
26897being debugged.
d57a3c85 26898
71b8c845
DE
26899@menu
26900* Sequences:: Canned Sequences of @value{GDBN} Commands
26901* Python:: Extending @value{GDBN} using Python
ed3ef339 26902* Guile:: Extending @value{GDBN} using Guile
71b8c845 26903* Auto-loading extensions:: Automatically loading extensions
ed3ef339 26904* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
26905* Aliases:: Creating new spellings of existing commands
26906@end menu
26907
26908To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26909of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26910can recognize which extension language is being used by looking at
95433b34
JB
26911the filename extension. Files with an unrecognized filename extension
26912are always treated as a @value{GDBN} Command Files.
26913@xref{Command Files,, Command files}.
26914
26915You can control how @value{GDBN} evaluates these files with the following
26916setting:
26917
26918@table @code
26919@kindex set script-extension
26920@kindex show script-extension
26921@item set script-extension off
26922All scripts are always evaluated as @value{GDBN} Command Files.
26923
26924@item set script-extension soft
26925The debugger determines the scripting language based on filename
26926extension. If this scripting language is supported, @value{GDBN}
26927evaluates the script using that language. Otherwise, it evaluates
26928the file as a @value{GDBN} Command File.
26929
26930@item set script-extension strict
26931The debugger determines the scripting language based on filename
26932extension, and evaluates the script using that language. If the
26933language is not supported, then the evaluation fails.
26934
26935@item show script-extension
26936Display the current value of the @code{script-extension} option.
26937
26938@end table
26939
ed2a2229
CB
26940@ifset SYSTEM_GDBINIT_DIR
26941This setting is not used for files in the system-wide gdbinit directory.
26942Files in that directory must have an extension matching their language,
26943or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26944commands. @xref{Startup}.
26945@end ifset
26946
8e04817f 26947@node Sequences
d57a3c85 26948@section Canned Sequences of Commands
104c1213 26949
8e04817f 26950Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26951Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26952commands for execution as a unit: user-defined commands and command
26953files.
104c1213 26954
8e04817f 26955@menu
fcc73fe3
EZ
26956* Define:: How to define your own commands
26957* Hooks:: Hooks for user-defined commands
26958* Command Files:: How to write scripts of commands to be stored in a file
26959* Output:: Commands for controlled output
71b8c845 26960* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26961@end menu
104c1213 26962
8e04817f 26963@node Define
d57a3c85 26964@subsection User-defined Commands
104c1213 26965
8e04817f 26966@cindex user-defined command
fcc73fe3 26967@cindex arguments, to user-defined commands
8e04817f
AC
26968A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26969which you assign a new name as a command. This is done with the
df3ee9ca 26970@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26971separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26972via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26973
8e04817f
AC
26974@smallexample
26975define adder
26976 print $arg0 + $arg1 + $arg2
c03c782f 26977end
8e04817f 26978@end smallexample
104c1213
JM
26979
26980@noindent
8e04817f 26981To execute the command use:
104c1213 26982
8e04817f
AC
26983@smallexample
26984adder 1 2 3
26985@end smallexample
104c1213 26986
8e04817f
AC
26987@noindent
26988This defines the command @code{adder}, which prints the sum of
26989its three arguments. Note the arguments are text substitutions, so they may
26990reference variables, use complex expressions, or even perform inferior
26991functions calls.
104c1213 26992
fcc73fe3
EZ
26993@cindex argument count in user-defined commands
26994@cindex how many arguments (user-defined commands)
c03c782f 26995In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26996been passed.
c03c782f
AS
26997
26998@smallexample
26999define adder
27000 if $argc == 2
27001 print $arg0 + $arg1
27002 end
27003 if $argc == 3
27004 print $arg0 + $arg1 + $arg2
27005 end
27006end
27007@end smallexample
27008
01770bbd
PA
27009Combining with the @code{eval} command (@pxref{eval}) makes it easier
27010to process a variable number of arguments:
27011
27012@smallexample
27013define adder
27014 set $i = 0
27015 set $sum = 0
27016 while $i < $argc
27017 eval "set $sum = $sum + $arg%d", $i
27018 set $i = $i + 1
27019 end
27020 print $sum
27021end
27022@end smallexample
27023
104c1213 27024@table @code
104c1213 27025
8e04817f
AC
27026@kindex define
27027@item define @var{commandname}
27028Define a command named @var{commandname}. If there is already a command
27029by that name, you are asked to confirm that you want to redefine it.
697aa1b7 27030The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
27031numbers, dashes, dots, and underscores. It may also start with any
27032predefined or user-defined prefix command.
27033For example, @samp{define target my-target} creates
adb483fe 27034a user-defined @samp{target my-target} command.
104c1213 27035
8e04817f
AC
27036The definition of the command is made up of other @value{GDBN} command lines,
27037which are given following the @code{define} command. The end of these
27038commands is marked by a line containing @code{end}.
104c1213 27039
8e04817f 27040@kindex document
ca91424e 27041@kindex end@r{ (user-defined commands)}
8e04817f
AC
27042@item document @var{commandname}
27043Document the user-defined command @var{commandname}, so that it can be
27044accessed by @code{help}. The command @var{commandname} must already be
27045defined. This command reads lines of documentation just as @code{define}
27046reads the lines of the command definition, ending with @code{end}.
27047After the @code{document} command is finished, @code{help} on command
27048@var{commandname} displays the documentation you have written.
104c1213 27049
8e04817f
AC
27050You may use the @code{document} command again to change the
27051documentation of a command. Redefining the command with @code{define}
27052does not change the documentation.
104c1213 27053
bf498525
PW
27054@kindex define-prefix
27055@item define-prefix @var{commandname}
27056Define or mark the command @var{commandname} as a user-defined prefix
27057command. Once marked, @var{commandname} can be used as prefix command
27058by the @code{define} command.
27059Note that @code{define-prefix} can be used with a not yet defined
27060@var{commandname}. In such a case, @var{commandname} is defined as
27061an empty user-defined command.
27062In case you redefine a command that was marked as a user-defined
27063prefix command, the subcommands of the redefined command are kept
27064(and @value{GDBN} indicates so to the user).
27065
27066Example:
27067@example
27068(gdb) define-prefix abc
27069(gdb) define-prefix abc def
27070(gdb) define abc def
27071Type commands for definition of "abc def".
27072End with a line saying just "end".
27073>echo command initial def\n
27074>end
27075(gdb) define abc def ghi
27076Type commands for definition of "abc def ghi".
27077End with a line saying just "end".
27078>echo command ghi\n
27079>end
27080(gdb) define abc def
27081Keeping subcommands of prefix command "def".
27082Redefine command "def"? (y or n) y
27083Type commands for definition of "abc def".
27084End with a line saying just "end".
27085>echo command def\n
27086>end
27087(gdb) abc def ghi
27088command ghi
27089(gdb) abc def
27090command def
27091(gdb)
27092@end example
27093
c45da7e6
EZ
27094@kindex dont-repeat
27095@cindex don't repeat command
27096@item dont-repeat
27097Used inside a user-defined command, this tells @value{GDBN} that this
27098command should not be repeated when the user hits @key{RET}
27099(@pxref{Command Syntax, repeat last command}).
27100
8e04817f
AC
27101@kindex help user-defined
27102@item help user-defined
7d74f244 27103List all user-defined commands and all python commands defined in class
6b92c0d3 27104COMMAND_USER. The first line of the documentation or docstring is
7d74f244 27105included (if any).
104c1213 27106
8e04817f
AC
27107@kindex show user
27108@item show user
27109@itemx show user @var{commandname}
27110Display the @value{GDBN} commands used to define @var{commandname} (but
27111not its documentation). If no @var{commandname} is given, display the
27112definitions for all user-defined commands.
7d74f244 27113This does not work for user-defined python commands.
104c1213 27114
fcc73fe3 27115@cindex infinite recursion in user-defined commands
20f01a46
DH
27116@kindex show max-user-call-depth
27117@kindex set max-user-call-depth
27118@item show max-user-call-depth
5ca0cb28
DH
27119@itemx set max-user-call-depth
27120The value of @code{max-user-call-depth} controls how many recursion
3f94c067 27121levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 27122infinite recursion and aborts the command.
7d74f244 27123This does not apply to user-defined python commands.
104c1213
JM
27124@end table
27125
fcc73fe3
EZ
27126In addition to the above commands, user-defined commands frequently
27127use control flow commands, described in @ref{Command Files}.
27128
8e04817f
AC
27129When user-defined commands are executed, the
27130commands of the definition are not printed. An error in any command
27131stops execution of the user-defined command.
104c1213 27132
8e04817f
AC
27133If used interactively, commands that would ask for confirmation proceed
27134without asking when used inside a user-defined command. Many @value{GDBN}
27135commands that normally print messages to say what they are doing omit the
27136messages when used in a user-defined command.
104c1213 27137
8e04817f 27138@node Hooks
d57a3c85 27139@subsection User-defined Command Hooks
8e04817f
AC
27140@cindex command hooks
27141@cindex hooks, for commands
27142@cindex hooks, pre-command
104c1213 27143
8e04817f 27144@kindex hook
8e04817f
AC
27145You may define @dfn{hooks}, which are a special kind of user-defined
27146command. Whenever you run the command @samp{foo}, if the user-defined
27147command @samp{hook-foo} exists, it is executed (with no arguments)
27148before that command.
104c1213 27149
8e04817f
AC
27150@cindex hooks, post-command
27151@kindex hookpost
8e04817f
AC
27152A hook may also be defined which is run after the command you executed.
27153Whenever you run the command @samp{foo}, if the user-defined command
27154@samp{hookpost-foo} exists, it is executed (with no arguments) after
27155that command. Post-execution hooks may exist simultaneously with
27156pre-execution hooks, for the same command.
104c1213 27157
8e04817f 27158It is valid for a hook to call the command which it hooks. If this
9f1c6395 27159occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 27160
8e04817f
AC
27161@c It would be nice if hookpost could be passed a parameter indicating
27162@c if the command it hooks executed properly or not. FIXME!
104c1213 27163
8e04817f
AC
27164@kindex stop@r{, a pseudo-command}
27165In addition, a pseudo-command, @samp{stop} exists. Defining
27166(@samp{hook-stop}) makes the associated commands execute every time
27167execution stops in your program: before breakpoint commands are run,
27168displays are printed, or the stack frame is printed.
104c1213 27169
8e04817f
AC
27170For example, to ignore @code{SIGALRM} signals while
27171single-stepping, but treat them normally during normal execution,
27172you could define:
104c1213 27173
474c8240 27174@smallexample
8e04817f
AC
27175define hook-stop
27176handle SIGALRM nopass
27177end
104c1213 27178
8e04817f
AC
27179define hook-run
27180handle SIGALRM pass
27181end
104c1213 27182
8e04817f 27183define hook-continue
d3e8051b 27184handle SIGALRM pass
8e04817f 27185end
474c8240 27186@end smallexample
104c1213 27187
d3e8051b 27188As a further example, to hook at the beginning and end of the @code{echo}
b383017d 27189command, and to add extra text to the beginning and end of the message,
8e04817f 27190you could define:
104c1213 27191
474c8240 27192@smallexample
8e04817f
AC
27193define hook-echo
27194echo <<<---
27195end
104c1213 27196
8e04817f
AC
27197define hookpost-echo
27198echo --->>>\n
27199end
104c1213 27200
8e04817f
AC
27201(@value{GDBP}) echo Hello World
27202<<<---Hello World--->>>
27203(@value{GDBP})
104c1213 27204
474c8240 27205@end smallexample
104c1213 27206
8e04817f
AC
27207You can define a hook for any single-word command in @value{GDBN}, but
27208not for command aliases; you should define a hook for the basic command
c1468174 27209name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
27210@c FIXME! So how does Joe User discover whether a command is an alias
27211@c or not?
adb483fe
DJ
27212You can hook a multi-word command by adding @code{hook-} or
27213@code{hookpost-} to the last word of the command, e.g.@:
27214@samp{define target hook-remote} to add a hook to @samp{target remote}.
27215
8e04817f
AC
27216If an error occurs during the execution of your hook, execution of
27217@value{GDBN} commands stops and @value{GDBN} issues a prompt
27218(before the command that you actually typed had a chance to run).
104c1213 27219
8e04817f
AC
27220If you try to define a hook which does not match any known command, you
27221get a warning from the @code{define} command.
c906108c 27222
8e04817f 27223@node Command Files
d57a3c85 27224@subsection Command Files
c906108c 27225
8e04817f 27226@cindex command files
fcc73fe3 27227@cindex scripting commands
6fc08d32
EZ
27228A command file for @value{GDBN} is a text file made of lines that are
27229@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27230also be included. An empty line in a command file does nothing; it
27231does not mean to repeat the last command, as it would from the
27232terminal.
c906108c 27233
6fc08d32 27234You can request the execution of a command file with the @code{source}
95433b34
JB
27235command. Note that the @code{source} command is also used to evaluate
27236scripts that are not Command Files. The exact behavior can be configured
27237using the @code{script-extension} setting.
27238@xref{Extending GDB,, Extending GDB}.
c906108c 27239
8e04817f
AC
27240@table @code
27241@kindex source
ca91424e 27242@cindex execute commands from a file
3f7b2faa 27243@item source [-s] [-v] @var{filename}
8e04817f 27244Execute the command file @var{filename}.
c906108c
SS
27245@end table
27246
fcc73fe3
EZ
27247The lines in a command file are generally executed sequentially,
27248unless the order of execution is changed by one of the
27249@emph{flow-control commands} described below. The commands are not
a71ec265
DH
27250printed as they are executed. An error in any command terminates
27251execution of the command file and control is returned to the console.
c906108c 27252
08001717
DE
27253@value{GDBN} first searches for @var{filename} in the current directory.
27254If the file is not found there, and @var{filename} does not specify a
27255directory, then @value{GDBN} also looks for the file on the source search path
27256(specified with the @samp{directory} command);
27257except that @file{$cdir} is not searched because the compilation directory
27258is not relevant to scripts.
4b505b12 27259
3f7b2faa
DE
27260If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27261on the search path even if @var{filename} specifies a directory.
27262The search is done by appending @var{filename} to each element of the
27263search path. So, for example, if @var{filename} is @file{mylib/myscript}
27264and the search path contains @file{/home/user} then @value{GDBN} will
27265look for the script @file{/home/user/mylib/myscript}.
27266The search is also done if @var{filename} is an absolute path.
27267For example, if @var{filename} is @file{/tmp/myscript} and
27268the search path contains @file{/home/user} then @value{GDBN} will
27269look for the script @file{/home/user/tmp/myscript}.
27270For DOS-like systems, if @var{filename} contains a drive specification,
27271it is stripped before concatenation. For example, if @var{filename} is
27272@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27273will look for the script @file{c:/tmp/myscript}.
27274
16026cd7
AS
27275If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27276each command as it is executed. The option must be given before
27277@var{filename}, and is interpreted as part of the filename anywhere else.
27278
8e04817f
AC
27279Commands that would ask for confirmation if used interactively proceed
27280without asking when used in a command file. Many @value{GDBN} commands that
27281normally print messages to say what they are doing omit the messages
27282when called from command files.
c906108c 27283
8e04817f
AC
27284@value{GDBN} also accepts command input from standard input. In this
27285mode, normal output goes to standard output and error output goes to
27286standard error. Errors in a command file supplied on standard input do
6fc08d32 27287not terminate execution of the command file---execution continues with
8e04817f 27288the next command.
c906108c 27289
474c8240 27290@smallexample
8e04817f 27291gdb < cmds > log 2>&1
474c8240 27292@end smallexample
c906108c 27293
8e04817f
AC
27294(The syntax above will vary depending on the shell used.) This example
27295will execute commands from the file @file{cmds}. All output and errors
27296would be directed to @file{log}.
c906108c 27297
fcc73fe3
EZ
27298Since commands stored on command files tend to be more general than
27299commands typed interactively, they frequently need to deal with
27300complicated situations, such as different or unexpected values of
27301variables and symbols, changes in how the program being debugged is
27302built, etc. @value{GDBN} provides a set of flow-control commands to
27303deal with these complexities. Using these commands, you can write
27304complex scripts that loop over data structures, execute commands
27305conditionally, etc.
27306
27307@table @code
27308@kindex if
27309@kindex else
27310@item if
27311@itemx else
27312This command allows to include in your script conditionally executed
27313commands. The @code{if} command takes a single argument, which is an
27314expression to evaluate. It is followed by a series of commands that
27315are executed only if the expression is true (its value is nonzero).
27316There can then optionally be an @code{else} line, followed by a series
27317of commands that are only executed if the expression was false. The
27318end of the list is marked by a line containing @code{end}.
27319
27320@kindex while
27321@item while
27322This command allows to write loops. Its syntax is similar to
27323@code{if}: the command takes a single argument, which is an expression
27324to evaluate, and must be followed by the commands to execute, one per
27325line, terminated by an @code{end}. These commands are called the
27326@dfn{body} of the loop. The commands in the body of @code{while} are
27327executed repeatedly as long as the expression evaluates to true.
27328
27329@kindex loop_break
27330@item loop_break
27331This command exits the @code{while} loop in whose body it is included.
27332Execution of the script continues after that @code{while}s @code{end}
27333line.
27334
27335@kindex loop_continue
27336@item loop_continue
27337This command skips the execution of the rest of the body of commands
27338in the @code{while} loop in whose body it is included. Execution
27339branches to the beginning of the @code{while} loop, where it evaluates
27340the controlling expression.
ca91424e
EZ
27341
27342@kindex end@r{ (if/else/while commands)}
27343@item end
27344Terminate the block of commands that are the body of @code{if},
27345@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
27346@end table
27347
27348
8e04817f 27349@node Output
d57a3c85 27350@subsection Commands for Controlled Output
c906108c 27351
8e04817f
AC
27352During the execution of a command file or a user-defined command, normal
27353@value{GDBN} output is suppressed; the only output that appears is what is
27354explicitly printed by the commands in the definition. This section
27355describes three commands useful for generating exactly the output you
27356want.
c906108c
SS
27357
27358@table @code
8e04817f
AC
27359@kindex echo
27360@item echo @var{text}
27361@c I do not consider backslash-space a standard C escape sequence
27362@c because it is not in ANSI.
27363Print @var{text}. Nonprinting characters can be included in
27364@var{text} using C escape sequences, such as @samp{\n} to print a
27365newline. @strong{No newline is printed unless you specify one.}
27366In addition to the standard C escape sequences, a backslash followed
27367by a space stands for a space. This is useful for displaying a
27368string with spaces at the beginning or the end, since leading and
27369trailing spaces are otherwise trimmed from all arguments.
27370To print @samp{@w{ }and foo =@w{ }}, use the command
27371@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 27372
8e04817f
AC
27373A backslash at the end of @var{text} can be used, as in C, to continue
27374the command onto subsequent lines. For example,
c906108c 27375
474c8240 27376@smallexample
8e04817f
AC
27377echo This is some text\n\
27378which is continued\n\
27379onto several lines.\n
474c8240 27380@end smallexample
c906108c 27381
8e04817f 27382produces the same output as
c906108c 27383
474c8240 27384@smallexample
8e04817f
AC
27385echo This is some text\n
27386echo which is continued\n
27387echo onto several lines.\n
474c8240 27388@end smallexample
c906108c 27389
8e04817f
AC
27390@kindex output
27391@item output @var{expression}
27392Print the value of @var{expression} and nothing but that value: no
27393newlines, no @samp{$@var{nn} = }. The value is not entered in the
27394value history either. @xref{Expressions, ,Expressions}, for more information
27395on expressions.
c906108c 27396
8e04817f
AC
27397@item output/@var{fmt} @var{expression}
27398Print the value of @var{expression} in format @var{fmt}. You can use
27399the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 27400Formats}, for more information.
c906108c 27401
8e04817f 27402@kindex printf
82160952
EZ
27403@item printf @var{template}, @var{expressions}@dots{}
27404Print the values of one or more @var{expressions} under the control of
27405the string @var{template}. To print several values, make
27406@var{expressions} be a comma-separated list of individual expressions,
27407which may be either numbers or pointers. Their values are printed as
27408specified by @var{template}, exactly as a C program would do by
27409executing the code below:
c906108c 27410
474c8240 27411@smallexample
82160952 27412printf (@var{template}, @var{expressions}@dots{});
474c8240 27413@end smallexample
c906108c 27414
82160952
EZ
27415As in @code{C} @code{printf}, ordinary characters in @var{template}
27416are printed verbatim, while @dfn{conversion specification} introduced
27417by the @samp{%} character cause subsequent @var{expressions} to be
27418evaluated, their values converted and formatted according to type and
27419style information encoded in the conversion specifications, and then
27420printed.
27421
8e04817f 27422For example, you can print two values in hex like this:
c906108c 27423
8e04817f
AC
27424@smallexample
27425printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27426@end smallexample
c906108c 27427
82160952
EZ
27428@code{printf} supports all the standard @code{C} conversion
27429specifications, including the flags and modifiers between the @samp{%}
27430character and the conversion letter, with the following exceptions:
27431
27432@itemize @bullet
27433@item
27434The argument-ordering modifiers, such as @samp{2$}, are not supported.
27435
27436@item
27437The modifier @samp{*} is not supported for specifying precision or
27438width.
27439
27440@item
27441The @samp{'} flag (for separation of digits into groups according to
27442@code{LC_NUMERIC'}) is not supported.
27443
27444@item
27445The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27446supported.
27447
27448@item
27449The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27450
27451@item
27452The conversion letters @samp{a} and @samp{A} are not supported.
27453@end itemize
27454
27455@noindent
27456Note that the @samp{ll} type modifier is supported only if the
27457underlying @code{C} implementation used to build @value{GDBN} supports
27458the @code{long long int} type, and the @samp{L} type modifier is
27459supported only if @code{long double} type is available.
27460
27461As in @code{C}, @code{printf} supports simple backslash-escape
27462sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27463@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27464single character. Octal and hexadecimal escape sequences are not
27465supported.
1a619819
LM
27466
27467Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27468(@dfn{Decimal Floating Point}) types using the following length modifiers
27469together with a floating point specifier.
1a619819
LM
27470letters:
27471
27472@itemize @bullet
27473@item
27474@samp{H} for printing @code{Decimal32} types.
27475
27476@item
27477@samp{D} for printing @code{Decimal64} types.
27478
27479@item
27480@samp{DD} for printing @code{Decimal128} types.
27481@end itemize
27482
27483If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27484support for the three length modifiers for DFP types, other modifiers
3b784c4f 27485such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27486
27487In case there is no such @code{C} support, no additional modifiers will be
27488available and the value will be printed in the standard way.
27489
27490Here's an example of printing DFP types using the above conversion letters:
27491@smallexample
0aea4bf3 27492printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27493@end smallexample
27494
01770bbd 27495@anchor{eval}
f1421989
HZ
27496@kindex eval
27497@item eval @var{template}, @var{expressions}@dots{}
27498Convert the values of one or more @var{expressions} under the control of
27499the string @var{template} to a command line, and call it.
27500
c906108c
SS
27501@end table
27502
71b8c845
DE
27503@node Auto-loading sequences
27504@subsection Controlling auto-loading native @value{GDBN} scripts
27505@cindex native script auto-loading
27506
27507When a new object file is read (for example, due to the @code{file}
27508command, or because the inferior has loaded a shared library),
27509@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27510@xref{Auto-loading extensions}.
27511
27512Auto-loading can be enabled or disabled,
27513and the list of auto-loaded scripts can be printed.
27514
27515@table @code
27516@anchor{set auto-load gdb-scripts}
27517@kindex set auto-load gdb-scripts
27518@item set auto-load gdb-scripts [on|off]
27519Enable or disable the auto-loading of canned sequences of commands scripts.
27520
27521@anchor{show auto-load gdb-scripts}
27522@kindex show auto-load gdb-scripts
27523@item show auto-load gdb-scripts
27524Show whether auto-loading of canned sequences of commands scripts is enabled or
27525disabled.
27526
27527@anchor{info auto-load gdb-scripts}
27528@kindex info auto-load gdb-scripts
27529@cindex print list of auto-loaded canned sequences of commands scripts
27530@item info auto-load gdb-scripts [@var{regexp}]
27531Print the list of all canned sequences of commands scripts that @value{GDBN}
27532auto-loaded.
27533@end table
27534
27535If @var{regexp} is supplied only canned sequences of commands scripts with
27536matching names are printed.
27537
329baa95
DE
27538@c Python docs live in a separate file.
27539@include python.texi
0e3509db 27540
ed3ef339
DE
27541@c Guile docs live in a separate file.
27542@include guile.texi
27543
71b8c845
DE
27544@node Auto-loading extensions
27545@section Auto-loading extensions
27546@cindex auto-loading extensions
27547
27548@value{GDBN} provides two mechanisms for automatically loading extensions
27549when a new object file is read (for example, due to the @code{file}
27550command, or because the inferior has loaded a shared library):
27551@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27552section of modern file formats like ELF.
27553
27554@menu
27555* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27556* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27557* Which flavor to choose?::
27558@end menu
27559
27560The auto-loading feature is useful for supplying application-specific
27561debugging commands and features.
27562
27563Auto-loading can be enabled or disabled,
27564and the list of auto-loaded scripts can be printed.
27565See the @samp{auto-loading} section of each extension language
27566for more information.
27567For @value{GDBN} command files see @ref{Auto-loading sequences}.
27568For Python files see @ref{Python Auto-loading}.
27569
27570Note that loading of this script file also requires accordingly configured
27571@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27572
27573@node objfile-gdbdotext file
27574@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27575@cindex @file{@var{objfile}-gdb.gdb}
27576@cindex @file{@var{objfile}-gdb.py}
27577@cindex @file{@var{objfile}-gdb.scm}
27578
27579When a new object file is read, @value{GDBN} looks for a file named
27580@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27581where @var{objfile} is the object file's name and
27582where @var{ext} is the file extension for the extension language:
27583
27584@table @code
27585@item @file{@var{objfile}-gdb.gdb}
27586GDB's own command language
27587@item @file{@var{objfile}-gdb.py}
27588Python
ed3ef339
DE
27589@item @file{@var{objfile}-gdb.scm}
27590Guile
71b8c845
DE
27591@end table
27592
27593@var{script-name} is formed by ensuring that the file name of @var{objfile}
27594is absolute, following all symlinks, and resolving @code{.} and @code{..}
27595components, and appending the @file{-gdb.@var{ext}} suffix.
27596If this file exists and is readable, @value{GDBN} will evaluate it as a
27597script in the specified extension language.
27598
27599If this file does not exist, then @value{GDBN} will look for
27600@var{script-name} file in all of the directories as specified below.
6e2469ff
HD
27601(On MS-Windows/MS-DOS, the drive letter of the executable's leading
27602directories is converted to a one-letter subdirectory, i.e.@:
27603@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27604filesystems disallow colons in file names.)
71b8c845
DE
27605
27606Note that loading of these files requires an accordingly configured
27607@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27608
27609For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27610scripts normally according to its @file{.exe} filename. But if no scripts are
27611found @value{GDBN} also tries script filenames matching the object file without
27612its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27613is attempted on any platform. This makes the script filenames compatible
27614between Unix and MS-Windows hosts.
27615
27616@table @code
27617@anchor{set auto-load scripts-directory}
27618@kindex set auto-load scripts-directory
27619@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27620Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27621may be delimited by the host platform path separator in use
27622(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27623
27624Each entry here needs to be covered also by the security setting
27625@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27626
27627@anchor{with-auto-load-dir}
27628This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27629@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27630configuration option @option{--with-auto-load-dir}.
27631
27632Any reference to @file{$debugdir} will get replaced by
27633@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27634reference to @file{$datadir} will get replaced by @var{data-directory} which is
27635determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27636@file{$datadir} must be placed as a directory component --- either alone or
27637delimited by @file{/} or @file{\} directory separators, depending on the host
27638platform.
27639
27640The list of directories uses path separator (@samp{:} on GNU and Unix
27641systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27642to the @env{PATH} environment variable.
27643
27644@anchor{show auto-load scripts-directory}
27645@kindex show auto-load scripts-directory
27646@item show auto-load scripts-directory
27647Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27648
27649@anchor{add-auto-load-scripts-directory}
27650@kindex add-auto-load-scripts-directory
27651@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27652Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27653Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27654@end table
27655
27656@value{GDBN} does not track which files it has already auto-loaded this way.
27657@value{GDBN} will load the associated script every time the corresponding
27658@var{objfile} is opened.
27659So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27660is evaluated more than once.
27661
27662@node dotdebug_gdb_scripts section
27663@subsection The @code{.debug_gdb_scripts} section
27664@cindex @code{.debug_gdb_scripts} section
27665
27666For systems using file formats like ELF and COFF,
27667when @value{GDBN} loads a new object file
27668it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27669If this section exists, its contents is a list of null-terminated entries
27670specifying scripts to load. Each entry begins with a non-null prefix byte that
27671specifies the kind of entry, typically the extension language and whether the
27672script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27673
9f050062
DE
27674The following entries are supported:
27675
27676@table @code
27677@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27678@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27679@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27680@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27681@end table
27682
27683@subsubsection Script File Entries
27684
27685If the entry specifies a file, @value{GDBN} will look for the file first
27686in the current directory and then along the source search path
71b8c845
DE
27687(@pxref{Source Path, ,Specifying Source Directories}),
27688except that @file{$cdir} is not searched, since the compilation
27689directory is not relevant to scripts.
27690
9f050062 27691File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27692for example, this GCC macro for Python scripts.
27693
27694@example
27695/* Note: The "MS" section flags are to remove duplicates. */
27696#define DEFINE_GDB_PY_SCRIPT(script_name) \
27697 asm("\
27698.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27699.byte 1 /* Python */\n\
27700.asciz \"" script_name "\"\n\
27701.popsection \n\
27702");
27703@end example
27704
27705@noindent
ed3ef339 27706For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27707Then one can reference the macro in a header or source file like this:
27708
27709@example
27710DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27711@end example
27712
27713The script name may include directories if desired.
27714
27715Note that loading of this script file also requires accordingly configured
27716@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27717
27718If the macro invocation is put in a header, any application or library
27719using this header will get a reference to the specified script,
27720and with the use of @code{"MS"} attributes on the section, the linker
27721will remove duplicates.
27722
9f050062
DE
27723@subsubsection Script Text Entries
27724
27725Script text entries allow to put the executable script in the entry
27726itself instead of loading it from a file.
27727The first line of the entry, everything after the prefix byte and up to
27728the first newline (@code{0xa}) character, is the script name, and must not
27729contain any kind of space character, e.g., spaces or tabs.
27730The rest of the entry, up to the trailing null byte, is the script to
27731execute in the specified language. The name needs to be unique among
27732all script names, as @value{GDBN} executes each script only once based
27733on its name.
27734
27735Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27736testsuite.
27737
27738@example
27739#include "symcat.h"
27740#include "gdb/section-scripts.h"
27741asm(
27742".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27743".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27744".ascii \"gdb.inlined-script\\n\"\n"
27745".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27746".ascii \" def __init__ (self):\\n\"\n"
27747".ascii \" super (test_cmd, self).__init__ ("
27748 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27749".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27750".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27751".ascii \"test_cmd ()\\n\"\n"
27752".byte 0\n"
27753".popsection\n"
27754);
27755@end example
27756
27757Loading of inlined scripts requires a properly configured
27758@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27759The path to specify in @code{auto-load safe-path} is the path of the file
27760containing the @code{.debug_gdb_scripts} section.
27761
71b8c845
DE
27762@node Which flavor to choose?
27763@subsection Which flavor to choose?
27764
27765Given the multiple ways of auto-loading extensions, it might not always
27766be clear which one to choose. This section provides some guidance.
27767
27768@noindent
27769Benefits of the @file{-gdb.@var{ext}} way:
27770
27771@itemize @bullet
27772@item
27773Can be used with file formats that don't support multiple sections.
27774
27775@item
27776Ease of finding scripts for public libraries.
27777
27778Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27779in the source search path.
27780For publicly installed libraries, e.g., @file{libstdc++}, there typically
27781isn't a source directory in which to find the script.
27782
27783@item
27784Doesn't require source code additions.
27785@end itemize
27786
27787@noindent
27788Benefits of the @code{.debug_gdb_scripts} way:
27789
27790@itemize @bullet
27791@item
27792Works with static linking.
27793
27794Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27795trigger their loading. When an application is statically linked the only
27796objfile available is the executable, and it is cumbersome to attach all the
27797scripts from all the input libraries to the executable's
27798@file{-gdb.@var{ext}} script.
27799
27800@item
27801Works with classes that are entirely inlined.
27802
27803Some classes can be entirely inlined, and thus there may not be an associated
27804shared library to attach a @file{-gdb.@var{ext}} script to.
27805
27806@item
27807Scripts needn't be copied out of the source tree.
27808
27809In some circumstances, apps can be built out of large collections of internal
27810libraries, and the build infrastructure necessary to install the
27811@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27812cumbersome. It may be easier to specify the scripts in the
27813@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27814top of the source tree to the source search path.
27815@end itemize
27816
ed3ef339
DE
27817@node Multiple Extension Languages
27818@section Multiple Extension Languages
27819
27820The Guile and Python extension languages do not share any state,
27821and generally do not interfere with each other.
27822There are some things to be aware of, however.
27823
27824@subsection Python comes first
27825
27826Python was @value{GDBN}'s first extension language, and to avoid breaking
27827existing behaviour Python comes first. This is generally solved by the
27828``first one wins'' principle. @value{GDBN} maintains a list of enabled
27829extension languages, and when it makes a call to an extension language,
27830(say to pretty-print a value), it tries each in turn until an extension
27831language indicates it has performed the request (e.g., has returned the
27832pretty-printed form of a value).
27833This extends to errors while performing such requests: If an error happens
27834while, for example, trying to pretty-print an object then the error is
27835reported and any following extension languages are not tried.
27836
5a56e9c5
DE
27837@node Aliases
27838@section Creating new spellings of existing commands
27839@cindex aliases for commands
27840
27841It is often useful to define alternate spellings of existing commands.
27842For example, if a new @value{GDBN} command defined in Python has
27843a long name to type, it is handy to have an abbreviated version of it
27844that involves less typing.
27845
27846@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27847of the @samp{step} command even though it is otherwise an ambiguous
27848abbreviation of other commands like @samp{set} and @samp{show}.
27849
27850Aliases are also used to provide shortened or more common versions
27851of multi-word commands. For example, @value{GDBN} provides the
27852@samp{tty} alias of the @samp{set inferior-tty} command.
27853
27854You can define a new alias with the @samp{alias} command.
27855
27856@table @code
27857
27858@kindex alias
5b860c93 27859@item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
5a56e9c5
DE
27860
27861@end table
27862
27863@var{ALIAS} specifies the name of the new alias.
27864Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27865underscores.
27866
27867@var{COMMAND} specifies the name of an existing command
27868that is being aliased.
27869
5b860c93
PW
27870@var{COMMAND} can also be the name of an existing alias. In this case,
27871@var{COMMAND} cannot be an alias that has default arguments.
27872
5a56e9c5 27873The @samp{-a} option specifies that the new alias is an abbreviation
5b4a1a8d 27874of the command. Abbreviations are not used in command completion.
5a56e9c5
DE
27875
27876The @samp{--} option specifies the end of options,
27877and is useful when @var{ALIAS} begins with a dash.
27878
5b860c93
PW
27879You can specify @var{default-args} for your alias.
27880These @var{default-args} will be automatically added before the alias
27881arguments typed explicitly on the command line.
27882
27883For example, the below defines an alias @code{btfullall} that shows all local
27884variables and all frame arguments:
27885@smallexample
27886(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27887@end smallexample
27888
27889For more information about @var{default-args}, see @ref{Command aliases default args,
27890,Automatically prepend default arguments to user-defined aliases}.
27891
5a56e9c5
DE
27892Here is a simple example showing how to make an abbreviation
27893of a command so that there is less to type.
27894Suppose you were tired of typing @samp{disas}, the current
27895shortest unambiguous abbreviation of the @samp{disassemble} command
27896and you wanted an even shorter version named @samp{di}.
27897The following will accomplish this.
27898
27899@smallexample
27900(gdb) alias -a di = disas
27901@end smallexample
27902
27903Note that aliases are different from user-defined commands.
27904With a user-defined command, you also need to write documentation
27905for it with the @samp{document} command.
27906An alias automatically picks up the documentation of the existing command.
27907
27908Here is an example where we make @samp{elms} an abbreviation of
27909@samp{elements} in the @samp{set print elements} command.
27910This is to show that you can make an abbreviation of any part
27911of a command.
27912
27913@smallexample
27914(gdb) alias -a set print elms = set print elements
27915(gdb) alias -a show print elms = show print elements
27916(gdb) set p elms 20
27917(gdb) show p elms
27918Limit on string chars or array elements to print is 200.
27919@end smallexample
27920
27921Note that if you are defining an alias of a @samp{set} command,
27922and you want to have an alias for the corresponding @samp{show}
27923command, then you need to define the latter separately.
27924
27925Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27926@var{ALIAS}, just as they are normally.
27927
27928@smallexample
27929(gdb) alias -a set pr elms = set p ele
27930@end smallexample
27931
27932Finally, here is an example showing the creation of a one word
27933alias for a more complex command.
27934This creates alias @samp{spe} of the command @samp{set print elements}.
27935
27936@smallexample
27937(gdb) alias spe = set print elements
27938(gdb) spe 20
27939@end smallexample
27940
21c294e6
AC
27941@node Interpreters
27942@chapter Command Interpreters
27943@cindex command interpreters
27944
27945@value{GDBN} supports multiple command interpreters, and some command
27946infrastructure to allow users or user interface writers to switch
27947between interpreters or run commands in other interpreters.
27948
27949@value{GDBN} currently supports two command interpreters, the console
27950interpreter (sometimes called the command-line interpreter or @sc{cli})
27951and the machine interface interpreter (or @sc{gdb/mi}). This manual
27952describes both of these interfaces in great detail.
27953
27954By default, @value{GDBN} will start with the console interpreter.
27955However, the user may choose to start @value{GDBN} with another
27956interpreter by specifying the @option{-i} or @option{--interpreter}
27957startup options. Defined interpreters include:
27958
27959@table @code
27960@item console
27961@cindex console interpreter
27962The traditional console or command-line interpreter. This is the most often
27963used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27964@value{GDBN} will use this interpreter.
27965
27966@item mi
27967@cindex mi interpreter
b4be1b06 27968The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
27969by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27970or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27971Interface}.
27972
b4be1b06
SM
27973@item mi3
27974@cindex mi3 interpreter
27975The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27976
21c294e6
AC
27977@item mi2
27978@cindex mi2 interpreter
b4be1b06 27979The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
27980
27981@item mi1
27982@cindex mi1 interpreter
b4be1b06 27983The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
27984
27985@end table
27986
27987@cindex invoke another interpreter
21c294e6
AC
27988
27989@kindex interpreter-exec
86f78169
PA
27990You may execute commands in any interpreter from the current
27991interpreter using the appropriate command. If you are running the
27992console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
27993
27994@smallexample
27995interpreter-exec mi "-data-list-register-names"
27996@end smallexample
27997
27998@sc{gdb/mi} has a similar command, although it is only available in versions of
27999@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28000
86f78169
PA
28001Note that @code{interpreter-exec} only changes the interpreter for the
28002duration of the specified command. It does not change the interpreter
28003permanently.
28004
28005@cindex start a new independent interpreter
28006
28007Although you may only choose a single interpreter at startup, it is
28008possible to run an independent interpreter on a specified input/output
28009device (usually a tty).
28010
28011For example, consider a debugger GUI or IDE that wants to provide a
28012@value{GDBN} console view. It may do so by embedding a terminal
28013emulator widget in its GUI, starting @value{GDBN} in the traditional
28014command-line mode with stdin/stdout/stderr redirected to that
28015terminal, and then creating an MI interpreter running on a specified
28016input/output device. The console interpreter created by @value{GDBN}
28017at startup handles commands the user types in the terminal widget,
28018while the GUI controls and synchronizes state with @value{GDBN} using
28019the separate MI interpreter.
28020
28021To start a new secondary @dfn{user interface} running MI, use the
28022@code{new-ui} command:
28023
28024@kindex new-ui
28025@cindex new user interface
28026@smallexample
28027new-ui @var{interpreter} @var{tty}
28028@end smallexample
28029
28030The @var{interpreter} parameter specifies the interpreter to run.
28031This accepts the same values as the @code{interpreter-exec} command.
28032For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28033@var{tty} parameter specifies the name of the bidirectional file the
28034interpreter uses for input/output, usually the name of a
28035pseudoterminal slave on Unix systems. For example:
28036
28037@smallexample
28038(@value{GDBP}) new-ui mi /dev/pts/9
28039@end smallexample
28040
28041@noindent
28042runs an MI interpreter on @file{/dev/pts/9}.
28043
8e04817f
AC
28044@node TUI
28045@chapter @value{GDBN} Text User Interface
28046@cindex TUI
d0d5df6f 28047@cindex Text User Interface
c906108c 28048
8e04817f
AC
28049@menu
28050* TUI Overview:: TUI overview
28051* TUI Keys:: TUI key bindings
7cf36c78 28052* TUI Single Key Mode:: TUI single key mode
db2e3e2e 28053* TUI Commands:: TUI-specific commands
8e04817f
AC
28054* TUI Configuration:: TUI configuration variables
28055@end menu
c906108c 28056
46ba6afa 28057The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
28058interface which uses the @code{curses} library to show the source
28059file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
28060commands in separate text windows. The TUI mode is supported only
28061on platforms where a suitable version of the @code{curses} library
28062is available.
d0d5df6f 28063
46ba6afa 28064The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 28065@samp{@value{GDBP} -tui}.
46ba6afa 28066You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 28067using various TUI commands and key bindings, such as @command{tui
bcd8537c 28068enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 28069@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 28070
8e04817f 28071@node TUI Overview
79a6e687 28072@section TUI Overview
c906108c 28073
46ba6afa 28074In TUI mode, @value{GDBN} can display several text windows:
c906108c 28075
8e04817f
AC
28076@table @emph
28077@item command
28078This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
28079prompt and the @value{GDBN} output. The @value{GDBN} input is still
28080managed using readline.
c906108c 28081
8e04817f
AC
28082@item source
28083The source window shows the source file of the program. The current
46ba6afa 28084line and active breakpoints are displayed in this window.
c906108c 28085
8e04817f
AC
28086@item assembly
28087The assembly window shows the disassembly output of the program.
c906108c 28088
8e04817f 28089@item register
46ba6afa
BW
28090This window shows the processor registers. Registers are highlighted
28091when their values change.
c906108c
SS
28092@end table
28093
269c21fe 28094The source and assembly windows show the current program position
46ba6afa
BW
28095by highlighting the current line and marking it with a @samp{>} marker.
28096Breakpoints are indicated with two markers. The first marker
269c21fe
SC
28097indicates the breakpoint type:
28098
28099@table @code
28100@item B
28101Breakpoint which was hit at least once.
28102
28103@item b
28104Breakpoint which was never hit.
28105
28106@item H
28107Hardware breakpoint which was hit at least once.
28108
28109@item h
28110Hardware breakpoint which was never hit.
269c21fe
SC
28111@end table
28112
28113The second marker indicates whether the breakpoint is enabled or not:
28114
28115@table @code
28116@item +
28117Breakpoint is enabled.
28118
28119@item -
28120Breakpoint is disabled.
269c21fe
SC
28121@end table
28122
46ba6afa
BW
28123The source, assembly and register windows are updated when the current
28124thread changes, when the frame changes, or when the program counter
28125changes.
28126
28127These windows are not all visible at the same time. The command
28128window is always visible. The others can be arranged in several
28129layouts:
c906108c 28130
8e04817f
AC
28131@itemize @bullet
28132@item
46ba6afa 28133source only,
2df3850c 28134
8e04817f 28135@item
46ba6afa 28136assembly only,
8e04817f
AC
28137
28138@item
46ba6afa 28139source and assembly,
8e04817f
AC
28140
28141@item
46ba6afa 28142source and registers, or
c906108c 28143
8e04817f 28144@item
46ba6afa 28145assembly and registers.
8e04817f 28146@end itemize
c906108c 28147
ee325b61
TT
28148These are the standard layouts, but other layouts can be defined.
28149
46ba6afa 28150A status line above the command window shows the following information:
b7bb15bc
SC
28151
28152@table @emph
28153@item target
46ba6afa 28154Indicates the current @value{GDBN} target.
b7bb15bc
SC
28155(@pxref{Targets, ,Specifying a Debugging Target}).
28156
28157@item process
46ba6afa 28158Gives the current process or thread number.
b7bb15bc
SC
28159When no process is being debugged, this field is set to @code{No process}.
28160
28161@item function
28162Gives the current function name for the selected frame.
28163The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 28164When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
28165the string @code{??} is displayed.
28166
28167@item line
28168Indicates the current line number for the selected frame.
46ba6afa 28169When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
28170
28171@item pc
28172Indicates the current program counter address.
b7bb15bc
SC
28173@end table
28174
8e04817f
AC
28175@node TUI Keys
28176@section TUI Key Bindings
28177@cindex TUI key bindings
c906108c 28178
8e04817f 28179The TUI installs several key bindings in the readline keymaps
39037522
TT
28180@ifset SYSTEM_READLINE
28181(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28182@end ifset
28183@ifclear SYSTEM_READLINE
28184(@pxref{Command Line Editing}).
28185@end ifclear
28186The following key bindings are installed for both TUI mode and the
28187@value{GDBN} standard mode.
c906108c 28188
8e04817f
AC
28189@table @kbd
28190@kindex C-x C-a
28191@item C-x C-a
28192@kindex C-x a
28193@itemx C-x a
28194@kindex C-x A
28195@itemx C-x A
46ba6afa
BW
28196Enter or leave the TUI mode. When leaving the TUI mode,
28197the curses window management stops and @value{GDBN} operates using
28198its standard mode, writing on the terminal directly. When reentering
28199the TUI mode, control is given back to the curses windows.
8e04817f 28200The screen is then refreshed.
c906108c 28201
c86d74cc
TT
28202This key binding uses the bindable Readline function
28203@code{tui-switch-mode}.
28204
8e04817f
AC
28205@kindex C-x 1
28206@item C-x 1
28207Use a TUI layout with only one window. The layout will
28208either be @samp{source} or @samp{assembly}. When the TUI mode
28209is not active, it will switch to the TUI mode.
2df3850c 28210
8e04817f 28211Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 28212
c86d74cc
TT
28213This key binding uses the bindable Readline function
28214@code{tui-delete-other-windows}.
28215
8e04817f
AC
28216@kindex C-x 2
28217@item C-x 2
28218Use a TUI layout with at least two windows. When the current
46ba6afa 28219layout already has two windows, the next layout with two windows is used.
8e04817f
AC
28220When a new layout is chosen, one window will always be common to the
28221previous layout and the new one.
c906108c 28222
8e04817f 28223Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 28224
c86d74cc
TT
28225This key binding uses the bindable Readline function
28226@code{tui-change-windows}.
28227
72ffddc9
SC
28228@kindex C-x o
28229@item C-x o
28230Change the active window. The TUI associates several key bindings
46ba6afa 28231(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
28232gives the focus to the next TUI window.
28233
28234Think of it as the Emacs @kbd{C-x o} binding.
28235
c86d74cc
TT
28236This key binding uses the bindable Readline function
28237@code{tui-other-window}.
28238
7cf36c78
SC
28239@kindex C-x s
28240@item C-x s
46ba6afa
BW
28241Switch in and out of the TUI SingleKey mode that binds single
28242keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
28243
28244This key binding uses the bindable Readline function
28245@code{next-keymap}.
c906108c
SS
28246@end table
28247
46ba6afa 28248The following key bindings only work in the TUI mode:
5d161b24 28249
46ba6afa 28250@table @asis
8e04817f 28251@kindex PgUp
46ba6afa 28252@item @key{PgUp}
8e04817f 28253Scroll the active window one page up.
c906108c 28254
8e04817f 28255@kindex PgDn
46ba6afa 28256@item @key{PgDn}
8e04817f 28257Scroll the active window one page down.
c906108c 28258
8e04817f 28259@kindex Up
46ba6afa 28260@item @key{Up}
8e04817f 28261Scroll the active window one line up.
c906108c 28262
8e04817f 28263@kindex Down
46ba6afa 28264@item @key{Down}
8e04817f 28265Scroll the active window one line down.
c906108c 28266
8e04817f 28267@kindex Left
46ba6afa 28268@item @key{Left}
8e04817f 28269Scroll the active window one column left.
c906108c 28270
8e04817f 28271@kindex Right
46ba6afa 28272@item @key{Right}
8e04817f 28273Scroll the active window one column right.
c906108c 28274
8e04817f 28275@kindex C-L
46ba6afa 28276@item @kbd{C-L}
8e04817f 28277Refresh the screen.
8e04817f 28278@end table
c906108c 28279
46ba6afa
BW
28280Because the arrow keys scroll the active window in the TUI mode, they
28281are not available for their normal use by readline unless the command
28282window has the focus. When another window is active, you must use
28283other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28284and @kbd{C-f} to control the command window.
8e04817f 28285
7cf36c78
SC
28286@node TUI Single Key Mode
28287@section TUI Single Key Mode
28288@cindex TUI single key mode
28289
46ba6afa
BW
28290The TUI also provides a @dfn{SingleKey} mode, which binds several
28291frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28292switch into this mode, where the following key bindings are used:
7cf36c78
SC
28293
28294@table @kbd
28295@kindex c @r{(SingleKey TUI key)}
28296@item c
28297continue
28298
28299@kindex d @r{(SingleKey TUI key)}
28300@item d
28301down
28302
28303@kindex f @r{(SingleKey TUI key)}
28304@item f
28305finish
28306
28307@kindex n @r{(SingleKey TUI key)}
28308@item n
28309next
28310
a5afdb16
RK
28311@kindex o @r{(SingleKey TUI key)}
28312@item o
28313nexti. The shortcut letter @samp{o} stands for ``step Over''.
28314
7cf36c78
SC
28315@kindex q @r{(SingleKey TUI key)}
28316@item q
46ba6afa 28317exit the SingleKey mode.
7cf36c78
SC
28318
28319@kindex r @r{(SingleKey TUI key)}
28320@item r
28321run
28322
28323@kindex s @r{(SingleKey TUI key)}
28324@item s
28325step
28326
a5afdb16
RK
28327@kindex i @r{(SingleKey TUI key)}
28328@item i
28329stepi. The shortcut letter @samp{i} stands for ``step Into''.
28330
7cf36c78
SC
28331@kindex u @r{(SingleKey TUI key)}
28332@item u
28333up
28334
28335@kindex v @r{(SingleKey TUI key)}
28336@item v
28337info locals
28338
28339@kindex w @r{(SingleKey TUI key)}
28340@item w
28341where
7cf36c78
SC
28342@end table
28343
28344Other keys temporarily switch to the @value{GDBN} command prompt.
28345The key that was pressed is inserted in the editing buffer so that
28346it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
28347with the TUI SingleKey mode. Once the command is entered the TUI
28348SingleKey mode is restored. The only way to permanently leave
7f9087cb 28349this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 28350
11061048
TT
28351@cindex SingleKey keymap name
28352If @value{GDBN} was built with Readline 8.0 or later, the TUI
28353SingleKey keymap will be named @samp{SingleKey}. This can be used in
28354@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 28355
8e04817f 28356@node TUI Commands
db2e3e2e 28357@section TUI-specific Commands
8e04817f
AC
28358@cindex TUI commands
28359
28360The TUI has specific commands to control the text windows.
46ba6afa
BW
28361These commands are always available, even when @value{GDBN} is not in
28362the TUI mode. When @value{GDBN} is in the standard mode, most
28363of these commands will automatically switch to the TUI mode.
c906108c 28364
ff12863f
PA
28365Note that if @value{GDBN}'s @code{stdout} is not connected to a
28366terminal, or @value{GDBN} has been started with the machine interface
28367interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28368these commands will fail with an error, because it would not be
28369possible or desirable to enable curses window management.
28370
c906108c 28371@table @code
a4ea0946
AB
28372@item tui enable
28373@kindex tui enable
28374Activate TUI mode. The last active TUI window layout will be used if
760f7560 28375TUI mode has previously been used in the current debugging session,
a4ea0946
AB
28376otherwise a default layout is used.
28377
28378@item tui disable
28379@kindex tui disable
28380Disable TUI mode, returning to the console interpreter.
28381
3d757584
SC
28382@item info win
28383@kindex info win
28384List and give the size of all displayed windows.
28385
ee325b61
TT
28386@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28387@kindex tui new-layout
28388Create a new TUI layout. The new layout will be named @var{name}, and
28389can be accessed using the @code{layout} command (see below).
28390
7c043ba6
TT
28391Each @var{window} parameter is either the name of a window to display,
28392or a window description. The windows will be displayed from top to
28393bottom in the order listed.
28394
28395The names of the windows are the same as the ones given to the
ee325b61 28396@code{focus} command (see below); additional, the @code{status}
7c043ba6
TT
28397window can be specified. Note that, because it is of fixed height,
28398the weight assigned to the status window is of no importance. It is
28399conventional to use @samp{0} here.
28400
28401A window description looks a bit like an invocation of @code{tui
28402new-layout}, and is of the form
28403@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28404
28405This specifies a sub-layout. If @code{-horizontal} is given, the
28406windows in this description will be arranged side-by-side, rather than
28407top-to-bottom.
ee325b61
TT
28408
28409Each @var{weight} is an integer. It is the weight of this window
28410relative to all the other windows in the layout. These numbers are
28411used to calculate how much of the screen is given to each window.
28412
28413For example:
28414
28415@example
28416(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28417@end example
28418
28419Here, the new layout is called @samp{example}. It shows the source
28420and register windows, followed by the status window, and then finally
28421the command window. The non-status windows all have the same weight,
28422so the terminal will be split into three roughly equal sections.
28423
7c043ba6
TT
28424Here is a more complex example, showing a horizontal layout:
28425
28426@example
28427(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28428@end example
28429
28430This will result in side-by-side source and assembly windows; with the
28431status and command window being beneath these, filling the entire
28432width of the terminal. Because they have weight 2, the source and
28433assembly windows will be twice the height of the command window.
28434
6008fc5f 28435@item layout @var{name}
4644b6e3 28436@kindex layout
ee325b61
TT
28437Changes which TUI windows are displayed. The @var{name} parameter
28438controls which layout is shown. It can be either one of the built-in
28439layout names, or the name of a layout defined by the user using
28440@code{tui new-layout}.
28441
28442The built-in layouts are as follows:
6008fc5f
AB
28443
28444@table @code
28445@item next
8e04817f 28446Display the next layout.
2df3850c 28447
6008fc5f 28448@item prev
8e04817f 28449Display the previous layout.
c906108c 28450
6008fc5f
AB
28451@item src
28452Display the source and command windows.
c906108c 28453
6008fc5f
AB
28454@item asm
28455Display the assembly and command windows.
c906108c 28456
6008fc5f
AB
28457@item split
28458Display the source, assembly, and command windows.
c906108c 28459
6008fc5f
AB
28460@item regs
28461When in @code{src} layout display the register, source, and command
28462windows. When in @code{asm} or @code{split} layout display the
28463register, assembler, and command windows.
28464@end table
8e04817f 28465
6008fc5f 28466@item focus @var{name}
8e04817f 28467@kindex focus
6008fc5f
AB
28468Changes which TUI window is currently active for scrolling. The
28469@var{name} parameter can be any of the following:
28470
28471@table @code
28472@item next
46ba6afa
BW
28473Make the next window active for scrolling.
28474
6008fc5f 28475@item prev
46ba6afa
BW
28476Make the previous window active for scrolling.
28477
6008fc5f 28478@item src
46ba6afa
BW
28479Make the source window active for scrolling.
28480
6008fc5f 28481@item asm
46ba6afa
BW
28482Make the assembly window active for scrolling.
28483
6008fc5f 28484@item regs
46ba6afa
BW
28485Make the register window active for scrolling.
28486
6008fc5f 28487@item cmd
46ba6afa 28488Make the command window active for scrolling.
6008fc5f 28489@end table
c906108c 28490
8e04817f
AC
28491@item refresh
28492@kindex refresh
7f9087cb 28493Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28494
51f0e40d 28495@item tui reg @var{group}
6a1b180d 28496@kindex tui reg
51f0e40d
AB
28497Changes the register group displayed in the tui register window to
28498@var{group}. If the register window is not currently displayed this
28499command will cause the register window to be displayed. The list of
28500register groups, as well as their order is target specific. The
28501following groups are available on most targets:
28502@table @code
28503@item next
28504Repeatedly selecting this group will cause the display to cycle
28505through all of the available register groups.
28506
28507@item prev
28508Repeatedly selecting this group will cause the display to cycle
28509through all of the available register groups in the reverse order to
28510@var{next}.
28511
28512@item general
28513Display the general registers.
28514@item float
28515Display the floating point registers.
28516@item system
28517Display the system registers.
28518@item vector
28519Display the vector registers.
28520@item all
28521Display all registers.
28522@end table
6a1b180d 28523
8e04817f
AC
28524@item update
28525@kindex update
28526Update the source window and the current execution point.
c906108c 28527
8e04817f
AC
28528@item winheight @var{name} +@var{count}
28529@itemx winheight @var{name} -@var{count}
28530@kindex winheight
28531Change the height of the window @var{name} by @var{count}
28532lines. Positive counts increase the height, while negative counts
bf555842
EZ
28533decrease it. The @var{name} parameter can be one of @code{src} (the
28534source window), @code{cmd} (the command window), @code{asm} (the
28535disassembly window), or @code{regs} (the register display window).
d6677607 28536@end table
2df3850c 28537
8e04817f 28538@node TUI Configuration
79a6e687 28539@section TUI Configuration Variables
8e04817f 28540@cindex TUI configuration variables
c906108c 28541
46ba6afa 28542Several configuration variables control the appearance of TUI windows.
c906108c 28543
8e04817f
AC
28544@table @code
28545@item set tui border-kind @var{kind}
28546@kindex set tui border-kind
28547Select the border appearance for the source, assembly and register windows.
28548The possible values are the following:
28549@table @code
28550@item space
28551Use a space character to draw the border.
c906108c 28552
8e04817f 28553@item ascii
46ba6afa 28554Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28555
8e04817f
AC
28556@item acs
28557Use the Alternate Character Set to draw the border. The border is
28558drawn using character line graphics if the terminal supports them.
8e04817f 28559@end table
c78b4128 28560
8e04817f
AC
28561@item set tui border-mode @var{mode}
28562@kindex set tui border-mode
46ba6afa
BW
28563@itemx set tui active-border-mode @var{mode}
28564@kindex set tui active-border-mode
28565Select the display attributes for the borders of the inactive windows
28566or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28567@table @code
28568@item normal
28569Use normal attributes to display the border.
c906108c 28570
8e04817f
AC
28571@item standout
28572Use standout mode.
c906108c 28573
8e04817f
AC
28574@item reverse
28575Use reverse video mode.
c906108c 28576
8e04817f
AC
28577@item half
28578Use half bright mode.
c906108c 28579
8e04817f
AC
28580@item half-standout
28581Use half bright and standout mode.
c906108c 28582
8e04817f
AC
28583@item bold
28584Use extra bright or bold mode.
c78b4128 28585
8e04817f
AC
28586@item bold-standout
28587Use extra bright or bold and standout mode.
8e04817f 28588@end table
7806cea7
TT
28589
28590@item set tui tab-width @var{nchars}
28591@kindex set tui tab-width
28592@kindex tabset
28593Set the width of tab stops to be @var{nchars} characters. This
28594setting affects the display of TAB characters in the source and
28595assembly windows.
d1da6b01
TT
28596
28597@item set tui compact-source @r{[}on@r{|}off@r{]}
28598@kindex set tui compact-source
28599Set whether the TUI source window is displayed in ``compact'' form.
28600The default display uses more space for line numbers and starts the
28601source text at the next tab stop; the compact display uses only as
28602much space as is needed for the line numbers in the current file, and
28603only a single space to separate the line numbers from the source.
7806cea7 28604@end table
c78b4128 28605
a2a7af0c
TT
28606Note that the colors of the TUI borders can be controlled using the
28607appropriate @code{set style} commands. @xref{Output Styling}.
28608
8e04817f
AC
28609@node Emacs
28610@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28611
8e04817f
AC
28612@cindex Emacs
28613@cindex @sc{gnu} Emacs
28614A special interface allows you to use @sc{gnu} Emacs to view (and
28615edit) the source files for the program you are debugging with
28616@value{GDBN}.
c906108c 28617
8e04817f
AC
28618To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28619executable file you want to debug as an argument. This command starts
28620@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28621created Emacs buffer.
28622@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28623
5e252a2e 28624Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28625things:
c906108c 28626
8e04817f
AC
28627@itemize @bullet
28628@item
5e252a2e
NR
28629All ``terminal'' input and output goes through an Emacs buffer, called
28630the GUD buffer.
c906108c 28631
8e04817f
AC
28632This applies both to @value{GDBN} commands and their output, and to the input
28633and output done by the program you are debugging.
bf0184be 28634
8e04817f
AC
28635This is useful because it means that you can copy the text of previous
28636commands and input them again; you can even use parts of the output
28637in this way.
bf0184be 28638
8e04817f
AC
28639All the facilities of Emacs' Shell mode are available for interacting
28640with your program. In particular, you can send signals the usual
28641way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28642stop.
bf0184be
ND
28643
28644@item
8e04817f 28645@value{GDBN} displays source code through Emacs.
bf0184be 28646
8e04817f
AC
28647Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28648source file for that frame and puts an arrow (@samp{=>}) at the
28649left margin of the current line. Emacs uses a separate buffer for
28650source display, and splits the screen to show both your @value{GDBN} session
28651and the source.
bf0184be 28652
8e04817f
AC
28653Explicit @value{GDBN} @code{list} or search commands still produce output as
28654usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28655@end itemize
28656
28657We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28658a graphical mode, enabled by default, which provides further buffers
28659that can control the execution and describe the state of your program.
28660@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28661
64fabec2
AC
28662If you specify an absolute file name when prompted for the @kbd{M-x
28663gdb} argument, then Emacs sets your current working directory to where
28664your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28665sets your current working directory to the directory associated
64fabec2
AC
28666with the previous buffer. In this case, @value{GDBN} may find your
28667program by searching your environment's @code{PATH} variable, but on
28668some operating systems it might not find the source. So, although the
28669@value{GDBN} input and output session proceeds normally, the auxiliary
28670buffer does not display the current source and line of execution.
28671
28672The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28673line of the GUD buffer and this serves as a default for the commands
28674that specify files for @value{GDBN} to operate on. @xref{Files,
28675,Commands to Specify Files}.
64fabec2
AC
28676
28677By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28678need to call @value{GDBN} by a different name (for example, if you
28679keep several configurations around, with different names) you can
28680customize the Emacs variable @code{gud-gdb-command-name} to run the
28681one you want.
8e04817f 28682
5e252a2e 28683In the GUD buffer, you can use these special Emacs commands in
8e04817f 28684addition to the standard Shell mode commands:
c906108c 28685
8e04817f
AC
28686@table @kbd
28687@item C-h m
5e252a2e 28688Describe the features of Emacs' GUD Mode.
c906108c 28689
64fabec2 28690@item C-c C-s
8e04817f
AC
28691Execute to another source line, like the @value{GDBN} @code{step} command; also
28692update the display window to show the current file and location.
c906108c 28693
64fabec2 28694@item C-c C-n
8e04817f
AC
28695Execute to next source line in this function, skipping all function
28696calls, like the @value{GDBN} @code{next} command. Then update the display window
28697to show the current file and location.
c906108c 28698
64fabec2 28699@item C-c C-i
8e04817f
AC
28700Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28701display window accordingly.
c906108c 28702
8e04817f
AC
28703@item C-c C-f
28704Execute until exit from the selected stack frame, like the @value{GDBN}
28705@code{finish} command.
c906108c 28706
64fabec2 28707@item C-c C-r
8e04817f
AC
28708Continue execution of your program, like the @value{GDBN} @code{continue}
28709command.
b433d00b 28710
64fabec2 28711@item C-c <
8e04817f
AC
28712Go up the number of frames indicated by the numeric argument
28713(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28714like the @value{GDBN} @code{up} command.
b433d00b 28715
64fabec2 28716@item C-c >
8e04817f
AC
28717Go down the number of frames indicated by the numeric argument, like the
28718@value{GDBN} @code{down} command.
8e04817f 28719@end table
c906108c 28720
7f9087cb 28721In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28722tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28723
5e252a2e
NR
28724In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28725separate frame which shows a backtrace when the GUD buffer is current.
28726Move point to any frame in the stack and type @key{RET} to make it
28727become the current frame and display the associated source in the
28728source buffer. Alternatively, click @kbd{Mouse-2} to make the
28729selected frame become the current one. In graphical mode, the
28730speedbar displays watch expressions.
64fabec2 28731
8e04817f
AC
28732If you accidentally delete the source-display buffer, an easy way to get
28733it back is to type the command @code{f} in the @value{GDBN} buffer, to
28734request a frame display; when you run under Emacs, this recreates
28735the source buffer if necessary to show you the context of the current
28736frame.
c906108c 28737
8e04817f
AC
28738The source files displayed in Emacs are in ordinary Emacs buffers
28739which are visiting the source files in the usual way. You can edit
28740the files with these buffers if you wish; but keep in mind that @value{GDBN}
28741communicates with Emacs in terms of line numbers. If you add or
28742delete lines from the text, the line numbers that @value{GDBN} knows cease
28743to correspond properly with the code.
b383017d 28744
5e252a2e
NR
28745A more detailed description of Emacs' interaction with @value{GDBN} is
28746given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28747Emacs Manual}).
c906108c 28748
922fbb7b
AC
28749@node GDB/MI
28750@chapter The @sc{gdb/mi} Interface
28751
28752@unnumberedsec Function and Purpose
28753
28754@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28755@sc{gdb/mi} is a line based machine oriented text interface to
28756@value{GDBN} and is activated by specifying using the
28757@option{--interpreter} command line option (@pxref{Mode Options}). It
28758is specifically intended to support the development of systems which
28759use the debugger as just one small component of a larger system.
922fbb7b
AC
28760
28761This chapter is a specification of the @sc{gdb/mi} interface. It is written
28762in the form of a reference manual.
28763
28764Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28765features described below are incomplete and subject to change
28766(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28767
28768@unnumberedsec Notation and Terminology
28769
28770@cindex notational conventions, for @sc{gdb/mi}
28771This chapter uses the following notation:
28772
28773@itemize @bullet
28774@item
28775@code{|} separates two alternatives.
28776
28777@item
28778@code{[ @var{something} ]} indicates that @var{something} is optional:
28779it may or may not be given.
28780
28781@item
28782@code{( @var{group} )*} means that @var{group} inside the parentheses
28783may repeat zero or more times.
28784
28785@item
28786@code{( @var{group} )+} means that @var{group} inside the parentheses
28787may repeat one or more times.
28788
28789@item
28790@code{"@var{string}"} means a literal @var{string}.
28791@end itemize
28792
28793@ignore
28794@heading Dependencies
28795@end ignore
28796
922fbb7b 28797@menu
c3b108f7 28798* GDB/MI General Design::
922fbb7b
AC
28799* GDB/MI Command Syntax::
28800* GDB/MI Compatibility with CLI::
af6eff6f 28801* GDB/MI Development and Front Ends::
922fbb7b 28802* GDB/MI Output Records::
ef21caaf 28803* GDB/MI Simple Examples::
922fbb7b 28804* GDB/MI Command Description Format::
ef21caaf 28805* GDB/MI Breakpoint Commands::
3fa7bf06 28806* GDB/MI Catchpoint Commands::
a2c02241
NR
28807* GDB/MI Program Context::
28808* GDB/MI Thread Commands::
5d77fe44 28809* GDB/MI Ada Tasking Commands::
a2c02241
NR
28810* GDB/MI Program Execution::
28811* GDB/MI Stack Manipulation::
28812* GDB/MI Variable Objects::
922fbb7b 28813* GDB/MI Data Manipulation::
a2c02241
NR
28814* GDB/MI Tracepoint Commands::
28815* GDB/MI Symbol Query::
351ff01a 28816* GDB/MI File Commands::
922fbb7b
AC
28817@ignore
28818* GDB/MI Kod Commands::
28819* GDB/MI Memory Overlay Commands::
28820* GDB/MI Signal Handling Commands::
28821@end ignore
922fbb7b 28822* GDB/MI Target Manipulation::
a6b151f1 28823* GDB/MI File Transfer Commands::
58d06528 28824* GDB/MI Ada Exceptions Commands::
d192b373 28825* GDB/MI Support Commands::
ef21caaf 28826* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28827@end menu
28828
c3b108f7
VP
28829@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28830@node GDB/MI General Design
28831@section @sc{gdb/mi} General Design
28832@cindex GDB/MI General Design
28833
28834Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28835parts---commands sent to @value{GDBN}, responses to those commands
28836and notifications. Each command results in exactly one response,
28837indicating either successful completion of the command, or an error.
28838For the commands that do not resume the target, the response contains the
28839requested information. For the commands that resume the target, the
28840response only indicates whether the target was successfully resumed.
28841Notifications is the mechanism for reporting changes in the state of the
28842target, or in @value{GDBN} state, that cannot conveniently be associated with
28843a command and reported as part of that command response.
28844
28845The important examples of notifications are:
28846@itemize @bullet
28847
28848@item
28849Exec notifications. These are used to report changes in
28850target state---when a target is resumed, or stopped. It would not
28851be feasible to include this information in response of resuming
28852commands, because one resume commands can result in multiple events in
28853different threads. Also, quite some time may pass before any event
28854happens in the target, while a frontend needs to know whether the resuming
28855command itself was successfully executed.
28856
28857@item
28858Console output, and status notifications. Console output
28859notifications are used to report output of CLI commands, as well as
28860diagnostics for other commands. Status notifications are used to
28861report the progress of a long-running operation. Naturally, including
28862this information in command response would mean no output is produced
28863until the command is finished, which is undesirable.
28864
28865@item
28866General notifications. Commands may have various side effects on
28867the @value{GDBN} or target state beyond their official purpose. For example,
28868a command may change the selected thread. Although such changes can
28869be included in command response, using notification allows for more
28870orthogonal frontend design.
28871
28872@end itemize
28873
28874There's no guarantee that whenever an MI command reports an error,
28875@value{GDBN} or the target are in any specific state, and especially,
28876the state is not reverted to the state before the MI command was
28877processed. Therefore, whenever an MI command results in an error,
28878we recommend that the frontend refreshes all the information shown in
28879the user interface.
28880
508094de
NR
28881
28882@menu
28883* Context management::
28884* Asynchronous and non-stop modes::
28885* Thread groups::
28886@end menu
28887
28888@node Context management
c3b108f7
VP
28889@subsection Context management
28890
403cb6b1
JB
28891@subsubsection Threads and Frames
28892
c3b108f7
VP
28893In most cases when @value{GDBN} accesses the target, this access is
28894done in context of a specific thread and frame (@pxref{Frames}).
28895Often, even when accessing global data, the target requires that a thread
28896be specified. The CLI interface maintains the selected thread and frame,
28897and supplies them to target on each command. This is convenient,
28898because a command line user would not want to specify that information
28899explicitly on each command, and because user interacts with
28900@value{GDBN} via a single terminal, so no confusion is possible as
28901to what thread and frame are the current ones.
28902
28903In the case of MI, the concept of selected thread and frame is less
28904useful. First, a frontend can easily remember this information
28905itself. Second, a graphical frontend can have more than one window,
28906each one used for debugging a different thread, and the frontend might
28907want to access additional threads for internal purposes. This
28908increases the risk that by relying on implicitly selected thread, the
28909frontend may be operating on a wrong one. Therefore, each MI command
28910should explicitly specify which thread and frame to operate on. To
28911make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28912@samp{--frame} options, the value to each is @value{GDBN} global
28913identifier for thread and frame to operate on.
c3b108f7
VP
28914
28915Usually, each top-level window in a frontend allows the user to select
28916a thread and a frame, and remembers the user selection for further
28917operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28918current thread or frame be changed. For example, when stopping on a
28919breakpoint it is reasonable to switch to the thread where breakpoint is
28920hit. For another example, if the user issues the CLI @samp{thread} or
28921@samp{frame} commands via the frontend, it is desirable to change the
28922frontend's selection to the one specified by user. @value{GDBN}
28923communicates the suggestion to change current thread and frame using the
28924@samp{=thread-selected} notification.
c3b108f7
VP
28925
28926Note that historically, MI shares the selected thread with CLI, so
28927frontends used the @code{-thread-select} to execute commands in the
28928right context. However, getting this to work right is cumbersome. The
28929simplest way is for frontend to emit @code{-thread-select} command
28930before every command. This doubles the number of commands that need
28931to be sent. The alternative approach is to suppress @code{-thread-select}
28932if the selected thread in @value{GDBN} is supposed to be identical to the
28933thread the frontend wants to operate on. However, getting this
28934optimization right can be tricky. In particular, if the frontend
28935sends several commands to @value{GDBN}, and one of the commands changes the
28936selected thread, then the behaviour of subsequent commands will
28937change. So, a frontend should either wait for response from such
28938problematic commands, or explicitly add @code{-thread-select} for
28939all subsequent commands. No frontend is known to do this exactly
28940right, so it is suggested to just always pass the @samp{--thread} and
28941@samp{--frame} options.
28942
403cb6b1
JB
28943@subsubsection Language
28944
28945The execution of several commands depends on which language is selected.
28946By default, the current language (@pxref{show language}) is used.
28947But for commands known to be language-sensitive, it is recommended
28948to use the @samp{--language} option. This option takes one argument,
28949which is the name of the language to use while executing the command.
28950For instance:
28951
28952@smallexample
28953-data-evaluate-expression --language c "sizeof (void*)"
28954^done,value="4"
28955(gdb)
28956@end smallexample
28957
28958The valid language names are the same names accepted by the
28959@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28960@samp{local} or @samp{unknown}.
28961
508094de 28962@node Asynchronous and non-stop modes
c3b108f7
VP
28963@subsection Asynchronous command execution and non-stop mode
28964
28965On some targets, @value{GDBN} is capable of processing MI commands
28966even while the target is running. This is called @dfn{asynchronous
28967command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 28968specify a preference for asynchronous execution using the
329ea579 28969@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
28970either running the executable or attaching to the target. After the
28971frontend has started the executable or attached to the target, it can
28972find if asynchronous execution is enabled using the
28973@code{-list-target-features} command.
28974
329ea579
PA
28975@table @code
28976@item -gdb-set mi-async on
28977@item -gdb-set mi-async off
28978Set whether MI is in asynchronous mode.
28979
28980When @code{off}, which is the default, MI execution commands (e.g.,
28981@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28982for the program to stop before processing further commands.
28983
28984When @code{on}, MI execution commands are background execution
28985commands (e.g., @code{-exec-continue} becomes the equivalent of the
28986@code{c&} CLI command), and so @value{GDBN} is capable of processing
28987MI commands even while the target is running.
28988
28989@item -gdb-show mi-async
28990Show whether MI asynchronous mode is enabled.
28991@end table
28992
28993Note: In @value{GDBN} version 7.7 and earlier, this option was called
28994@code{target-async} instead of @code{mi-async}, and it had the effect
28995of both putting MI in asynchronous mode and making CLI background
28996commands possible. CLI background commands are now always possible
28997``out of the box'' if the target supports them. The old spelling is
28998kept as a deprecated alias for backwards compatibility.
28999
c3b108f7
VP
29000Even if @value{GDBN} can accept a command while target is running,
29001many commands that access the target do not work when the target is
29002running. Therefore, asynchronous command execution is most useful
29003when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29004it is possible to examine the state of one thread, while other threads
29005are running.
29006
29007When a given thread is running, MI commands that try to access the
29008target in the context of that thread may not work, or may work only on
29009some targets. In particular, commands that try to operate on thread's
29010stack will not work, on any target. Commands that read memory, or
29011modify breakpoints, may work or not work, depending on the target. Note
29012that even commands that operate on global state, such as @code{print},
29013@code{set}, and breakpoint commands, still access the target in the
29014context of a specific thread, so frontend should try to find a
29015stopped thread and perform the operation on that thread (using the
29016@samp{--thread} option).
29017
29018Which commands will work in the context of a running thread is
29019highly target dependent. However, the two commands
29020@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29021to find the state of a thread, will always work.
29022
508094de 29023@node Thread groups
c3b108f7
VP
29024@subsection Thread groups
29025@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 29026On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
29027hardware systems, each one having several cores with several different
29028processes running on each core. This section describes the MI
29029mechanism to support such debugging scenarios.
29030
29031The key observation is that regardless of the structure of the
29032target, MI can have a global list of threads, because most commands that
29033accept the @samp{--thread} option do not need to know what process that
29034thread belongs to. Therefore, it is not necessary to introduce
29035neither additional @samp{--process} option, nor an notion of the
29036current process in the MI interface. The only strictly new feature
29037that is required is the ability to find how the threads are grouped
29038into processes.
29039
29040To allow the user to discover such grouping, and to support arbitrary
29041hierarchy of machines/cores/processes, MI introduces the concept of a
29042@dfn{thread group}. Thread group is a collection of threads and other
29043thread groups. A thread group always has a string identifier, a type,
29044and may have additional attributes specific to the type. A new
29045command, @code{-list-thread-groups}, returns the list of top-level
29046thread groups, which correspond to processes that @value{GDBN} is
29047debugging at the moment. By passing an identifier of a thread group
29048to the @code{-list-thread-groups} command, it is possible to obtain
29049the members of specific thread group.
29050
29051To allow the user to easily discover processes, and other objects, he
29052wishes to debug, a concept of @dfn{available thread group} is
29053introduced. Available thread group is an thread group that
29054@value{GDBN} is not debugging, but that can be attached to, using the
29055@code{-target-attach} command. The list of available top-level thread
29056groups can be obtained using @samp{-list-thread-groups --available}.
29057In general, the content of a thread group may be only retrieved only
29058after attaching to that thread group.
29059
65c574f6 29060Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
29061Programs}). Each inferior corresponds to a thread group of a special
29062type @samp{process}, and some additional operations are permitted on
29063such thread groups.
29064
922fbb7b
AC
29065@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29066@node GDB/MI Command Syntax
29067@section @sc{gdb/mi} Command Syntax
29068
29069@menu
29070* GDB/MI Input Syntax::
29071* GDB/MI Output Syntax::
922fbb7b
AC
29072@end menu
29073
29074@node GDB/MI Input Syntax
29075@subsection @sc{gdb/mi} Input Syntax
29076
29077@cindex input syntax for @sc{gdb/mi}
29078@cindex @sc{gdb/mi}, input syntax
29079@table @code
29080@item @var{command} @expansion{}
29081@code{@var{cli-command} | @var{mi-command}}
29082
29083@item @var{cli-command} @expansion{}
29084@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29085@var{cli-command} is any existing @value{GDBN} CLI command.
29086
29087@item @var{mi-command} @expansion{}
29088@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29089@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29090
29091@item @var{token} @expansion{}
29092"any sequence of digits"
29093
29094@item @var{option} @expansion{}
29095@code{"-" @var{parameter} [ " " @var{parameter} ]}
29096
29097@item @var{parameter} @expansion{}
29098@code{@var{non-blank-sequence} | @var{c-string}}
29099
29100@item @var{operation} @expansion{}
29101@emph{any of the operations described in this chapter}
29102
29103@item @var{non-blank-sequence} @expansion{}
29104@emph{anything, provided it doesn't contain special characters such as
29105"-", @var{nl}, """ and of course " "}
29106
29107@item @var{c-string} @expansion{}
29108@code{""" @var{seven-bit-iso-c-string-content} """}
29109
29110@item @var{nl} @expansion{}
29111@code{CR | CR-LF}
29112@end table
29113
29114@noindent
29115Notes:
29116
29117@itemize @bullet
29118@item
29119The CLI commands are still handled by the @sc{mi} interpreter; their
29120output is described below.
29121
29122@item
29123The @code{@var{token}}, when present, is passed back when the command
29124finishes.
29125
29126@item
29127Some @sc{mi} commands accept optional arguments as part of the parameter
29128list. Each option is identified by a leading @samp{-} (dash) and may be
29129followed by an optional argument parameter. Options occur first in the
29130parameter list and can be delimited from normal parameters using
29131@samp{--} (this is useful when some parameters begin with a dash).
29132@end itemize
29133
29134Pragmatics:
29135
29136@itemize @bullet
29137@item
29138We want easy access to the existing CLI syntax (for debugging).
29139
29140@item
29141We want it to be easy to spot a @sc{mi} operation.
29142@end itemize
29143
29144@node GDB/MI Output Syntax
29145@subsection @sc{gdb/mi} Output Syntax
29146
29147@cindex output syntax of @sc{gdb/mi}
29148@cindex @sc{gdb/mi}, output syntax
29149The output from @sc{gdb/mi} consists of zero or more out-of-band records
29150followed, optionally, by a single result record. This result record
29151is for the most recent command. The sequence of output records is
594fe323 29152terminated by @samp{(gdb)}.
922fbb7b
AC
29153
29154If an input command was prefixed with a @code{@var{token}} then the
29155corresponding output for that command will also be prefixed by that same
29156@var{token}.
29157
29158@table @code
29159@item @var{output} @expansion{}
594fe323 29160@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
29161
29162@item @var{result-record} @expansion{}
29163@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29164
29165@item @var{out-of-band-record} @expansion{}
29166@code{@var{async-record} | @var{stream-record}}
29167
29168@item @var{async-record} @expansion{}
29169@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29170
29171@item @var{exec-async-output} @expansion{}
dcf106f3 29172@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
29173
29174@item @var{status-async-output} @expansion{}
dcf106f3 29175@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
29176
29177@item @var{notify-async-output} @expansion{}
dcf106f3 29178@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
29179
29180@item @var{async-output} @expansion{}
dcf106f3 29181@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
29182
29183@item @var{result-class} @expansion{}
29184@code{"done" | "running" | "connected" | "error" | "exit"}
29185
29186@item @var{async-class} @expansion{}
29187@code{"stopped" | @var{others}} (where @var{others} will be added
29188depending on the needs---this is still in development).
29189
29190@item @var{result} @expansion{}
29191@code{ @var{variable} "=" @var{value}}
29192
29193@item @var{variable} @expansion{}
29194@code{ @var{string} }
29195
29196@item @var{value} @expansion{}
29197@code{ @var{const} | @var{tuple} | @var{list} }
29198
29199@item @var{const} @expansion{}
29200@code{@var{c-string}}
29201
29202@item @var{tuple} @expansion{}
29203@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29204
29205@item @var{list} @expansion{}
29206@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29207@var{result} ( "," @var{result} )* "]" }
29208
29209@item @var{stream-record} @expansion{}
29210@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29211
29212@item @var{console-stream-output} @expansion{}
dcf106f3 29213@code{"~" @var{c-string nl}}
922fbb7b
AC
29214
29215@item @var{target-stream-output} @expansion{}
dcf106f3 29216@code{"@@" @var{c-string nl}}
922fbb7b
AC
29217
29218@item @var{log-stream-output} @expansion{}
dcf106f3 29219@code{"&" @var{c-string nl}}
922fbb7b
AC
29220
29221@item @var{nl} @expansion{}
29222@code{CR | CR-LF}
29223
29224@item @var{token} @expansion{}
29225@emph{any sequence of digits}.
29226@end table
29227
29228@noindent
29229Notes:
29230
29231@itemize @bullet
29232@item
29233All output sequences end in a single line containing a period.
29234
29235@item
721c02de
VP
29236The @code{@var{token}} is from the corresponding request. Note that
29237for all async output, while the token is allowed by the grammar and
29238may be output by future versions of @value{GDBN} for select async
29239output messages, it is generally omitted. Frontends should treat
29240all async output as reporting general changes in the state of the
29241target and there should be no need to associate async output to any
29242prior command.
922fbb7b
AC
29243
29244@item
29245@cindex status output in @sc{gdb/mi}
29246@var{status-async-output} contains on-going status information about the
29247progress of a slow operation. It can be discarded. All status output is
29248prefixed by @samp{+}.
29249
29250@item
29251@cindex async output in @sc{gdb/mi}
29252@var{exec-async-output} contains asynchronous state change on the target
29253(stopped, started, disappeared). All async output is prefixed by
29254@samp{*}.
29255
29256@item
29257@cindex notify output in @sc{gdb/mi}
29258@var{notify-async-output} contains supplementary information that the
29259client should handle (e.g., a new breakpoint information). All notify
29260output is prefixed by @samp{=}.
29261
29262@item
29263@cindex console output in @sc{gdb/mi}
29264@var{console-stream-output} is output that should be displayed as is in the
29265console. It is the textual response to a CLI command. All the console
29266output is prefixed by @samp{~}.
29267
29268@item
29269@cindex target output in @sc{gdb/mi}
29270@var{target-stream-output} is the output produced by the target program.
29271All the target output is prefixed by @samp{@@}.
29272
29273@item
29274@cindex log output in @sc{gdb/mi}
29275@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29276instance messages that should be displayed as part of an error log. All
29277the log output is prefixed by @samp{&}.
29278
29279@item
29280@cindex list output in @sc{gdb/mi}
29281New @sc{gdb/mi} commands should only output @var{lists} containing
29282@var{values}.
29283
29284
29285@end itemize
29286
29287@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29288details about the various output records.
29289
922fbb7b
AC
29290@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29291@node GDB/MI Compatibility with CLI
29292@section @sc{gdb/mi} Compatibility with CLI
29293
29294@cindex compatibility, @sc{gdb/mi} and CLI
29295@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 29296
a2c02241
NR
29297For the developers convenience CLI commands can be entered directly,
29298but there may be some unexpected behaviour. For example, commands
29299that query the user will behave as if the user replied yes, breakpoint
29300command lists are not executed and some CLI commands, such as
29301@code{if}, @code{when} and @code{define}, prompt for further input with
29302@samp{>}, which is not valid MI output.
ef21caaf
NR
29303
29304This feature may be removed at some stage in the future and it is
a2c02241
NR
29305recommended that front ends use the @code{-interpreter-exec} command
29306(@pxref{-interpreter-exec}).
922fbb7b 29307
af6eff6f
NR
29308@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29309@node GDB/MI Development and Front Ends
29310@section @sc{gdb/mi} Development and Front Ends
29311@cindex @sc{gdb/mi} development
29312
29313The application which takes the MI output and presents the state of the
29314program being debugged to the user is called a @dfn{front end}.
29315
1fea0d53
SM
29316Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29317to the MI interface may break existing usage. This section describes how the
29318protocol changes and how to request previous version of the protocol when it
29319does.
af6eff6f
NR
29320
29321Some changes in MI need not break a carefully designed front end, and
29322for these the MI version will remain unchanged. The following is a
29323list of changes that may occur within one level, so front ends should
29324parse MI output in a way that can handle them:
29325
29326@itemize @bullet
29327@item
29328New MI commands may be added.
29329
29330@item
29331New fields may be added to the output of any MI command.
29332
36ece8b3
NR
29333@item
29334The range of values for fields with specified values, e.g.,
9f708cb2 29335@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 29336
af6eff6f
NR
29337@c The format of field's content e.g type prefix, may change so parse it
29338@c at your own risk. Yes, in general?
29339
29340@c The order of fields may change? Shouldn't really matter but it might
29341@c resolve inconsistencies.
29342@end itemize
29343
29344If the changes are likely to break front ends, the MI version level
1fea0d53
SM
29345will be increased by one. The new versions of the MI protocol are not compatible
29346with the old versions. Old versions of MI remain available, allowing front ends
29347to keep using them until they are modified to use the latest MI version.
af6eff6f 29348
1fea0d53
SM
29349Since @code{--interpreter=mi} always points to the latest MI version, it is
29350recommended that front ends request a specific version of MI when launching
29351@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29352interpreter with the MI version they expect.
29353
09f2921c 29354The following table gives a summary of the released versions of the MI
1fea0d53
SM
29355interface: the version number, the version of GDB in which it first appeared
29356and the breaking changes compared to the previous version.
29357
29358@multitable @columnfractions .05 .05 .9
29359@headitem MI version @tab GDB version @tab Breaking changes
29360
29361@item
29362@center 1
29363@tab
29364@center 5.1
29365@tab
29366None
29367
29368@item
29369@center 2
29370@tab
29371@center 6.0
29372@tab
29373
29374@itemize
29375@item
29376The @code{-environment-pwd}, @code{-environment-directory} and
29377@code{-environment-path} commands now returns values using the MI output
29378syntax, rather than CLI output syntax.
29379
29380@item
29381@code{-var-list-children}'s @code{children} result field is now a list, rather
29382than a tuple.
29383
29384@item
29385@code{-var-update}'s @code{changelist} result field is now a list, rather than
29386a tuple.
29387@end itemize
29388
b4be1b06
SM
29389@item
29390@center 3
29391@tab
29392@center 9.1
29393@tab
29394
29395@itemize
29396@item
29397The output of information about multi-location breakpoints has changed in the
29398responses to the @code{-break-insert} and @code{-break-info} commands, as well
29399as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29400The multiple locations are now placed in a @code{locations} field, whose value
29401is a list.
29402@end itemize
29403
1fea0d53 29404@end multitable
af6eff6f 29405
b4be1b06
SM
29406If your front end cannot yet migrate to a more recent version of the
29407MI protocol, you can nevertheless selectively enable specific features
29408available in those recent MI versions, using the following commands:
29409
29410@table @code
29411
29412@item -fix-multi-location-breakpoint-output
29413Use the output for multi-location breakpoints which was introduced by
29414MI 3, even when using MI versions 2 or 1. This command has no
29415effect when using MI version 3 or later.
29416
5c85e20d 29417@end table
b4be1b06 29418
af6eff6f
NR
29419The best way to avoid unexpected changes in MI that might break your front
29420end is to make your project known to @value{GDBN} developers and
7a9a6b69 29421follow development on @email{gdb@@sourceware.org} and
fa0f268d 29422@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
29423@cindex mailing lists
29424
922fbb7b
AC
29425@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29426@node GDB/MI Output Records
29427@section @sc{gdb/mi} Output Records
29428
29429@menu
29430* GDB/MI Result Records::
29431* GDB/MI Stream Records::
82f68b1c 29432* GDB/MI Async Records::
54516a0b 29433* GDB/MI Breakpoint Information::
c3b108f7 29434* GDB/MI Frame Information::
dc146f7c 29435* GDB/MI Thread Information::
4368ebeb 29436* GDB/MI Ada Exception Information::
922fbb7b
AC
29437@end menu
29438
29439@node GDB/MI Result Records
29440@subsection @sc{gdb/mi} Result Records
29441
29442@cindex result records in @sc{gdb/mi}
29443@cindex @sc{gdb/mi}, result records
29444In addition to a number of out-of-band notifications, the response to a
29445@sc{gdb/mi} command includes one of the following result indications:
29446
29447@table @code
29448@findex ^done
29449@item "^done" [ "," @var{results} ]
29450The synchronous operation was successful, @code{@var{results}} are the return
29451values.
29452
29453@item "^running"
29454@findex ^running
8e9c5e02
VP
29455This result record is equivalent to @samp{^done}. Historically, it
29456was output instead of @samp{^done} if the command has resumed the
29457target. This behaviour is maintained for backward compatibility, but
29458all frontends should treat @samp{^done} and @samp{^running}
29459identically and rely on the @samp{*running} output record to determine
29460which threads are resumed.
922fbb7b 29461
ef21caaf
NR
29462@item "^connected"
29463@findex ^connected
3f94c067 29464@value{GDBN} has connected to a remote target.
ef21caaf 29465
2ea126fa 29466@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 29467@findex ^error
2ea126fa
JB
29468The operation failed. The @code{msg=@var{c-string}} variable contains
29469the corresponding error message.
29470
29471If present, the @code{code=@var{c-string}} variable provides an error
29472code on which consumers can rely on to detect the corresponding
29473error condition. At present, only one error code is defined:
29474
29475@table @samp
29476@item "undefined-command"
29477Indicates that the command causing the error does not exist.
29478@end table
ef21caaf
NR
29479
29480@item "^exit"
29481@findex ^exit
3f94c067 29482@value{GDBN} has terminated.
ef21caaf 29483
922fbb7b
AC
29484@end table
29485
29486@node GDB/MI Stream Records
29487@subsection @sc{gdb/mi} Stream Records
29488
29489@cindex @sc{gdb/mi}, stream records
29490@cindex stream records in @sc{gdb/mi}
29491@value{GDBN} internally maintains a number of output streams: the console, the
29492target, and the log. The output intended for each of these streams is
29493funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29494
29495Each stream record begins with a unique @dfn{prefix character} which
29496identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29497Syntax}). In addition to the prefix, each stream record contains a
29498@code{@var{string-output}}. This is either raw text (with an implicit new
29499line) or a quoted C string (which does not contain an implicit newline).
29500
29501@table @code
29502@item "~" @var{string-output}
29503The console output stream contains text that should be displayed in the
29504CLI console window. It contains the textual responses to CLI commands.
29505
29506@item "@@" @var{string-output}
29507The target output stream contains any textual output from the running
ef21caaf
NR
29508target. This is only present when GDB's event loop is truly
29509asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29510
29511@item "&" @var{string-output}
29512The log stream contains debugging messages being produced by @value{GDBN}'s
29513internals.
29514@end table
29515
82f68b1c
VP
29516@node GDB/MI Async Records
29517@subsection @sc{gdb/mi} Async Records
922fbb7b 29518
82f68b1c
VP
29519@cindex async records in @sc{gdb/mi}
29520@cindex @sc{gdb/mi}, async records
29521@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29522additional changes that have occurred. Those changes can either be a
82f68b1c 29523consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29524target activity (e.g., target stopped).
29525
8eb41542 29526The following is the list of possible async records:
922fbb7b
AC
29527
29528@table @code
034dad6f 29529
e1ac3328 29530@item *running,thread-id="@var{thread}"
5d5658a1 29531The target is now running. The @var{thread} field can be the global
09f2921c 29532thread ID of the thread that is now running, and it can be
5d5658a1
PA
29533@samp{all} if all threads are running. The frontend should assume
29534that no interaction with a running thread is possible after this
29535notification is produced. The frontend should not assume that this
29536notification is output only once for any command. @value{GDBN} may
29537emit this notification several times, either for different threads,
29538because it cannot resume all threads together, or even for a single
29539thread, if the thread must be stepped though some code before letting
29540it run freely.
e1ac3328 29541
dc146f7c 29542@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29543The target has stopped. The @var{reason} field can have one of the
29544following values:
034dad6f
BR
29545
29546@table @code
29547@item breakpoint-hit
29548A breakpoint was reached.
29549@item watchpoint-trigger
29550A watchpoint was triggered.
29551@item read-watchpoint-trigger
29552A read watchpoint was triggered.
29553@item access-watchpoint-trigger
29554An access watchpoint was triggered.
29555@item function-finished
29556An -exec-finish or similar CLI command was accomplished.
29557@item location-reached
29558An -exec-until or similar CLI command was accomplished.
29559@item watchpoint-scope
29560A watchpoint has gone out of scope.
29561@item end-stepping-range
29562An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29563similar CLI command was accomplished.
29564@item exited-signalled
29565The inferior exited because of a signal.
29566@item exited
29567The inferior exited.
29568@item exited-normally
29569The inferior exited normally.
29570@item signal-received
29571A signal was received by the inferior.
36dfb11c
TT
29572@item solib-event
29573The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29574This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29575set or when a @code{catch load} or @code{catch unload} catchpoint is
29576in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29577@item fork
29578The inferior has forked. This is reported when @code{catch fork}
29579(@pxref{Set Catchpoints}) has been used.
29580@item vfork
29581The inferior has vforked. This is reported in when @code{catch vfork}
29582(@pxref{Set Catchpoints}) has been used.
29583@item syscall-entry
29584The inferior entered a system call. This is reported when @code{catch
29585syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29586@item syscall-return
36dfb11c
TT
29587The inferior returned from a system call. This is reported when
29588@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29589@item exec
29590The inferior called @code{exec}. This is reported when @code{catch exec}
29591(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29592@end table
29593
5d5658a1
PA
29594The @var{id} field identifies the global thread ID of the thread
29595that directly caused the stop -- for example by hitting a breakpoint.
29596Depending on whether all-stop
c3b108f7
VP
29597mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29598stop all threads, or only the thread that directly triggered the stop.
29599If all threads are stopped, the @var{stopped} field will have the
29600value of @code{"all"}. Otherwise, the value of the @var{stopped}
29601field will be a list of thread identifiers. Presently, this list will
29602always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29603several threads in the list. The @var{core} field reports the
29604processor core on which the stop event has happened. This field may be absent
29605if such information is not available.
c3b108f7 29606
a79b8f6e
VP
29607@item =thread-group-added,id="@var{id}"
29608@itemx =thread-group-removed,id="@var{id}"
29609A thread group was either added or removed. The @var{id} field
29610contains the @value{GDBN} identifier of the thread group. When a thread
29611group is added, it generally might not be associated with a running
29612process. When a thread group is removed, its id becomes invalid and
29613cannot be used in any way.
29614
29615@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29616A thread group became associated with a running program,
29617either because the program was just started or the thread group
29618was attached to a program. The @var{id} field contains the
29619@value{GDBN} identifier of the thread group. The @var{pid} field
29620contains process identifier, specific to the operating system.
29621
8cf64490 29622@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29623A thread group is no longer associated with a running program,
29624either because the program has exited, or because it was detached
c3b108f7 29625from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29626thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29627only when the inferior exited with some code.
c3b108f7
VP
29628
29629@item =thread-created,id="@var{id}",group-id="@var{gid}"
29630@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29631A thread either was created, or has exited. The @var{id} field
5d5658a1 29632contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29633field identifies the thread group this thread belongs to.
66bb093b 29634
4034d0ff
AT
29635@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29636Informs that the selected thread or frame were changed. This notification
29637is not emitted as result of the @code{-thread-select} or
29638@code{-stack-select-frame} commands, but is emitted whenever an MI command
29639that is not documented to change the selected thread and frame actually
29640changes them. In particular, invoking, directly or indirectly
29641(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29642will generate this notification. Changing the thread or frame from another
29643user interface (see @ref{Interpreters}) will also generate this notification.
29644
29645The @var{frame} field is only present if the newly selected thread is
29646stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29647
29648We suggest that in response to this notification, front ends
29649highlight the selected thread and cause subsequent commands to apply to
29650that thread.
29651
c86cf029
VP
29652@item =library-loaded,...
29653Reports that a new library file was loaded by the program. This
51457a05
MAL
29654notification has 5 fields---@var{id}, @var{target-name},
29655@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29656opaque identifier of the library. For remote debugging case,
29657@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29658library file on the target, and on the host respectively. For native
29659debugging, both those fields have the same value. The
f1cbe1d3
TT
29660@var{symbols-loaded} field is emitted only for backward compatibility
29661and should not be relied on to convey any useful information. The
29662@var{thread-group} field, if present, specifies the id of the thread
29663group in whose context the library was loaded. If the field is
29664absent, it means the library was loaded in the context of all present
51457a05
MAL
29665thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29666to this library.
c86cf029
VP
29667
29668@item =library-unloaded,...
134eb42c 29669Reports that a library was unloaded by the program. This notification
c86cf029 29670has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29671the same meaning as for the @code{=library-loaded} notification.
29672The @var{thread-group} field, if present, specifies the id of the
29673thread group in whose context the library was unloaded. If the field is
29674absent, it means the library was unloaded in the context of all present
29675thread groups.
c86cf029 29676
201b4506
YQ
29677@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29678@itemx =traceframe-changed,end
29679Reports that the trace frame was changed and its new number is
29680@var{tfnum}. The number of the tracepoint associated with this trace
29681frame is @var{tpnum}.
29682
134a2066 29683@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29684Reports that the new trace state variable @var{name} is created with
134a2066 29685initial value @var{initial}.
bb25a15c
YQ
29686
29687@item =tsv-deleted,name=@var{name}
29688@itemx =tsv-deleted
29689Reports that the trace state variable @var{name} is deleted or all
29690trace state variables are deleted.
29691
134a2066
YQ
29692@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29693Reports that the trace state variable @var{name} is modified with
29694the initial value @var{initial}. The current value @var{current} of
29695trace state variable is optional and is reported if the current
29696value of trace state variable is known.
29697
8d3788bd
VP
29698@item =breakpoint-created,bkpt=@{...@}
29699@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29700@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29701Reports that a breakpoint was created, modified, or deleted,
29702respectively. Only user-visible breakpoints are reported to the MI
29703user.
29704
29705The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29706breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29707@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29708
29709Note that if a breakpoint is emitted in the result record of a
29710command, then it will not also be emitted in an async record.
29711
38b022b4 29712@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29713@itemx =record-stopped,thread-group="@var{id}"
29714Execution log recording was either started or stopped on an
29715inferior. The @var{id} is the @value{GDBN} identifier of the thread
29716group corresponding to the affected inferior.
29717
38b022b4
SM
29718The @var{method} field indicates the method used to record execution. If the
29719method in use supports multiple recording formats, @var{format} will be present
8504e097 29720and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29721for existing method and format values.
29722
5b9afe8a
YQ
29723@item =cmd-param-changed,param=@var{param},value=@var{value}
29724Reports that a parameter of the command @code{set @var{param}} is
29725changed to @var{value}. In the multi-word @code{set} command,
29726the @var{param} is the whole parameter list to @code{set} command.
29727For example, In command @code{set check type on}, @var{param}
29728is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29729
29730@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29731Reports that bytes from @var{addr} to @var{data} + @var{len} were
29732written in an inferior. The @var{id} is the identifier of the
29733thread group corresponding to the affected inferior. The optional
29734@code{type="code"} part is reported if the memory written to holds
29735executable code.
82f68b1c
VP
29736@end table
29737
54516a0b
TT
29738@node GDB/MI Breakpoint Information
29739@subsection @sc{gdb/mi} Breakpoint Information
29740
29741When @value{GDBN} reports information about a breakpoint, a
29742tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29743following fields:
29744
29745@table @code
29746@item number
b4be1b06 29747The breakpoint number.
54516a0b
TT
29748
29749@item type
29750The type of the breakpoint. For ordinary breakpoints this will be
29751@samp{breakpoint}, but many values are possible.
29752
8ac3646f
TT
29753@item catch-type
29754If the type of the breakpoint is @samp{catchpoint}, then this
29755indicates the exact type of catchpoint.
29756
54516a0b
TT
29757@item disp
29758This is the breakpoint disposition---either @samp{del}, meaning that
29759the breakpoint will be deleted at the next stop, or @samp{keep},
29760meaning that the breakpoint will not be deleted.
29761
29762@item enabled
29763This indicates whether the breakpoint is enabled, in which case the
29764value is @samp{y}, or disabled, in which case the value is @samp{n}.
29765Note that this is not the same as the field @code{enable}.
29766
29767@item addr
29768The address of the breakpoint. This may be a hexidecimal number,
29769giving the address; or the string @samp{<PENDING>}, for a pending
29770breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29771multiple locations. This field will not be present if no address can
29772be determined. For example, a watchpoint does not have an address.
29773
aa7ca1bb
AH
29774@item addr_flags
29775Optional field containing any flags related to the address. These flags are
29776architecture-dependent; see @ref{Architectures} for their meaning for a
29777particular CPU.
29778
54516a0b
TT
29779@item func
29780If known, the function in which the breakpoint appears.
29781If not known, this field is not present.
29782
29783@item filename
29784The name of the source file which contains this function, if known.
29785If not known, this field is not present.
29786
29787@item fullname
29788The full file name of the source file which contains this function, if
29789known. If not known, this field is not present.
29790
29791@item line
29792The line number at which this breakpoint appears, if known.
29793If not known, this field is not present.
29794
29795@item at
29796If the source file is not known, this field may be provided. If
29797provided, this holds the address of the breakpoint, possibly followed
29798by a symbol name.
29799
29800@item pending
29801If this breakpoint is pending, this field is present and holds the
29802text used to set the breakpoint, as entered by the user.
29803
29804@item evaluated-by
29805Where this breakpoint's condition is evaluated, either @samp{host} or
29806@samp{target}.
29807
29808@item thread
29809If this is a thread-specific breakpoint, then this identifies the
29810thread in which the breakpoint can trigger.
29811
29812@item task
29813If this breakpoint is restricted to a particular Ada task, then this
29814field will hold the task identifier.
29815
29816@item cond
29817If the breakpoint is conditional, this is the condition expression.
29818
29819@item ignore
29820The ignore count of the breakpoint.
29821
29822@item enable
29823The enable count of the breakpoint.
29824
29825@item traceframe-usage
29826FIXME.
29827
29828@item static-tracepoint-marker-string-id
29829For a static tracepoint, the name of the static tracepoint marker.
29830
29831@item mask
29832For a masked watchpoint, this is the mask.
29833
29834@item pass
29835A tracepoint's pass count.
29836
29837@item original-location
29838The location of the breakpoint as originally specified by the user.
29839This field is optional.
29840
29841@item times
29842The number of times the breakpoint has been hit.
29843
29844@item installed
29845This field is only given for tracepoints. This is either @samp{y},
29846meaning that the tracepoint is installed, or @samp{n}, meaning that it
29847is not.
29848
29849@item what
29850Some extra data, the exact contents of which are type-dependent.
29851
b4be1b06
SM
29852@item locations
29853This field is present if the breakpoint has multiple locations. It is also
29854exceptionally present if the breakpoint is enabled and has a single, disabled
29855location.
29856
6b92c0d3 29857The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29858
29859@end table
29860
29861A location in a multi-location breakpoint is represented as a tuple with the
29862following fields:
29863
29864@table @code
29865
29866@item number
29867The location number as a dotted pair, like @samp{1.2}. The first digit is the
29868number of the parent breakpoint. The second digit is the number of the
29869location within that breakpoint.
29870
29871@item enabled
29872This indicates whether the location is enabled, in which case the
29873value is @samp{y}, or disabled, in which case the value is @samp{n}.
29874Note that this is not the same as the field @code{enable}.
29875
29876@item addr
29877The address of this location as an hexidecimal number.
29878
aa7ca1bb
AH
29879@item addr_flags
29880Optional field containing any flags related to the address. These flags are
29881architecture-dependent; see @ref{Architectures} for their meaning for a
29882particular CPU.
29883
b4be1b06
SM
29884@item func
29885If known, the function in which the location appears.
29886If not known, this field is not present.
29887
29888@item file
29889The name of the source file which contains this location, if known.
29890If not known, this field is not present.
29891
29892@item fullname
29893The full file name of the source file which contains this location, if
29894known. If not known, this field is not present.
29895
29896@item line
29897The line number at which this location appears, if known.
29898If not known, this field is not present.
29899
29900@item thread-groups
29901The thread groups this location is in.
29902
54516a0b
TT
29903@end table
29904
29905For example, here is what the output of @code{-break-insert}
29906(@pxref{GDB/MI Breakpoint Commands}) might be:
29907
29908@smallexample
29909-> -break-insert main
29910<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29911 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29912 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29913 times="0"@}
54516a0b
TT
29914<- (gdb)
29915@end smallexample
29916
c3b108f7
VP
29917@node GDB/MI Frame Information
29918@subsection @sc{gdb/mi} Frame Information
29919
29920Response from many MI commands includes an information about stack
29921frame. This information is a tuple that may have the following
29922fields:
29923
29924@table @code
29925@item level
29926The level of the stack frame. The innermost frame has the level of
29927zero. This field is always present.
29928
29929@item func
29930The name of the function corresponding to the frame. This field may
29931be absent if @value{GDBN} is unable to determine the function name.
29932
29933@item addr
29934The code address for the frame. This field is always present.
29935
aa7ca1bb
AH
29936@item addr_flags
29937Optional field containing any flags related to the address. These flags are
29938architecture-dependent; see @ref{Architectures} for their meaning for a
29939particular CPU.
29940
c3b108f7
VP
29941@item file
29942The name of the source files that correspond to the frame's code
29943address. This field may be absent.
29944
29945@item line
29946The source line corresponding to the frames' code address. This field
29947may be absent.
29948
29949@item from
29950The name of the binary file (either executable or shared library) the
29951corresponds to the frame's code address. This field may be absent.
29952
29953@end table
82f68b1c 29954
dc146f7c
VP
29955@node GDB/MI Thread Information
29956@subsection @sc{gdb/mi} Thread Information
29957
29958Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
29959uses a tuple with the following fields. The fields are always present unless
29960stated otherwise.
dc146f7c
VP
29961
29962@table @code
29963@item id
ebe553db 29964The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
29965
29966@item target-id
ebe553db 29967The target-specific string identifying the thread.
dc146f7c
VP
29968
29969@item details
29970Additional information about the thread provided by the target.
29971It is supposed to be human-readable and not interpreted by the
29972frontend. This field is optional.
29973
ebe553db
SM
29974@item name
29975The name of the thread. If the user specified a name using the
29976@code{thread name} command, then this name is given. Otherwise, if
29977@value{GDBN} can extract the thread name from the target, then that
29978name is given. If @value{GDBN} cannot find the thread name, then this
29979field is omitted.
29980
dc146f7c 29981@item state
ebe553db
SM
29982The execution state of the thread, either @samp{stopped} or @samp{running},
29983depending on whether the thread is presently running.
29984
29985@item frame
29986The stack frame currently executing in the thread. This field is only present
29987if the thread is stopped. Its format is documented in
29988@ref{GDB/MI Frame Information}.
dc146f7c
VP
29989
29990@item core
29991The value of this field is an integer number of the processor core the
29992thread was last seen on. This field is optional.
29993@end table
29994
956a9fb9
JB
29995@node GDB/MI Ada Exception Information
29996@subsection @sc{gdb/mi} Ada Exception Information
29997
29998Whenever a @code{*stopped} record is emitted because the program
29999stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30000@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
30001the @code{exception-name} field. Also, for exceptions that were raised
30002with an exception message, @value{GDBN} provides that message via
30003the @code{exception-message} field.
922fbb7b 30004
ef21caaf
NR
30005@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30006@node GDB/MI Simple Examples
30007@section Simple Examples of @sc{gdb/mi} Interaction
30008@cindex @sc{gdb/mi}, simple examples
30009
30010This subsection presents several simple examples of interaction using
30011the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30012following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30013the output received from @sc{gdb/mi}.
30014
d3e8051b 30015Note the line breaks shown in the examples are here only for
ef21caaf
NR
30016readability, they don't appear in the real output.
30017
79a6e687 30018@subheading Setting a Breakpoint
ef21caaf
NR
30019
30020Setting a breakpoint generates synchronous output which contains detailed
30021information of the breakpoint.
30022
30023@smallexample
30024-> -break-insert main
30025<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30026 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
30027 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30028 times="0"@}
ef21caaf
NR
30029<- (gdb)
30030@end smallexample
30031
30032@subheading Program Execution
30033
30034Program execution generates asynchronous records and MI gives the
30035reason that execution stopped.
30036
30037@smallexample
30038-> -exec-run
30039<- ^running
30040<- (gdb)
a47ec5fe 30041<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
30042 frame=@{addr="0x08048564",func="main",
30043 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
30044 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30045 arch="i386:x86_64"@}
ef21caaf
NR
30046<- (gdb)
30047-> -exec-continue
30048<- ^running
30049<- (gdb)
30050<- *stopped,reason="exited-normally"
30051<- (gdb)
30052@end smallexample
30053
3f94c067 30054@subheading Quitting @value{GDBN}
ef21caaf 30055
3f94c067 30056Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
30057
30058@smallexample
30059-> (gdb)
30060<- -gdb-exit
30061<- ^exit
30062@end smallexample
30063
a6b29f87
VP
30064Please note that @samp{^exit} is printed immediately, but it might
30065take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30066performs necessary cleanups, including killing programs being debugged
30067or disconnecting from debug hardware, so the frontend should wait till
30068@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30069fails to exit in reasonable time.
30070
a2c02241 30071@subheading A Bad Command
ef21caaf
NR
30072
30073Here's what happens if you pass a non-existent command:
30074
30075@smallexample
30076-> -rubbish
30077<- ^error,msg="Undefined MI command: rubbish"
594fe323 30078<- (gdb)
ef21caaf
NR
30079@end smallexample
30080
30081
922fbb7b
AC
30082@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30083@node GDB/MI Command Description Format
30084@section @sc{gdb/mi} Command Description Format
30085
30086The remaining sections describe blocks of commands. Each block of
30087commands is laid out in a fashion similar to this section.
30088
922fbb7b
AC
30089@subheading Motivation
30090
30091The motivation for this collection of commands.
30092
30093@subheading Introduction
30094
30095A brief introduction to this collection of commands as a whole.
30096
30097@subheading Commands
30098
30099For each command in the block, the following is described:
30100
30101@subsubheading Synopsis
30102
30103@smallexample
30104 -command @var{args}@dots{}
30105@end smallexample
30106
922fbb7b
AC
30107@subsubheading Result
30108
265eeb58 30109@subsubheading @value{GDBN} Command
922fbb7b 30110
265eeb58 30111The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
30112
30113@subsubheading Example
30114
ef21caaf
NR
30115Example(s) formatted for readability. Some of the described commands have
30116not been implemented yet and these are labeled N.A.@: (not available).
30117
30118
922fbb7b 30119@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
30120@node GDB/MI Breakpoint Commands
30121@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
30122
30123@cindex breakpoint commands for @sc{gdb/mi}
30124@cindex @sc{gdb/mi}, breakpoint commands
30125This section documents @sc{gdb/mi} commands for manipulating
30126breakpoints.
30127
30128@subheading The @code{-break-after} Command
30129@findex -break-after
30130
30131@subsubheading Synopsis
30132
30133@smallexample
30134 -break-after @var{number} @var{count}
30135@end smallexample
30136
30137The breakpoint number @var{number} is not in effect until it has been
30138hit @var{count} times. To see how this is reflected in the output of
30139the @samp{-break-list} command, see the description of the
30140@samp{-break-list} command below.
30141
30142@subsubheading @value{GDBN} Command
30143
30144The corresponding @value{GDBN} command is @samp{ignore}.
30145
30146@subsubheading Example
30147
30148@smallexample
594fe323 30149(gdb)
922fbb7b 30150-break-insert main
a47ec5fe
AR
30151^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30152enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
30153fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30154times="0"@}
594fe323 30155(gdb)
922fbb7b
AC
30156-break-after 1 3
30157~
30158^done
594fe323 30159(gdb)
922fbb7b
AC
30160-break-list
30161^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30162hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30163@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30164@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30165@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30166@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30167@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30168body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30169addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30170line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 30171(gdb)
922fbb7b
AC
30172@end smallexample
30173
30174@ignore
30175@subheading The @code{-break-catch} Command
30176@findex -break-catch
48cb2d85 30177@end ignore
922fbb7b
AC
30178
30179@subheading The @code{-break-commands} Command
30180@findex -break-commands
922fbb7b 30181
48cb2d85
VP
30182@subsubheading Synopsis
30183
30184@smallexample
30185 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30186@end smallexample
30187
30188Specifies the CLI commands that should be executed when breakpoint
30189@var{number} is hit. The parameters @var{command1} to @var{commandN}
30190are the commands. If no command is specified, any previously-set
30191commands are cleared. @xref{Break Commands}. Typical use of this
30192functionality is tracing a program, that is, printing of values of
30193some variables whenever breakpoint is hit and then continuing.
30194
30195@subsubheading @value{GDBN} Command
30196
30197The corresponding @value{GDBN} command is @samp{commands}.
30198
30199@subsubheading Example
30200
30201@smallexample
30202(gdb)
30203-break-insert main
30204^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30205enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
30206fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30207times="0"@}
48cb2d85
VP
30208(gdb)
30209-break-commands 1 "print v" "continue"
30210^done
30211(gdb)
30212@end smallexample
922fbb7b
AC
30213
30214@subheading The @code{-break-condition} Command
30215@findex -break-condition
30216
30217@subsubheading Synopsis
30218
30219@smallexample
30220 -break-condition @var{number} @var{expr}
30221@end smallexample
30222
30223Breakpoint @var{number} will stop the program only if the condition in
30224@var{expr} is true. The condition becomes part of the
30225@samp{-break-list} output (see the description of the @samp{-break-list}
30226command below).
30227
30228@subsubheading @value{GDBN} Command
30229
30230The corresponding @value{GDBN} command is @samp{condition}.
30231
30232@subsubheading Example
30233
30234@smallexample
594fe323 30235(gdb)
922fbb7b
AC
30236-break-condition 1 1
30237^done
594fe323 30238(gdb)
922fbb7b
AC
30239-break-list
30240^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30241hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30242@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30243@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30244@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30245@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30246@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30247body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30248addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30249line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 30250(gdb)
922fbb7b
AC
30251@end smallexample
30252
30253@subheading The @code{-break-delete} Command
30254@findex -break-delete
30255
30256@subsubheading Synopsis
30257
30258@smallexample
30259 -break-delete ( @var{breakpoint} )+
30260@end smallexample
30261
30262Delete the breakpoint(s) whose number(s) are specified in the argument
30263list. This is obviously reflected in the breakpoint list.
30264
79a6e687 30265@subsubheading @value{GDBN} Command
922fbb7b
AC
30266
30267The corresponding @value{GDBN} command is @samp{delete}.
30268
30269@subsubheading Example
30270
30271@smallexample
594fe323 30272(gdb)
922fbb7b
AC
30273-break-delete 1
30274^done
594fe323 30275(gdb)
922fbb7b
AC
30276-break-list
30277^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30278hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30279@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30280@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30281@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30282@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30283@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30284body=[]@}
594fe323 30285(gdb)
922fbb7b
AC
30286@end smallexample
30287
30288@subheading The @code{-break-disable} Command
30289@findex -break-disable
30290
30291@subsubheading Synopsis
30292
30293@smallexample
30294 -break-disable ( @var{breakpoint} )+
30295@end smallexample
30296
30297Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30298break list is now set to @samp{n} for the named @var{breakpoint}(s).
30299
30300@subsubheading @value{GDBN} Command
30301
30302The corresponding @value{GDBN} command is @samp{disable}.
30303
30304@subsubheading Example
30305
30306@smallexample
594fe323 30307(gdb)
922fbb7b
AC
30308-break-disable 2
30309^done
594fe323 30310(gdb)
922fbb7b
AC
30311-break-list
30312^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30313hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30314@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30315@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30316@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30317@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30318@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30319body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 30320addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30321line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30322(gdb)
922fbb7b
AC
30323@end smallexample
30324
30325@subheading The @code{-break-enable} Command
30326@findex -break-enable
30327
30328@subsubheading Synopsis
30329
30330@smallexample
30331 -break-enable ( @var{breakpoint} )+
30332@end smallexample
30333
30334Enable (previously disabled) @var{breakpoint}(s).
30335
30336@subsubheading @value{GDBN} Command
30337
30338The corresponding @value{GDBN} command is @samp{enable}.
30339
30340@subsubheading Example
30341
30342@smallexample
594fe323 30343(gdb)
922fbb7b
AC
30344-break-enable 2
30345^done
594fe323 30346(gdb)
922fbb7b
AC
30347-break-list
30348^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30349hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30350@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30351@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30352@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30353@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30354@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30355body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30356addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30357line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30358(gdb)
922fbb7b
AC
30359@end smallexample
30360
30361@subheading The @code{-break-info} Command
30362@findex -break-info
30363
30364@subsubheading Synopsis
30365
30366@smallexample
30367 -break-info @var{breakpoint}
30368@end smallexample
30369
30370@c REDUNDANT???
30371Get information about a single breakpoint.
30372
54516a0b
TT
30373The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30374Information}, for details on the format of each breakpoint in the
30375table.
30376
79a6e687 30377@subsubheading @value{GDBN} Command
922fbb7b
AC
30378
30379The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30380
30381@subsubheading Example
30382N.A.
30383
30384@subheading The @code{-break-insert} Command
30385@findex -break-insert
629500fa 30386@anchor{-break-insert}
922fbb7b
AC
30387
30388@subsubheading Synopsis
30389
30390@smallexample
6791b117 30391 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
922fbb7b 30392 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 30393 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
30394@end smallexample
30395
30396@noindent
afe8ab22 30397If specified, @var{location}, can be one of:
922fbb7b 30398
629500fa
KS
30399@table @var
30400@item linespec location
30401A linespec location. @xref{Linespec Locations}.
30402
30403@item explicit location
30404An explicit location. @sc{gdb/mi} explicit locations are
30405analogous to the CLI's explicit locations using the option names
30406listed below. @xref{Explicit Locations}.
30407
30408@table @samp
30409@item --source @var{filename}
30410The source file name of the location. This option requires the use
30411of either @samp{--function} or @samp{--line}.
30412
30413@item --function @var{function}
30414The name of a function or method.
922fbb7b 30415
629500fa
KS
30416@item --label @var{label}
30417The name of a label.
30418
30419@item --line @var{lineoffset}
30420An absolute or relative line offset from the start of the location.
30421@end table
30422
30423@item address location
30424An address location, *@var{address}. @xref{Address Locations}.
30425@end table
30426
30427@noindent
922fbb7b
AC
30428The possible optional parameters of this command are:
30429
30430@table @samp
30431@item -t
948d5102 30432Insert a temporary breakpoint.
922fbb7b
AC
30433@item -h
30434Insert a hardware breakpoint.
afe8ab22
VP
30435@item -f
30436If @var{location} cannot be parsed (for example if it
30437refers to unknown files or functions), create a pending
30438breakpoint. Without this flag, @value{GDBN} will report
30439an error, and won't create a breakpoint, if @var{location}
30440cannot be parsed.
41447f92
VP
30441@item -d
30442Create a disabled breakpoint.
18148017
VP
30443@item -a
30444Create a tracepoint. @xref{Tracepoints}. When this parameter
30445is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
30446@item -c @var{condition}
30447Make the breakpoint conditional on @var{condition}.
30448@item -i @var{ignore-count}
30449Initialize the @var{ignore-count}.
30450@item -p @var{thread-id}
5d5658a1
PA
30451Restrict the breakpoint to the thread with the specified global
30452@var{thread-id}.
6791b117
PA
30453@item --qualified
30454This option makes @value{GDBN} interpret a function name specified as
30455a complete fully-qualified name.
922fbb7b
AC
30456@end table
30457
30458@subsubheading Result
30459
54516a0b
TT
30460@xref{GDB/MI Breakpoint Information}, for details on the format of the
30461resulting breakpoint.
922fbb7b
AC
30462
30463Note: this format is open to change.
30464@c An out-of-band breakpoint instead of part of the result?
30465
30466@subsubheading @value{GDBN} Command
30467
30468The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 30469@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
30470
30471@subsubheading Example
30472
30473@smallexample
594fe323 30474(gdb)
922fbb7b 30475-break-insert main
948d5102 30476^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30477fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30478times="0"@}
594fe323 30479(gdb)
922fbb7b 30480-break-insert -t foo
948d5102 30481^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30482fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30483times="0"@}
594fe323 30484(gdb)
922fbb7b
AC
30485-break-list
30486^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30487hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30488@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30489@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30490@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30491@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30492@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30493body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30494addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30495fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30496times="0"@},
922fbb7b 30497bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30498addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30499fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30500times="0"@}]@}
594fe323 30501(gdb)
496ee73e
KS
30502@c -break-insert -r foo.*
30503@c ~int foo(int, int);
30504@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30505@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30506@c times="0"@}
496ee73e 30507@c (gdb)
922fbb7b
AC
30508@end smallexample
30509
c5867ab6
HZ
30510@subheading The @code{-dprintf-insert} Command
30511@findex -dprintf-insert
30512
30513@subsubheading Synopsis
30514
30515@smallexample
6791b117 30516 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
c5867ab6
HZ
30517 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30518 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30519 [ @var{argument} ]
30520@end smallexample
30521
30522@noindent
6791b117
PA
30523If supplied, @var{location} and @code{--qualified} may be specified
30524the same way as for the @code{-break-insert} command.
30525@xref{-break-insert}.
c5867ab6
HZ
30526
30527The possible optional parameters of this command are:
30528
30529@table @samp
30530@item -t
30531Insert a temporary breakpoint.
30532@item -f
30533If @var{location} cannot be parsed (for example, if it
30534refers to unknown files or functions), create a pending
30535breakpoint. Without this flag, @value{GDBN} will report
30536an error, and won't create a breakpoint, if @var{location}
30537cannot be parsed.
30538@item -d
30539Create a disabled breakpoint.
30540@item -c @var{condition}
30541Make the breakpoint conditional on @var{condition}.
30542@item -i @var{ignore-count}
30543Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30544to @var{ignore-count}.
30545@item -p @var{thread-id}
5d5658a1
PA
30546Restrict the breakpoint to the thread with the specified global
30547@var{thread-id}.
c5867ab6
HZ
30548@end table
30549
30550@subsubheading Result
30551
30552@xref{GDB/MI Breakpoint Information}, for details on the format of the
30553resulting breakpoint.
30554
30555@c An out-of-band breakpoint instead of part of the result?
30556
30557@subsubheading @value{GDBN} Command
30558
30559The corresponding @value{GDBN} command is @samp{dprintf}.
30560
30561@subsubheading Example
30562
30563@smallexample
30564(gdb)
305654-dprintf-insert foo "At foo entry\n"
305664^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30567addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30568fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30569times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30570original-location="foo"@}
30571(gdb)
305725-dprintf-insert 26 "arg=%d, g=%d\n" arg g
305735^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30574addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30575fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30576times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30577original-location="mi-dprintf.c:26"@}
30578(gdb)
30579@end smallexample
30580
922fbb7b
AC
30581@subheading The @code{-break-list} Command
30582@findex -break-list
30583
30584@subsubheading Synopsis
30585
30586@smallexample
30587 -break-list
30588@end smallexample
30589
30590Displays the list of inserted breakpoints, showing the following fields:
30591
30592@table @samp
30593@item Number
30594number of the breakpoint
30595@item Type
30596type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30597@item Disposition
30598should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30599or @samp{nokeep}
30600@item Enabled
30601is the breakpoint enabled or no: @samp{y} or @samp{n}
30602@item Address
30603memory location at which the breakpoint is set
30604@item What
30605logical location of the breakpoint, expressed by function name, file
30606name, line number
998580f1
MK
30607@item Thread-groups
30608list of thread groups to which this breakpoint applies
922fbb7b
AC
30609@item Times
30610number of times the breakpoint has been hit
30611@end table
30612
30613If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30614@code{body} field is an empty list.
30615
30616@subsubheading @value{GDBN} Command
30617
30618The corresponding @value{GDBN} command is @samp{info break}.
30619
30620@subsubheading Example
30621
30622@smallexample
594fe323 30623(gdb)
922fbb7b
AC
30624-break-list
30625^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30626hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30627@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30628@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30629@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30630@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30631@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30632body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30633addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30634times="0"@},
922fbb7b 30635bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30636addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30637line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30638(gdb)
922fbb7b
AC
30639@end smallexample
30640
30641Here's an example of the result when there are no breakpoints:
30642
30643@smallexample
594fe323 30644(gdb)
922fbb7b
AC
30645-break-list
30646^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30647hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30648@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30649@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30650@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30651@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30652@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30653body=[]@}
594fe323 30654(gdb)
922fbb7b
AC
30655@end smallexample
30656
18148017
VP
30657@subheading The @code{-break-passcount} Command
30658@findex -break-passcount
30659
30660@subsubheading Synopsis
30661
30662@smallexample
30663 -break-passcount @var{tracepoint-number} @var{passcount}
30664@end smallexample
30665
30666Set the passcount for tracepoint @var{tracepoint-number} to
30667@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30668is not a tracepoint, error is emitted. This corresponds to CLI
30669command @samp{passcount}.
30670
922fbb7b
AC
30671@subheading The @code{-break-watch} Command
30672@findex -break-watch
30673
30674@subsubheading Synopsis
30675
30676@smallexample
30677 -break-watch [ -a | -r ]
30678@end smallexample
30679
30680Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30681@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30682read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30683option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30684trigger only when the memory location is accessed for reading. Without
30685either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30686i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30687@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30688
30689Note that @samp{-break-list} will report a single list of watchpoints and
30690breakpoints inserted.
30691
30692@subsubheading @value{GDBN} Command
30693
30694The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30695@samp{rwatch}.
30696
30697@subsubheading Example
30698
30699Setting a watchpoint on a variable in the @code{main} function:
30700
30701@smallexample
594fe323 30702(gdb)
922fbb7b
AC
30703-break-watch x
30704^done,wpt=@{number="2",exp="x"@}
594fe323 30705(gdb)
922fbb7b
AC
30706-exec-continue
30707^running
0869d01b
NR
30708(gdb)
30709*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30710value=@{old="-268439212",new="55"@},
76ff342d 30711frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30712fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30713(gdb)
922fbb7b
AC
30714@end smallexample
30715
30716Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30717the program execution twice: first for the variable changing value, then
30718for the watchpoint going out of scope.
30719
30720@smallexample
594fe323 30721(gdb)
922fbb7b
AC
30722-break-watch C
30723^done,wpt=@{number="5",exp="C"@}
594fe323 30724(gdb)
922fbb7b
AC
30725-exec-continue
30726^running
0869d01b
NR
30727(gdb)
30728*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30729wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30730frame=@{func="callee4",args=[],
76ff342d 30731file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30732fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30733arch="i386:x86_64"@}
594fe323 30734(gdb)
922fbb7b
AC
30735-exec-continue
30736^running
0869d01b
NR
30737(gdb)
30738*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30739frame=@{func="callee3",args=[@{name="strarg",
30740value="0x11940 \"A string argument.\""@}],
76ff342d 30741file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30742fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30743arch="i386:x86_64"@}
594fe323 30744(gdb)
922fbb7b
AC
30745@end smallexample
30746
30747Listing breakpoints and watchpoints, at different points in the program
30748execution. Note that once the watchpoint goes out of scope, it is
30749deleted.
30750
30751@smallexample
594fe323 30752(gdb)
922fbb7b
AC
30753-break-watch C
30754^done,wpt=@{number="2",exp="C"@}
594fe323 30755(gdb)
922fbb7b
AC
30756-break-list
30757^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30758hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30759@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30760@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30761@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30762@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30763@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30764body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30765addr="0x00010734",func="callee4",
948d5102 30766file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30767fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30768times="1"@},
922fbb7b 30769bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30770enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30771(gdb)
922fbb7b
AC
30772-exec-continue
30773^running
0869d01b
NR
30774(gdb)
30775*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30776value=@{old="-276895068",new="3"@},
30777frame=@{func="callee4",args=[],
76ff342d 30778file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30779fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30780arch="i386:x86_64"@}
594fe323 30781(gdb)
922fbb7b
AC
30782-break-list
30783^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30784hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30785@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30786@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30787@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30788@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30789@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30790body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30791addr="0x00010734",func="callee4",
948d5102 30792file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30793fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30794times="1"@},
922fbb7b 30795bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30796enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30797(gdb)
922fbb7b
AC
30798-exec-continue
30799^running
30800^done,reason="watchpoint-scope",wpnum="2",
30801frame=@{func="callee3",args=[@{name="strarg",
30802value="0x11940 \"A string argument.\""@}],
76ff342d 30803file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30804fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30805arch="i386:x86_64"@}
594fe323 30806(gdb)
922fbb7b
AC
30807-break-list
30808^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30809hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30810@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30811@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30812@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30813@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30814@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30815body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30816addr="0x00010734",func="callee4",
948d5102
NR
30817file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30818fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30819thread-groups=["i1"],times="1"@}]@}
594fe323 30820(gdb)
922fbb7b
AC
30821@end smallexample
30822
3fa7bf06
MG
30823
30824@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30825@node GDB/MI Catchpoint Commands
30826@section @sc{gdb/mi} Catchpoint Commands
30827
30828This section documents @sc{gdb/mi} commands for manipulating
30829catchpoints.
30830
40555925
JB
30831@menu
30832* Shared Library GDB/MI Catchpoint Commands::
30833* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30834* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30835@end menu
30836
30837@node Shared Library GDB/MI Catchpoint Commands
30838@subsection Shared Library @sc{gdb/mi} Catchpoints
30839
3fa7bf06
MG
30840@subheading The @code{-catch-load} Command
30841@findex -catch-load
30842
30843@subsubheading Synopsis
30844
30845@smallexample
30846 -catch-load [ -t ] [ -d ] @var{regexp}
30847@end smallexample
30848
30849Add a catchpoint for library load events. If the @samp{-t} option is used,
30850the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30851Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30852in a disabled state. The @samp{regexp} argument is a regular
30853expression used to match the name of the loaded library.
30854
30855
30856@subsubheading @value{GDBN} Command
30857
30858The corresponding @value{GDBN} command is @samp{catch load}.
30859
30860@subsubheading Example
30861
30862@smallexample
30863-catch-load -t foo.so
30864^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30865what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30866(gdb)
30867@end smallexample
30868
30869
30870@subheading The @code{-catch-unload} Command
30871@findex -catch-unload
30872
30873@subsubheading Synopsis
30874
30875@smallexample
30876 -catch-unload [ -t ] [ -d ] @var{regexp}
30877@end smallexample
30878
30879Add a catchpoint for library unload events. If the @samp{-t} option is
30880used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30881Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30882created in a disabled state. The @samp{regexp} argument is a regular
30883expression used to match the name of the unloaded library.
30884
30885@subsubheading @value{GDBN} Command
30886
30887The corresponding @value{GDBN} command is @samp{catch unload}.
30888
30889@subsubheading Example
30890
30891@smallexample
30892-catch-unload -d bar.so
30893^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30894what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30895(gdb)
30896@end smallexample
30897
40555925
JB
30898@node Ada Exception GDB/MI Catchpoint Commands
30899@subsection Ada Exception @sc{gdb/mi} Catchpoints
30900
30901The following @sc{gdb/mi} commands can be used to create catchpoints
30902that stop the execution when Ada exceptions are being raised.
30903
30904@subheading The @code{-catch-assert} Command
30905@findex -catch-assert
30906
30907@subsubheading Synopsis
30908
30909@smallexample
30910 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30911@end smallexample
30912
30913Add a catchpoint for failed Ada assertions.
30914
30915The possible optional parameters for this command are:
30916
30917@table @samp
30918@item -c @var{condition}
30919Make the catchpoint conditional on @var{condition}.
30920@item -d
30921Create a disabled catchpoint.
30922@item -t
30923Create a temporary catchpoint.
30924@end table
30925
30926@subsubheading @value{GDBN} Command
30927
30928The corresponding @value{GDBN} command is @samp{catch assert}.
30929
30930@subsubheading Example
30931
30932@smallexample
30933-catch-assert
30934^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30935enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30936thread-groups=["i1"],times="0",
30937original-location="__gnat_debug_raise_assert_failure"@}
30938(gdb)
30939@end smallexample
30940
30941@subheading The @code{-catch-exception} Command
30942@findex -catch-exception
30943
30944@subsubheading Synopsis
30945
30946@smallexample
30947 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30948 [ -t ] [ -u ]
30949@end smallexample
30950
30951Add a catchpoint stopping when Ada exceptions are raised.
30952By default, the command stops the program when any Ada exception
30953gets raised. But it is also possible, by using some of the
30954optional parameters described below, to create more selective
30955catchpoints.
30956
30957The possible optional parameters for this command are:
30958
30959@table @samp
30960@item -c @var{condition}
30961Make the catchpoint conditional on @var{condition}.
30962@item -d
30963Create a disabled catchpoint.
30964@item -e @var{exception-name}
30965Only stop when @var{exception-name} is raised. This option cannot
30966be used combined with @samp{-u}.
30967@item -t
30968Create a temporary catchpoint.
30969@item -u
30970Stop only when an unhandled exception gets raised. This option
30971cannot be used combined with @samp{-e}.
30972@end table
30973
30974@subsubheading @value{GDBN} Command
30975
30976The corresponding @value{GDBN} commands are @samp{catch exception}
30977and @samp{catch exception unhandled}.
30978
30979@subsubheading Example
30980
30981@smallexample
30982-catch-exception -e Program_Error
30983^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30984enabled="y",addr="0x0000000000404874",
30985what="`Program_Error' Ada exception", thread-groups=["i1"],
30986times="0",original-location="__gnat_debug_raise_exception"@}
30987(gdb)
30988@end smallexample
3fa7bf06 30989
bea298f9
XR
30990@subheading The @code{-catch-handlers} Command
30991@findex -catch-handlers
30992
30993@subsubheading Synopsis
30994
30995@smallexample
30996 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30997 [ -t ]
30998@end smallexample
30999
31000Add a catchpoint stopping when Ada exceptions are handled.
31001By default, the command stops the program when any Ada exception
31002gets handled. But it is also possible, by using some of the
31003optional parameters described below, to create more selective
31004catchpoints.
31005
31006The possible optional parameters for this command are:
31007
31008@table @samp
31009@item -c @var{condition}
31010Make the catchpoint conditional on @var{condition}.
31011@item -d
31012Create a disabled catchpoint.
31013@item -e @var{exception-name}
31014Only stop when @var{exception-name} is handled.
31015@item -t
31016Create a temporary catchpoint.
31017@end table
31018
31019@subsubheading @value{GDBN} Command
31020
31021The corresponding @value{GDBN} command is @samp{catch handlers}.
31022
31023@subsubheading Example
31024
31025@smallexample
31026-catch-handlers -e Constraint_Error
31027^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31028enabled="y",addr="0x0000000000402f68",
31029what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31030times="0",original-location="__gnat_begin_handler"@}
31031(gdb)
31032@end smallexample
31033
30056ea0
AB
31034@node C++ Exception GDB/MI Catchpoint Commands
31035@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31036
31037The following @sc{gdb/mi} commands can be used to create catchpoints
31038that stop the execution when C@t{++} exceptions are being throw, rethrown,
31039or caught.
31040
31041@subheading The @code{-catch-throw} Command
31042@findex -catch-throw
31043
31044@subsubheading Synopsis
31045
31046@smallexample
31047 -catch-throw [ -t ] [ -r @var{regexp}]
31048@end smallexample
31049
31050Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31051given, then only exceptions whose type matches the regular expression
31052will be caught.
31053
31054If @samp{-t} is given, then the catchpoint is enabled only for one
31055stop, the catchpoint is automatically deleted after stopping once for
31056the event.
31057
31058@subsubheading @value{GDBN} Command
31059
31060The corresponding @value{GDBN} commands are @samp{catch throw}
31061and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31062
31063@subsubheading Example
31064
31065@smallexample
31066-catch-throw -r exception_type
cb1e4e32
PA
31067^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31068 what="exception throw",catch-type="throw",
31069 thread-groups=["i1"],
30056ea0
AB
31070 regexp="exception_type",times="0"@}
31071(gdb)
31072-exec-run
31073^running
31074(gdb)
31075~"\n"
31076~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31077 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31078*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31079 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31080 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31081 thread-id="1",stopped-threads="all",core="6"
31082(gdb)
31083@end smallexample
31084
31085@subheading The @code{-catch-rethrow} Command
31086@findex -catch-rethrow
31087
31088@subsubheading Synopsis
31089
31090@smallexample
31091 -catch-rethrow [ -t ] [ -r @var{regexp}]
31092@end smallexample
31093
31094Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31095then only exceptions whose type matches the regular expression will be
31096caught.
31097
31098If @samp{-t} is given, then the catchpoint is enabled only for one
31099stop, the catchpoint is automatically deleted after the first event is
31100caught.
31101
31102@subsubheading @value{GDBN} Command
31103
31104The corresponding @value{GDBN} commands are @samp{catch rethrow}
31105and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31106
31107@subsubheading Example
31108
31109@smallexample
31110-catch-rethrow -r exception_type
cb1e4e32
PA
31111^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31112 what="exception rethrow",catch-type="rethrow",
31113 thread-groups=["i1"],
30056ea0
AB
31114 regexp="exception_type",times="0"@}
31115(gdb)
31116-exec-run
31117^running
31118(gdb)
31119~"\n"
31120~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31121 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31122*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31123 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31124 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31125 thread-id="1",stopped-threads="all",core="6"
31126(gdb)
31127@end smallexample
31128
31129@subheading The @code{-catch-catch} Command
31130@findex -catch-catch
31131
31132@subsubheading Synopsis
31133
31134@smallexample
31135 -catch-catch [ -t ] [ -r @var{regexp}]
31136@end smallexample
31137
31138Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31139is given, then only exceptions whose type matches the regular
31140expression will be caught.
31141
31142If @samp{-t} is given, then the catchpoint is enabled only for one
31143stop, the catchpoint is automatically deleted after the first event is
31144caught.
31145
31146@subsubheading @value{GDBN} Command
31147
31148The corresponding @value{GDBN} commands are @samp{catch catch}
31149and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31150
31151@subsubheading Example
31152
31153@smallexample
31154-catch-catch -r exception_type
cb1e4e32
PA
31155^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31156 what="exception catch",catch-type="catch",
31157 thread-groups=["i1"],
30056ea0
AB
31158 regexp="exception_type",times="0"@}
31159(gdb)
31160-exec-run
31161^running
31162(gdb)
31163~"\n"
31164~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31165 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31166*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31167 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31168 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31169 thread-id="1",stopped-threads="all",core="6"
31170(gdb)
31171@end smallexample
31172
922fbb7b 31173@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31174@node GDB/MI Program Context
31175@section @sc{gdb/mi} Program Context
922fbb7b 31176
a2c02241
NR
31177@subheading The @code{-exec-arguments} Command
31178@findex -exec-arguments
922fbb7b 31179
922fbb7b
AC
31180
31181@subsubheading Synopsis
31182
31183@smallexample
a2c02241 31184 -exec-arguments @var{args}
922fbb7b
AC
31185@end smallexample
31186
a2c02241
NR
31187Set the inferior program arguments, to be used in the next
31188@samp{-exec-run}.
922fbb7b 31189
a2c02241 31190@subsubheading @value{GDBN} Command
922fbb7b 31191
a2c02241 31192The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 31193
a2c02241 31194@subsubheading Example
922fbb7b 31195
fbc5282e
MK
31196@smallexample
31197(gdb)
31198-exec-arguments -v word
31199^done
31200(gdb)
31201@end smallexample
922fbb7b 31202
a2c02241 31203
9901a55b 31204@ignore
a2c02241
NR
31205@subheading The @code{-exec-show-arguments} Command
31206@findex -exec-show-arguments
31207
31208@subsubheading Synopsis
31209
31210@smallexample
31211 -exec-show-arguments
31212@end smallexample
31213
31214Print the arguments of the program.
922fbb7b
AC
31215
31216@subsubheading @value{GDBN} Command
31217
a2c02241 31218The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
31219
31220@subsubheading Example
a2c02241 31221N.A.
9901a55b 31222@end ignore
922fbb7b 31223
922fbb7b 31224
a2c02241
NR
31225@subheading The @code{-environment-cd} Command
31226@findex -environment-cd
922fbb7b 31227
a2c02241 31228@subsubheading Synopsis
922fbb7b
AC
31229
31230@smallexample
a2c02241 31231 -environment-cd @var{pathdir}
922fbb7b
AC
31232@end smallexample
31233
a2c02241 31234Set @value{GDBN}'s working directory.
922fbb7b 31235
a2c02241 31236@subsubheading @value{GDBN} Command
922fbb7b 31237
a2c02241
NR
31238The corresponding @value{GDBN} command is @samp{cd}.
31239
31240@subsubheading Example
922fbb7b
AC
31241
31242@smallexample
594fe323 31243(gdb)
a2c02241
NR
31244-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31245^done
594fe323 31246(gdb)
922fbb7b
AC
31247@end smallexample
31248
31249
a2c02241
NR
31250@subheading The @code{-environment-directory} Command
31251@findex -environment-directory
922fbb7b
AC
31252
31253@subsubheading Synopsis
31254
31255@smallexample
a2c02241 31256 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31257@end smallexample
31258
a2c02241
NR
31259Add directories @var{pathdir} to beginning of search path for source files.
31260If the @samp{-r} option is used, the search path is reset to the default
31261search path. If directories @var{pathdir} are supplied in addition to the
31262@samp{-r} option, the search path is first reset and then addition
31263occurs as normal.
31264Multiple directories may be specified, separated by blanks. Specifying
31265multiple directories in a single command
31266results in the directories added to the beginning of the
31267search path in the same order they were presented in the command.
31268If blanks are needed as
31269part of a directory name, double-quotes should be used around
31270the name. In the command output, the path will show up separated
d3e8051b 31271by the system directory-separator character. The directory-separator
a2c02241
NR
31272character must not be used
31273in any directory name.
31274If no directories are specified, the current search path is displayed.
922fbb7b
AC
31275
31276@subsubheading @value{GDBN} Command
31277
a2c02241 31278The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
31279
31280@subsubheading Example
31281
922fbb7b 31282@smallexample
594fe323 31283(gdb)
a2c02241
NR
31284-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31285^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31286(gdb)
a2c02241
NR
31287-environment-directory ""
31288^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31289(gdb)
a2c02241
NR
31290-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31291^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 31292(gdb)
a2c02241
NR
31293-environment-directory -r
31294^done,source-path="$cdir:$cwd"
594fe323 31295(gdb)
922fbb7b
AC
31296@end smallexample
31297
31298
a2c02241
NR
31299@subheading The @code{-environment-path} Command
31300@findex -environment-path
922fbb7b
AC
31301
31302@subsubheading Synopsis
31303
31304@smallexample
a2c02241 31305 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31306@end smallexample
31307
a2c02241
NR
31308Add directories @var{pathdir} to beginning of search path for object files.
31309If the @samp{-r} option is used, the search path is reset to the original
31310search path that existed at gdb start-up. If directories @var{pathdir} are
31311supplied in addition to the
31312@samp{-r} option, the search path is first reset and then addition
31313occurs as normal.
31314Multiple directories may be specified, separated by blanks. Specifying
31315multiple directories in a single command
31316results in the directories added to the beginning of the
31317search path in the same order they were presented in the command.
31318If blanks are needed as
31319part of a directory name, double-quotes should be used around
31320the name. In the command output, the path will show up separated
d3e8051b 31321by the system directory-separator character. The directory-separator
a2c02241
NR
31322character must not be used
31323in any directory name.
31324If no directories are specified, the current path is displayed.
31325
922fbb7b
AC
31326
31327@subsubheading @value{GDBN} Command
31328
a2c02241 31329The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
31330
31331@subsubheading Example
31332
922fbb7b 31333@smallexample
594fe323 31334(gdb)
a2c02241
NR
31335-environment-path
31336^done,path="/usr/bin"
594fe323 31337(gdb)
a2c02241
NR
31338-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31339^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 31340(gdb)
a2c02241
NR
31341-environment-path -r /usr/local/bin
31342^done,path="/usr/local/bin:/usr/bin"
594fe323 31343(gdb)
922fbb7b
AC
31344@end smallexample
31345
31346
a2c02241
NR
31347@subheading The @code{-environment-pwd} Command
31348@findex -environment-pwd
922fbb7b
AC
31349
31350@subsubheading Synopsis
31351
31352@smallexample
a2c02241 31353 -environment-pwd
922fbb7b
AC
31354@end smallexample
31355
a2c02241 31356Show the current working directory.
922fbb7b 31357
79a6e687 31358@subsubheading @value{GDBN} Command
922fbb7b 31359
a2c02241 31360The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
31361
31362@subsubheading Example
31363
922fbb7b 31364@smallexample
594fe323 31365(gdb)
a2c02241
NR
31366-environment-pwd
31367^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 31368(gdb)
922fbb7b
AC
31369@end smallexample
31370
a2c02241
NR
31371@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31372@node GDB/MI Thread Commands
31373@section @sc{gdb/mi} Thread Commands
31374
31375
31376@subheading The @code{-thread-info} Command
31377@findex -thread-info
922fbb7b
AC
31378
31379@subsubheading Synopsis
31380
31381@smallexample
8e8901c5 31382 -thread-info [ @var{thread-id} ]
922fbb7b
AC
31383@end smallexample
31384
5d5658a1
PA
31385Reports information about either a specific thread, if the
31386@var{thread-id} parameter is present, or about all threads.
31387@var{thread-id} is the thread's global thread ID. When printing
31388information about all threads, also reports the global ID of the
31389current thread.
8e8901c5 31390
79a6e687 31391@subsubheading @value{GDBN} Command
922fbb7b 31392
8e8901c5
VP
31393The @samp{info thread} command prints the same information
31394about all threads.
922fbb7b 31395
4694da01 31396@subsubheading Result
922fbb7b 31397
ebe553db 31398The result contains the following attributes:
4694da01
TT
31399
31400@table @samp
ebe553db
SM
31401@item threads
31402A list of threads. The format of the elements of the list is described in
31403@ref{GDB/MI Thread Information}.
31404
31405@item current-thread-id
31406The global id of the currently selected thread. This field is omitted if there
31407is no selected thread (for example, when the selected inferior is not running,
31408and therefore has no threads) or if a @var{thread-id} argument was passed to
31409the command.
4694da01
TT
31410
31411@end table
31412
31413@subsubheading Example
31414
31415@smallexample
31416-thread-info
31417^done,threads=[
31418@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31419 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31420 args=[]@},state="running"@},
31421@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31422 frame=@{level="0",addr="0x0804891f",func="foo",
31423 args=[@{name="i",value="10"@}],
6d52907e 31424 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
31425 state="running"@}],
31426current-thread-id="1"
31427(gdb)
31428@end smallexample
31429
a2c02241
NR
31430@subheading The @code{-thread-list-ids} Command
31431@findex -thread-list-ids
922fbb7b 31432
a2c02241 31433@subsubheading Synopsis
922fbb7b 31434
a2c02241
NR
31435@smallexample
31436 -thread-list-ids
31437@end smallexample
922fbb7b 31438
5d5658a1
PA
31439Produces a list of the currently known global @value{GDBN} thread ids.
31440At the end of the list it also prints the total number of such
31441threads.
922fbb7b 31442
c3b108f7
VP
31443This command is retained for historical reasons, the
31444@code{-thread-info} command should be used instead.
31445
922fbb7b
AC
31446@subsubheading @value{GDBN} Command
31447
a2c02241 31448Part of @samp{info threads} supplies the same information.
922fbb7b
AC
31449
31450@subsubheading Example
31451
922fbb7b 31452@smallexample
594fe323 31453(gdb)
a2c02241
NR
31454-thread-list-ids
31455^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 31456current-thread-id="1",number-of-threads="3"
594fe323 31457(gdb)
922fbb7b
AC
31458@end smallexample
31459
a2c02241
NR
31460
31461@subheading The @code{-thread-select} Command
31462@findex -thread-select
922fbb7b
AC
31463
31464@subsubheading Synopsis
31465
31466@smallexample
5d5658a1 31467 -thread-select @var{thread-id}
922fbb7b
AC
31468@end smallexample
31469
5d5658a1
PA
31470Make thread with global thread number @var{thread-id} the current
31471thread. It prints the number of the new current thread, and the
31472topmost frame for that thread.
922fbb7b 31473
c3b108f7
VP
31474This command is deprecated in favor of explicitly using the
31475@samp{--thread} option to each command.
31476
922fbb7b
AC
31477@subsubheading @value{GDBN} Command
31478
a2c02241 31479The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31480
31481@subsubheading Example
922fbb7b
AC
31482
31483@smallexample
594fe323 31484(gdb)
a2c02241
NR
31485-exec-next
31486^running
594fe323 31487(gdb)
a2c02241
NR
31488*stopped,reason="end-stepping-range",thread-id="2",line="187",
31489file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31490(gdb)
a2c02241
NR
31491-thread-list-ids
31492^done,
31493thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31494number-of-threads="3"
594fe323 31495(gdb)
a2c02241
NR
31496-thread-select 3
31497^done,new-thread-id="3",
31498frame=@{level="0",func="vprintf",
31499args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31500@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31501(gdb)
922fbb7b
AC
31502@end smallexample
31503
5d77fe44
JB
31504@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31505@node GDB/MI Ada Tasking Commands
31506@section @sc{gdb/mi} Ada Tasking Commands
31507
31508@subheading The @code{-ada-task-info} Command
31509@findex -ada-task-info
31510
31511@subsubheading Synopsis
31512
31513@smallexample
31514 -ada-task-info [ @var{task-id} ]
31515@end smallexample
31516
31517Reports information about either a specific Ada task, if the
31518@var{task-id} parameter is present, or about all Ada tasks.
31519
31520@subsubheading @value{GDBN} Command
31521
31522The @samp{info tasks} command prints the same information
31523about all Ada tasks (@pxref{Ada Tasks}).
31524
31525@subsubheading Result
31526
31527The result is a table of Ada tasks. The following columns are
31528defined for each Ada task:
31529
31530@table @samp
31531@item current
31532This field exists only for the current thread. It has the value @samp{*}.
31533
31534@item id
31535The identifier that @value{GDBN} uses to refer to the Ada task.
31536
31537@item task-id
31538The identifier that the target uses to refer to the Ada task.
31539
31540@item thread-id
5d5658a1
PA
31541The global thread identifier of the thread corresponding to the Ada
31542task.
5d77fe44
JB
31543
31544This field should always exist, as Ada tasks are always implemented
31545on top of a thread. But if @value{GDBN} cannot find this corresponding
31546thread for any reason, the field is omitted.
31547
31548@item parent-id
31549This field exists only when the task was created by another task.
31550In this case, it provides the ID of the parent task.
31551
31552@item priority
31553The base priority of the task.
31554
31555@item state
31556The current state of the task. For a detailed description of the
31557possible states, see @ref{Ada Tasks}.
31558
31559@item name
31560The name of the task.
31561
31562@end table
31563
31564@subsubheading Example
31565
31566@smallexample
31567-ada-task-info
31568^done,tasks=@{nr_rows="3",nr_cols="8",
31569hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31570@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31571@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31572@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31573@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31574@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31575@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31576@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31577body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31578state="Child Termination Wait",name="main_task"@}]@}
31579(gdb)
31580@end smallexample
31581
a2c02241
NR
31582@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31583@node GDB/MI Program Execution
31584@section @sc{gdb/mi} Program Execution
922fbb7b 31585
ef21caaf 31586These are the asynchronous commands which generate the out-of-band
3f94c067 31587record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31588asynchronously with remote targets and this interaction is mimicked in
31589other cases.
922fbb7b 31590
922fbb7b
AC
31591@subheading The @code{-exec-continue} Command
31592@findex -exec-continue
31593
31594@subsubheading Synopsis
31595
31596@smallexample
540aa8e7 31597 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31598@end smallexample
31599
540aa8e7
MS
31600Resumes the execution of the inferior program, which will continue
31601to execute until it reaches a debugger stop event. If the
31602@samp{--reverse} option is specified, execution resumes in reverse until
31603it reaches a stop event. Stop events may include
31604@itemize @bullet
31605@item
31606breakpoints or watchpoints
31607@item
31608signals or exceptions
31609@item
31610the end of the process (or its beginning under @samp{--reverse})
31611@item
31612the end or beginning of a replay log if one is being used.
31613@end itemize
31614In all-stop mode (@pxref{All-Stop
31615Mode}), may resume only one thread, or all threads, depending on the
31616value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31617specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31618ignored in all-stop mode. If the @samp{--thread-group} options is
31619specified, then all threads in that thread group are resumed.
922fbb7b
AC
31620
31621@subsubheading @value{GDBN} Command
31622
31623The corresponding @value{GDBN} corresponding is @samp{continue}.
31624
31625@subsubheading Example
31626
31627@smallexample
31628-exec-continue
31629^running
594fe323 31630(gdb)
922fbb7b 31631@@Hello world
a47ec5fe
AR
31632*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31633func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31634line="13",arch="i386:x86_64"@}
594fe323 31635(gdb)
922fbb7b
AC
31636@end smallexample
31637
31638
31639@subheading The @code{-exec-finish} Command
31640@findex -exec-finish
31641
31642@subsubheading Synopsis
31643
31644@smallexample
540aa8e7 31645 -exec-finish [--reverse]
922fbb7b
AC
31646@end smallexample
31647
ef21caaf
NR
31648Resumes the execution of the inferior program until the current
31649function is exited. Displays the results returned by the function.
540aa8e7
MS
31650If the @samp{--reverse} option is specified, resumes the reverse
31651execution of the inferior program until the point where current
31652function was called.
922fbb7b
AC
31653
31654@subsubheading @value{GDBN} Command
31655
31656The corresponding @value{GDBN} command is @samp{finish}.
31657
31658@subsubheading Example
31659
31660Function returning @code{void}.
31661
31662@smallexample
31663-exec-finish
31664^running
594fe323 31665(gdb)
922fbb7b
AC
31666@@hello from foo
31667*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31668file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31669(gdb)
922fbb7b
AC
31670@end smallexample
31671
31672Function returning other than @code{void}. The name of the internal
31673@value{GDBN} variable storing the result is printed, together with the
31674value itself.
31675
31676@smallexample
31677-exec-finish
31678^running
594fe323 31679(gdb)
922fbb7b
AC
31680*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31681args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31682file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31683arch="i386:x86_64"@},
922fbb7b 31684gdb-result-var="$1",return-value="0"
594fe323 31685(gdb)
922fbb7b
AC
31686@end smallexample
31687
31688
31689@subheading The @code{-exec-interrupt} Command
31690@findex -exec-interrupt
31691
31692@subsubheading Synopsis
31693
31694@smallexample
c3b108f7 31695 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31696@end smallexample
31697
ef21caaf
NR
31698Interrupts the background execution of the target. Note how the token
31699associated with the stop message is the one for the execution command
31700that has been interrupted. The token for the interrupt itself only
31701appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31702interrupt a non-running program, an error message will be printed.
31703
c3b108f7
VP
31704Note that when asynchronous execution is enabled, this command is
31705asynchronous just like other execution commands. That is, first the
31706@samp{^done} response will be printed, and the target stop will be
31707reported after that using the @samp{*stopped} notification.
31708
31709In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31710All threads (in all inferiors) will be interrupted if the
31711@samp{--all} option is specified. If the @samp{--thread-group}
31712option is specified, all threads in that group will be interrupted.
c3b108f7 31713
922fbb7b
AC
31714@subsubheading @value{GDBN} Command
31715
31716The corresponding @value{GDBN} command is @samp{interrupt}.
31717
31718@subsubheading Example
31719
31720@smallexample
594fe323 31721(gdb)
922fbb7b
AC
31722111-exec-continue
31723111^running
31724
594fe323 31725(gdb)
922fbb7b
AC
31726222-exec-interrupt
31727222^done
594fe323 31728(gdb)
922fbb7b 31729111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31730frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31731fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31732(gdb)
922fbb7b 31733
594fe323 31734(gdb)
922fbb7b
AC
31735-exec-interrupt
31736^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31737(gdb)
922fbb7b
AC
31738@end smallexample
31739
83eba9b7
VP
31740@subheading The @code{-exec-jump} Command
31741@findex -exec-jump
31742
31743@subsubheading Synopsis
31744
31745@smallexample
31746 -exec-jump @var{location}
31747@end smallexample
31748
31749Resumes execution of the inferior program at the location specified by
31750parameter. @xref{Specify Location}, for a description of the
31751different forms of @var{location}.
31752
31753@subsubheading @value{GDBN} Command
31754
31755The corresponding @value{GDBN} command is @samp{jump}.
31756
31757@subsubheading Example
31758
31759@smallexample
31760-exec-jump foo.c:10
31761*running,thread-id="all"
31762^running
31763@end smallexample
31764
922fbb7b
AC
31765
31766@subheading The @code{-exec-next} Command
31767@findex -exec-next
31768
31769@subsubheading Synopsis
31770
31771@smallexample
540aa8e7 31772 -exec-next [--reverse]
922fbb7b
AC
31773@end smallexample
31774
ef21caaf
NR
31775Resumes execution of the inferior program, stopping when the beginning
31776of the next source line is reached.
922fbb7b 31777
540aa8e7
MS
31778If the @samp{--reverse} option is specified, resumes reverse execution
31779of the inferior program, stopping at the beginning of the previous
31780source line. If you issue this command on the first line of a
31781function, it will take you back to the caller of that function, to the
31782source line where the function was called.
31783
31784
922fbb7b
AC
31785@subsubheading @value{GDBN} Command
31786
31787The corresponding @value{GDBN} command is @samp{next}.
31788
31789@subsubheading Example
31790
31791@smallexample
31792-exec-next
31793^running
594fe323 31794(gdb)
922fbb7b 31795*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31796(gdb)
922fbb7b
AC
31797@end smallexample
31798
31799
31800@subheading The @code{-exec-next-instruction} Command
31801@findex -exec-next-instruction
31802
31803@subsubheading Synopsis
31804
31805@smallexample
540aa8e7 31806 -exec-next-instruction [--reverse]
922fbb7b
AC
31807@end smallexample
31808
ef21caaf
NR
31809Executes one machine instruction. If the instruction is a function
31810call, continues until the function returns. If the program stops at an
31811instruction in the middle of a source line, the address will be
31812printed as well.
922fbb7b 31813
540aa8e7
MS
31814If the @samp{--reverse} option is specified, resumes reverse execution
31815of the inferior program, stopping at the previous instruction. If the
31816previously executed instruction was a return from another function,
31817it will continue to execute in reverse until the call to that function
31818(from the current stack frame) is reached.
31819
922fbb7b
AC
31820@subsubheading @value{GDBN} Command
31821
31822The corresponding @value{GDBN} command is @samp{nexti}.
31823
31824@subsubheading Example
31825
31826@smallexample
594fe323 31827(gdb)
922fbb7b
AC
31828-exec-next-instruction
31829^running
31830
594fe323 31831(gdb)
922fbb7b
AC
31832*stopped,reason="end-stepping-range",
31833addr="0x000100d4",line="5",file="hello.c"
594fe323 31834(gdb)
922fbb7b
AC
31835@end smallexample
31836
31837
31838@subheading The @code{-exec-return} Command
31839@findex -exec-return
31840
31841@subsubheading Synopsis
31842
31843@smallexample
31844 -exec-return
31845@end smallexample
31846
31847Makes current function return immediately. Doesn't execute the inferior.
31848Displays the new current frame.
31849
31850@subsubheading @value{GDBN} Command
31851
31852The corresponding @value{GDBN} command is @samp{return}.
31853
31854@subsubheading Example
31855
31856@smallexample
594fe323 31857(gdb)
922fbb7b
AC
31858200-break-insert callee4
31859200^done,bkpt=@{number="1",addr="0x00010734",
31860file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31861(gdb)
922fbb7b
AC
31862000-exec-run
31863000^running
594fe323 31864(gdb)
a47ec5fe 31865000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31866frame=@{func="callee4",args=[],
76ff342d 31867file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31868fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31869arch="i386:x86_64"@}
594fe323 31870(gdb)
922fbb7b
AC
31871205-break-delete
31872205^done
594fe323 31873(gdb)
922fbb7b
AC
31874111-exec-return
31875111^done,frame=@{level="0",func="callee3",
31876args=[@{name="strarg",
31877value="0x11940 \"A string argument.\""@}],
76ff342d 31878file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31879fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31880arch="i386:x86_64"@}
594fe323 31881(gdb)
922fbb7b
AC
31882@end smallexample
31883
31884
31885@subheading The @code{-exec-run} Command
31886@findex -exec-run
31887
31888@subsubheading Synopsis
31889
31890@smallexample
5713b9b5 31891 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31892@end smallexample
31893
ef21caaf
NR
31894Starts execution of the inferior from the beginning. The inferior
31895executes until either a breakpoint is encountered or the program
31896exits. In the latter case the output will include an exit code, if
31897the program has exited exceptionally.
922fbb7b 31898
5713b9b5
JB
31899When neither the @samp{--all} nor the @samp{--thread-group} option
31900is specified, the current inferior is started. If the
a79b8f6e
VP
31901@samp{--thread-group} option is specified, it should refer to a thread
31902group of type @samp{process}, and that thread group will be started.
31903If the @samp{--all} option is specified, then all inferiors will be started.
31904
5713b9b5
JB
31905Using the @samp{--start} option instructs the debugger to stop
31906the execution at the start of the inferior's main subprogram,
31907following the same behavior as the @code{start} command
31908(@pxref{Starting}).
31909
922fbb7b
AC
31910@subsubheading @value{GDBN} Command
31911
31912The corresponding @value{GDBN} command is @samp{run}.
31913
ef21caaf 31914@subsubheading Examples
922fbb7b
AC
31915
31916@smallexample
594fe323 31917(gdb)
922fbb7b
AC
31918-break-insert main
31919^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31920(gdb)
922fbb7b
AC
31921-exec-run
31922^running
594fe323 31923(gdb)
a47ec5fe 31924*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31925frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31926fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31927(gdb)
922fbb7b
AC
31928@end smallexample
31929
ef21caaf
NR
31930@noindent
31931Program exited normally:
31932
31933@smallexample
594fe323 31934(gdb)
ef21caaf
NR
31935-exec-run
31936^running
594fe323 31937(gdb)
ef21caaf
NR
31938x = 55
31939*stopped,reason="exited-normally"
594fe323 31940(gdb)
ef21caaf
NR
31941@end smallexample
31942
31943@noindent
31944Program exited exceptionally:
31945
31946@smallexample
594fe323 31947(gdb)
ef21caaf
NR
31948-exec-run
31949^running
594fe323 31950(gdb)
ef21caaf
NR
31951x = 55
31952*stopped,reason="exited",exit-code="01"
594fe323 31953(gdb)
ef21caaf
NR
31954@end smallexample
31955
31956Another way the program can terminate is if it receives a signal such as
31957@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31958
31959@smallexample
594fe323 31960(gdb)
ef21caaf
NR
31961*stopped,reason="exited-signalled",signal-name="SIGINT",
31962signal-meaning="Interrupt"
31963@end smallexample
31964
922fbb7b 31965
a2c02241
NR
31966@c @subheading -exec-signal
31967
31968
31969@subheading The @code{-exec-step} Command
31970@findex -exec-step
922fbb7b
AC
31971
31972@subsubheading Synopsis
31973
31974@smallexample
540aa8e7 31975 -exec-step [--reverse]
922fbb7b
AC
31976@end smallexample
31977
a2c02241
NR
31978Resumes execution of the inferior program, stopping when the beginning
31979of the next source line is reached, if the next source line is not a
31980function call. If it is, stop at the first instruction of the called
540aa8e7
MS
31981function. If the @samp{--reverse} option is specified, resumes reverse
31982execution of the inferior program, stopping at the beginning of the
31983previously executed source line.
922fbb7b
AC
31984
31985@subsubheading @value{GDBN} Command
31986
a2c02241 31987The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
31988
31989@subsubheading Example
31990
31991Stepping into a function:
31992
31993@smallexample
31994-exec-step
31995^running
594fe323 31996(gdb)
922fbb7b
AC
31997*stopped,reason="end-stepping-range",
31998frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 31999@{name="b",value="0"@}],file="recursive2.c",
6d52907e 32000fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 32001(gdb)
922fbb7b
AC
32002@end smallexample
32003
32004Regular stepping:
32005
32006@smallexample
32007-exec-step
32008^running
594fe323 32009(gdb)
922fbb7b 32010*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 32011(gdb)
922fbb7b
AC
32012@end smallexample
32013
32014
32015@subheading The @code{-exec-step-instruction} Command
32016@findex -exec-step-instruction
32017
32018@subsubheading Synopsis
32019
32020@smallexample
540aa8e7 32021 -exec-step-instruction [--reverse]
922fbb7b
AC
32022@end smallexample
32023
540aa8e7
MS
32024Resumes the inferior which executes one machine instruction. If the
32025@samp{--reverse} option is specified, resumes reverse execution of the
32026inferior program, stopping at the previously executed instruction.
32027The output, once @value{GDBN} has stopped, will vary depending on
32028whether we have stopped in the middle of a source line or not. In the
32029former case, the address at which the program stopped will be printed
32030as well.
922fbb7b
AC
32031
32032@subsubheading @value{GDBN} Command
32033
32034The corresponding @value{GDBN} command is @samp{stepi}.
32035
32036@subsubheading Example
32037
32038@smallexample
594fe323 32039(gdb)
922fbb7b
AC
32040-exec-step-instruction
32041^running
32042
594fe323 32043(gdb)
922fbb7b 32044*stopped,reason="end-stepping-range",
76ff342d 32045frame=@{func="foo",args=[],file="try.c",
6d52907e 32046fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 32047(gdb)
922fbb7b
AC
32048-exec-step-instruction
32049^running
32050
594fe323 32051(gdb)
922fbb7b 32052*stopped,reason="end-stepping-range",
76ff342d 32053frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 32054fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 32055(gdb)
922fbb7b
AC
32056@end smallexample
32057
32058
32059@subheading The @code{-exec-until} Command
32060@findex -exec-until
32061
32062@subsubheading Synopsis
32063
32064@smallexample
32065 -exec-until [ @var{location} ]
32066@end smallexample
32067
ef21caaf
NR
32068Executes the inferior until the @var{location} specified in the
32069argument is reached. If there is no argument, the inferior executes
32070until a source line greater than the current one is reached. The
32071reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
32072
32073@subsubheading @value{GDBN} Command
32074
32075The corresponding @value{GDBN} command is @samp{until}.
32076
32077@subsubheading Example
32078
32079@smallexample
594fe323 32080(gdb)
922fbb7b
AC
32081-exec-until recursive2.c:6
32082^running
594fe323 32083(gdb)
922fbb7b
AC
32084x = 55
32085*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
32086file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32087arch="i386:x86_64"@}
594fe323 32088(gdb)
922fbb7b
AC
32089@end smallexample
32090
32091@ignore
32092@subheading -file-clear
32093Is this going away????
32094@end ignore
32095
351ff01a 32096@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32097@node GDB/MI Stack Manipulation
32098@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 32099
1e611234
PM
32100@subheading The @code{-enable-frame-filters} Command
32101@findex -enable-frame-filters
32102
32103@smallexample
32104-enable-frame-filters
32105@end smallexample
32106
32107@value{GDBN} allows Python-based frame filters to affect the output of
32108the MI commands relating to stack traces. As there is no way to
32109implement this in a fully backward-compatible way, a front end must
32110request that this functionality be enabled.
32111
32112Once enabled, this feature cannot be disabled.
32113
32114Note that if Python support has not been compiled into @value{GDBN},
32115this command will still succeed (and do nothing).
922fbb7b 32116
a2c02241
NR
32117@subheading The @code{-stack-info-frame} Command
32118@findex -stack-info-frame
922fbb7b
AC
32119
32120@subsubheading Synopsis
32121
32122@smallexample
a2c02241 32123 -stack-info-frame
922fbb7b
AC
32124@end smallexample
32125
a2c02241 32126Get info on the selected frame.
922fbb7b
AC
32127
32128@subsubheading @value{GDBN} Command
32129
a2c02241
NR
32130The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32131(without arguments).
922fbb7b
AC
32132
32133@subsubheading Example
32134
32135@smallexample
594fe323 32136(gdb)
a2c02241
NR
32137-stack-info-frame
32138^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32139file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32140fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32141arch="i386:x86_64"@}
594fe323 32142(gdb)
922fbb7b
AC
32143@end smallexample
32144
a2c02241
NR
32145@subheading The @code{-stack-info-depth} Command
32146@findex -stack-info-depth
922fbb7b
AC
32147
32148@subsubheading Synopsis
32149
32150@smallexample
a2c02241 32151 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
32152@end smallexample
32153
a2c02241
NR
32154Return the depth of the stack. If the integer argument @var{max-depth}
32155is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
32156
32157@subsubheading @value{GDBN} Command
32158
a2c02241 32159There's no equivalent @value{GDBN} command.
922fbb7b
AC
32160
32161@subsubheading Example
32162
a2c02241
NR
32163For a stack with frame levels 0 through 11:
32164
922fbb7b 32165@smallexample
594fe323 32166(gdb)
a2c02241
NR
32167-stack-info-depth
32168^done,depth="12"
594fe323 32169(gdb)
a2c02241
NR
32170-stack-info-depth 4
32171^done,depth="4"
594fe323 32172(gdb)
a2c02241
NR
32173-stack-info-depth 12
32174^done,depth="12"
594fe323 32175(gdb)
a2c02241
NR
32176-stack-info-depth 11
32177^done,depth="11"
594fe323 32178(gdb)
a2c02241
NR
32179-stack-info-depth 13
32180^done,depth="12"
594fe323 32181(gdb)
922fbb7b
AC
32182@end smallexample
32183
1e611234 32184@anchor{-stack-list-arguments}
a2c02241
NR
32185@subheading The @code{-stack-list-arguments} Command
32186@findex -stack-list-arguments
922fbb7b
AC
32187
32188@subsubheading Synopsis
32189
32190@smallexample
6211c335 32191 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 32192 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
32193@end smallexample
32194
a2c02241
NR
32195Display a list of the arguments for the frames between @var{low-frame}
32196and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
32197@var{high-frame} are not provided, list the arguments for the whole
32198call stack. If the two arguments are equal, show the single frame
32199at the corresponding level. It is an error if @var{low-frame} is
32200larger than the actual number of frames. On the other hand,
32201@var{high-frame} may be larger than the actual number of frames, in
32202which case only existing frames will be returned.
a2c02241 32203
3afae151
VP
32204If @var{print-values} is 0 or @code{--no-values}, print only the names of
32205the variables; if it is 1 or @code{--all-values}, print also their
32206values; and if it is 2 or @code{--simple-values}, print the name,
32207type and value for simple data types, and the name and type for arrays,
1e611234
PM
32208structures and unions. If the option @code{--no-frame-filters} is
32209supplied, then Python frame filters will not be executed.
32210
6211c335
YQ
32211If the @code{--skip-unavailable} option is specified, arguments that
32212are not available are not listed. Partially available arguments
32213are still displayed, however.
922fbb7b 32214
b3372f91
VP
32215Use of this command to obtain arguments in a single frame is
32216deprecated in favor of the @samp{-stack-list-variables} command.
32217
922fbb7b
AC
32218@subsubheading @value{GDBN} Command
32219
a2c02241
NR
32220@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32221@samp{gdb_get_args} command which partially overlaps with the
32222functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
32223
32224@subsubheading Example
922fbb7b 32225
a2c02241 32226@smallexample
594fe323 32227(gdb)
a2c02241
NR
32228-stack-list-frames
32229^done,
32230stack=[
32231frame=@{level="0",addr="0x00010734",func="callee4",
32232file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32233fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32234arch="i386:x86_64"@},
a2c02241
NR
32235frame=@{level="1",addr="0x0001076c",func="callee3",
32236file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32237fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32238arch="i386:x86_64"@},
a2c02241
NR
32239frame=@{level="2",addr="0x0001078c",func="callee2",
32240file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32241fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32242arch="i386:x86_64"@},
a2c02241
NR
32243frame=@{level="3",addr="0x000107b4",func="callee1",
32244file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32245fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32246arch="i386:x86_64"@},
a2c02241
NR
32247frame=@{level="4",addr="0x000107e0",func="main",
32248file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
32249fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32250arch="i386:x86_64"@}]
594fe323 32251(gdb)
a2c02241
NR
32252-stack-list-arguments 0
32253^done,
32254stack-args=[
32255frame=@{level="0",args=[]@},
32256frame=@{level="1",args=[name="strarg"]@},
32257frame=@{level="2",args=[name="intarg",name="strarg"]@},
32258frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32259frame=@{level="4",args=[]@}]
594fe323 32260(gdb)
a2c02241
NR
32261-stack-list-arguments 1
32262^done,
32263stack-args=[
32264frame=@{level="0",args=[]@},
32265frame=@{level="1",
32266 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32267frame=@{level="2",args=[
32268@{name="intarg",value="2"@},
32269@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32270@{frame=@{level="3",args=[
32271@{name="intarg",value="2"@},
32272@{name="strarg",value="0x11940 \"A string argument.\""@},
32273@{name="fltarg",value="3.5"@}]@},
32274frame=@{level="4",args=[]@}]
594fe323 32275(gdb)
a2c02241
NR
32276-stack-list-arguments 0 2 2
32277^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 32278(gdb)
a2c02241
NR
32279-stack-list-arguments 1 2 2
32280^done,stack-args=[frame=@{level="2",
32281args=[@{name="intarg",value="2"@},
32282@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 32283(gdb)
a2c02241
NR
32284@end smallexample
32285
32286@c @subheading -stack-list-exception-handlers
922fbb7b 32287
a2c02241 32288
1e611234 32289@anchor{-stack-list-frames}
a2c02241
NR
32290@subheading The @code{-stack-list-frames} Command
32291@findex -stack-list-frames
1abaf70c
BR
32292
32293@subsubheading Synopsis
32294
32295@smallexample
1e611234 32296 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
32297@end smallexample
32298
a2c02241
NR
32299List the frames currently on the stack. For each frame it displays the
32300following info:
32301
32302@table @samp
32303@item @var{level}
d3e8051b 32304The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
32305@item @var{addr}
32306The @code{$pc} value for that frame.
32307@item @var{func}
32308Function name.
32309@item @var{file}
32310File name of the source file where the function lives.
7d288aaa
TT
32311@item @var{fullname}
32312The full file name of the source file where the function lives.
a2c02241
NR
32313@item @var{line}
32314Line number corresponding to the @code{$pc}.
7d288aaa
TT
32315@item @var{from}
32316The shared library where this function is defined. This is only given
32317if the frame's function is not known.
6d52907e
JV
32318@item @var{arch}
32319Frame's architecture.
a2c02241
NR
32320@end table
32321
32322If invoked without arguments, this command prints a backtrace for the
32323whole stack. If given two integer arguments, it shows the frames whose
32324levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
32325are equal, it shows the single frame at the corresponding level. It is
32326an error if @var{low-frame} is larger than the actual number of
a5451f4e 32327frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
32328actual number of frames, in which case only existing frames will be
32329returned. If the option @code{--no-frame-filters} is supplied, then
32330Python frame filters will not be executed.
1abaf70c
BR
32331
32332@subsubheading @value{GDBN} Command
32333
a2c02241 32334The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
32335
32336@subsubheading Example
32337
a2c02241
NR
32338Full stack backtrace:
32339
1abaf70c 32340@smallexample
594fe323 32341(gdb)
a2c02241
NR
32342-stack-list-frames
32343^done,stack=
32344[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
32345 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32346 arch="i386:x86_64"@},
a2c02241 32347frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
32348 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32349 arch="i386:x86_64"@},
a2c02241 32350frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
32351 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32352 arch="i386:x86_64"@},
a2c02241 32353frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32354 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32355 arch="i386:x86_64"@},
a2c02241 32356frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32357 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32358 arch="i386:x86_64"@},
a2c02241 32359frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32360 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32361 arch="i386:x86_64"@},
a2c02241 32362frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
32363 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32364 arch="i386:x86_64"@},
a2c02241 32365frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
32366 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32367 arch="i386:x86_64"@},
a2c02241 32368frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
32369 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32370 arch="i386:x86_64"@},
a2c02241 32371frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
32372 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32373 arch="i386:x86_64"@},
a2c02241 32374frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
32375 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32376 arch="i386:x86_64"@},
a2c02241 32377frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
32378 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32379 arch="i386:x86_64"@}]
594fe323 32380(gdb)
1abaf70c
BR
32381@end smallexample
32382
a2c02241 32383Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 32384
a2c02241 32385@smallexample
594fe323 32386(gdb)
a2c02241
NR
32387-stack-list-frames 3 5
32388^done,stack=
32389[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32390 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32391 arch="i386:x86_64"@},
a2c02241 32392frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32393 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32394 arch="i386:x86_64"@},
a2c02241 32395frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32396 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32397 arch="i386:x86_64"@}]
594fe323 32398(gdb)
a2c02241 32399@end smallexample
922fbb7b 32400
a2c02241 32401Show a single frame:
922fbb7b
AC
32402
32403@smallexample
594fe323 32404(gdb)
a2c02241
NR
32405-stack-list-frames 3 3
32406^done,stack=
32407[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32408 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32409 arch="i386:x86_64"@}]
594fe323 32410(gdb)
922fbb7b
AC
32411@end smallexample
32412
922fbb7b 32413
a2c02241
NR
32414@subheading The @code{-stack-list-locals} Command
32415@findex -stack-list-locals
1e611234 32416@anchor{-stack-list-locals}
57c22c6c 32417
a2c02241 32418@subsubheading Synopsis
922fbb7b
AC
32419
32420@smallexample
6211c335 32421 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
32422@end smallexample
32423
a2c02241
NR
32424Display the local variable names for the selected frame. If
32425@var{print-values} is 0 or @code{--no-values}, print only the names of
32426the variables; if it is 1 or @code{--all-values}, print also their
32427values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32428type and value for simple data types, and the name and type for arrays,
a2c02241
NR
32429structures and unions. In this last case, a frontend can immediately
32430display the value of simple data types and create variable objects for
d3e8051b 32431other data types when the user wishes to explore their values in
1e611234
PM
32432more detail. If the option @code{--no-frame-filters} is supplied, then
32433Python frame filters will not be executed.
922fbb7b 32434
6211c335
YQ
32435If the @code{--skip-unavailable} option is specified, local variables
32436that are not available are not listed. Partially available local
32437variables are still displayed, however.
32438
b3372f91
VP
32439This command is deprecated in favor of the
32440@samp{-stack-list-variables} command.
32441
922fbb7b
AC
32442@subsubheading @value{GDBN} Command
32443
a2c02241 32444@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
32445
32446@subsubheading Example
922fbb7b
AC
32447
32448@smallexample
594fe323 32449(gdb)
a2c02241
NR
32450-stack-list-locals 0
32451^done,locals=[name="A",name="B",name="C"]
594fe323 32452(gdb)
a2c02241
NR
32453-stack-list-locals --all-values
32454^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32455 @{name="C",value="@{1, 2, 3@}"@}]
32456-stack-list-locals --simple-values
32457^done,locals=[@{name="A",type="int",value="1"@},
32458 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 32459(gdb)
922fbb7b
AC
32460@end smallexample
32461
1e611234 32462@anchor{-stack-list-variables}
b3372f91
VP
32463@subheading The @code{-stack-list-variables} Command
32464@findex -stack-list-variables
32465
32466@subsubheading Synopsis
32467
32468@smallexample
6211c335 32469 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
32470@end smallexample
32471
32472Display the names of local variables and function arguments for the selected frame. If
32473@var{print-values} is 0 or @code{--no-values}, print only the names of
32474the variables; if it is 1 or @code{--all-values}, print also their
32475values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32476type and value for simple data types, and the name and type for arrays,
1e611234
PM
32477structures and unions. If the option @code{--no-frame-filters} is
32478supplied, then Python frame filters will not be executed.
b3372f91 32479
6211c335
YQ
32480If the @code{--skip-unavailable} option is specified, local variables
32481and arguments that are not available are not listed. Partially
32482available arguments and local variables are still displayed, however.
32483
b3372f91
VP
32484@subsubheading Example
32485
32486@smallexample
32487(gdb)
32488-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32489^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32490(gdb)
32491@end smallexample
32492
922fbb7b 32493
a2c02241
NR
32494@subheading The @code{-stack-select-frame} Command
32495@findex -stack-select-frame
922fbb7b
AC
32496
32497@subsubheading Synopsis
32498
32499@smallexample
a2c02241 32500 -stack-select-frame @var{framenum}
922fbb7b
AC
32501@end smallexample
32502
a2c02241
NR
32503Change the selected frame. Select a different frame @var{framenum} on
32504the stack.
922fbb7b 32505
c3b108f7
VP
32506This command in deprecated in favor of passing the @samp{--frame}
32507option to every command.
32508
922fbb7b
AC
32509@subsubheading @value{GDBN} Command
32510
a2c02241
NR
32511The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32512@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32513
32514@subsubheading Example
32515
32516@smallexample
594fe323 32517(gdb)
a2c02241 32518-stack-select-frame 2
922fbb7b 32519^done
594fe323 32520(gdb)
922fbb7b
AC
32521@end smallexample
32522
32523@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32524@node GDB/MI Variable Objects
32525@section @sc{gdb/mi} Variable Objects
922fbb7b 32526
a1b5960f 32527@ignore
922fbb7b 32528
a2c02241 32529@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32530
a2c02241
NR
32531For the implementation of a variable debugger window (locals, watched
32532expressions, etc.), we are proposing the adaptation of the existing code
32533used by @code{Insight}.
922fbb7b 32534
a2c02241 32535The two main reasons for that are:
922fbb7b 32536
a2c02241
NR
32537@enumerate 1
32538@item
32539It has been proven in practice (it is already on its second generation).
922fbb7b 32540
a2c02241
NR
32541@item
32542It will shorten development time (needless to say how important it is
32543now).
32544@end enumerate
922fbb7b 32545
a2c02241
NR
32546The original interface was designed to be used by Tcl code, so it was
32547slightly changed so it could be used through @sc{gdb/mi}. This section
32548describes the @sc{gdb/mi} operations that will be available and gives some
32549hints about their use.
922fbb7b 32550
a2c02241
NR
32551@emph{Note}: In addition to the set of operations described here, we
32552expect the @sc{gui} implementation of a variable window to require, at
32553least, the following operations:
922fbb7b 32554
a2c02241
NR
32555@itemize @bullet
32556@item @code{-gdb-show} @code{output-radix}
32557@item @code{-stack-list-arguments}
32558@item @code{-stack-list-locals}
32559@item @code{-stack-select-frame}
32560@end itemize
922fbb7b 32561
a1b5960f
VP
32562@end ignore
32563
c8b2f53c 32564@subheading Introduction to Variable Objects
922fbb7b 32565
a2c02241 32566@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32567
32568Variable objects are "object-oriented" MI interface for examining and
32569changing values of expressions. Unlike some other MI interfaces that
32570work with expressions, variable objects are specifically designed for
32571simple and efficient presentation in the frontend. A variable object
32572is identified by string name. When a variable object is created, the
32573frontend specifies the expression for that variable object. The
32574expression can be a simple variable, or it can be an arbitrary complex
32575expression, and can even involve CPU registers. After creating a
32576variable object, the frontend can invoke other variable object
32577operations---for example to obtain or change the value of a variable
32578object, or to change display format.
32579
32580Variable objects have hierarchical tree structure. Any variable object
32581that corresponds to a composite type, such as structure in C, has
32582a number of child variable objects, for example corresponding to each
32583element of a structure. A child variable object can itself have
32584children, recursively. Recursion ends when we reach
25d5ea92
VP
32585leaf variable objects, which always have built-in types. Child variable
32586objects are created only by explicit request, so if a frontend
32587is not interested in the children of a particular variable object, no
32588child will be created.
c8b2f53c
VP
32589
32590For a leaf variable object it is possible to obtain its value as a
32591string, or set the value from a string. String value can be also
32592obtained for a non-leaf variable object, but it's generally a string
32593that only indicates the type of the object, and does not list its
32594contents. Assignment to a non-leaf variable object is not allowed.
32595
32596A frontend does not need to read the values of all variable objects each time
32597the program stops. Instead, MI provides an update command that lists all
32598variable objects whose values has changed since the last update
32599operation. This considerably reduces the amount of data that must
25d5ea92
VP
32600be transferred to the frontend. As noted above, children variable
32601objects are created on demand, and only leaf variable objects have a
32602real value. As result, gdb will read target memory only for leaf
32603variables that frontend has created.
32604
32605The automatic update is not always desirable. For example, a frontend
32606might want to keep a value of some expression for future reference,
32607and never update it. For another example, fetching memory is
32608relatively slow for embedded targets, so a frontend might want
32609to disable automatic update for the variables that are either not
32610visible on the screen, or ``closed''. This is possible using so
32611called ``frozen variable objects''. Such variable objects are never
32612implicitly updated.
922fbb7b 32613
c3b108f7
VP
32614Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32615fixed variable object, the expression is parsed when the variable
32616object is created, including associating identifiers to specific
32617variables. The meaning of expression never changes. For a floating
32618variable object the values of variables whose names appear in the
32619expressions are re-evaluated every time in the context of the current
32620frame. Consider this example:
32621
32622@smallexample
32623void do_work(...)
32624@{
32625 struct work_state state;
32626
32627 if (...)
32628 do_work(...);
32629@}
32630@end smallexample
32631
32632If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32633this function, and we enter the recursive call, the variable
c3b108f7
VP
32634object will report the value of @code{state} in the top-level
32635@code{do_work} invocation. On the other hand, a floating variable
32636object will report the value of @code{state} in the current frame.
32637
32638If an expression specified when creating a fixed variable object
32639refers to a local variable, the variable object becomes bound to the
32640thread and frame in which the variable object is created. When such
32641variable object is updated, @value{GDBN} makes sure that the
32642thread/frame combination the variable object is bound to still exists,
32643and re-evaluates the variable object in context of that thread/frame.
32644
a2c02241
NR
32645The following is the complete set of @sc{gdb/mi} operations defined to
32646access this functionality:
922fbb7b 32647
a2c02241
NR
32648@multitable @columnfractions .4 .6
32649@item @strong{Operation}
32650@tab @strong{Description}
922fbb7b 32651
0cc7d26f
TT
32652@item @code{-enable-pretty-printing}
32653@tab enable Python-based pretty-printing
a2c02241
NR
32654@item @code{-var-create}
32655@tab create a variable object
32656@item @code{-var-delete}
22d8a470 32657@tab delete the variable object and/or its children
a2c02241
NR
32658@item @code{-var-set-format}
32659@tab set the display format of this variable
32660@item @code{-var-show-format}
32661@tab show the display format of this variable
32662@item @code{-var-info-num-children}
32663@tab tells how many children this object has
32664@item @code{-var-list-children}
32665@tab return a list of the object's children
32666@item @code{-var-info-type}
32667@tab show the type of this variable object
32668@item @code{-var-info-expression}
02142340
VP
32669@tab print parent-relative expression that this variable object represents
32670@item @code{-var-info-path-expression}
32671@tab print full expression that this variable object represents
a2c02241
NR
32672@item @code{-var-show-attributes}
32673@tab is this variable editable? does it exist here?
32674@item @code{-var-evaluate-expression}
32675@tab get the value of this variable
32676@item @code{-var-assign}
32677@tab set the value of this variable
32678@item @code{-var-update}
32679@tab update the variable and its children
25d5ea92 32680@item @code{-var-set-frozen}
6b92c0d3 32681@tab set frozenness attribute
0cc7d26f
TT
32682@item @code{-var-set-update-range}
32683@tab set range of children to display on update
a2c02241 32684@end multitable
922fbb7b 32685
a2c02241
NR
32686In the next subsection we describe each operation in detail and suggest
32687how it can be used.
922fbb7b 32688
a2c02241 32689@subheading Description And Use of Operations on Variable Objects
922fbb7b 32690
0cc7d26f
TT
32691@subheading The @code{-enable-pretty-printing} Command
32692@findex -enable-pretty-printing
32693
32694@smallexample
32695-enable-pretty-printing
32696@end smallexample
32697
32698@value{GDBN} allows Python-based visualizers to affect the output of the
32699MI variable object commands. However, because there was no way to
32700implement this in a fully backward-compatible way, a front end must
32701request that this functionality be enabled.
32702
32703Once enabled, this feature cannot be disabled.
32704
32705Note that if Python support has not been compiled into @value{GDBN},
32706this command will still succeed (and do nothing).
32707
f43030c4
TT
32708This feature is currently (as of @value{GDBN} 7.0) experimental, and
32709may work differently in future versions of @value{GDBN}.
32710
a2c02241
NR
32711@subheading The @code{-var-create} Command
32712@findex -var-create
ef21caaf 32713
a2c02241 32714@subsubheading Synopsis
ef21caaf 32715
a2c02241
NR
32716@smallexample
32717 -var-create @{@var{name} | "-"@}
c3b108f7 32718 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32719@end smallexample
32720
32721This operation creates a variable object, which allows the monitoring of
32722a variable, the result of an expression, a memory cell or a CPU
32723register.
ef21caaf 32724
a2c02241
NR
32725The @var{name} parameter is the string by which the object can be
32726referenced. It must be unique. If @samp{-} is specified, the varobj
32727system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32728unique provided that one does not specify @var{name} of that format.
a2c02241 32729The command fails if a duplicate name is found.
ef21caaf 32730
a2c02241
NR
32731The frame under which the expression should be evaluated can be
32732specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32733frame should be used. A @samp{@@} indicates that a floating variable
32734object must be created.
922fbb7b 32735
a2c02241
NR
32736@var{expression} is any expression valid on the current language set (must not
32737begin with a @samp{*}), or one of the following:
922fbb7b 32738
a2c02241
NR
32739@itemize @bullet
32740@item
32741@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32742
a2c02241
NR
32743@item
32744@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32745
a2c02241
NR
32746@item
32747@samp{$@var{regname}} --- a CPU register name
32748@end itemize
922fbb7b 32749
0cc7d26f
TT
32750@cindex dynamic varobj
32751A varobj's contents may be provided by a Python-based pretty-printer. In this
32752case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32753have slightly different semantics in some cases. If the
32754@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32755will never create a dynamic varobj. This ensures backward
32756compatibility for existing clients.
32757
a2c02241 32758@subsubheading Result
922fbb7b 32759
0cc7d26f
TT
32760This operation returns attributes of the newly-created varobj. These
32761are:
32762
32763@table @samp
32764@item name
32765The name of the varobj.
32766
32767@item numchild
32768The number of children of the varobj. This number is not necessarily
32769reliable for a dynamic varobj. Instead, you must examine the
32770@samp{has_more} attribute.
32771
32772@item value
32773The varobj's scalar value. For a varobj whose type is some sort of
32774aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32775will not be interesting.
32776
32777@item type
32778The varobj's type. This is a string representation of the type, as
8264ba82
AG
32779would be printed by the @value{GDBN} CLI. If @samp{print object}
32780(@pxref{Print Settings, set print object}) is set to @code{on}, the
32781@emph{actual} (derived) type of the object is shown rather than the
32782@emph{declared} one.
0cc7d26f
TT
32783
32784@item thread-id
32785If a variable object is bound to a specific thread, then this is the
5d5658a1 32786thread's global identifier.
0cc7d26f
TT
32787
32788@item has_more
32789For a dynamic varobj, this indicates whether there appear to be any
32790children available. For a non-dynamic varobj, this will be 0.
32791
32792@item dynamic
32793This attribute will be present and have the value @samp{1} if the
32794varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32795then this attribute will not be present.
32796
32797@item displayhint
32798A dynamic varobj can supply a display hint to the front end. The
32799value comes directly from the Python pretty-printer object's
4c374409 32800@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32801@end table
32802
32803Typical output will look like this:
922fbb7b
AC
32804
32805@smallexample
0cc7d26f
TT
32806 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32807 has_more="@var{has_more}"
dcaaae04
NR
32808@end smallexample
32809
a2c02241
NR
32810
32811@subheading The @code{-var-delete} Command
32812@findex -var-delete
922fbb7b
AC
32813
32814@subsubheading Synopsis
32815
32816@smallexample
22d8a470 32817 -var-delete [ -c ] @var{name}
922fbb7b
AC
32818@end smallexample
32819
a2c02241 32820Deletes a previously created variable object and all of its children.
22d8a470 32821With the @samp{-c} option, just deletes the children.
922fbb7b 32822
a2c02241 32823Returns an error if the object @var{name} is not found.
922fbb7b 32824
922fbb7b 32825
a2c02241
NR
32826@subheading The @code{-var-set-format} Command
32827@findex -var-set-format
922fbb7b 32828
a2c02241 32829@subsubheading Synopsis
922fbb7b
AC
32830
32831@smallexample
a2c02241 32832 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32833@end smallexample
32834
a2c02241
NR
32835Sets the output format for the value of the object @var{name} to be
32836@var{format-spec}.
32837
de051565 32838@anchor{-var-set-format}
a2c02241
NR
32839The syntax for the @var{format-spec} is as follows:
32840
32841@smallexample
32842 @var{format-spec} @expansion{}
1c35a88f 32843 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32844@end smallexample
32845
c8b2f53c
VP
32846The natural format is the default format choosen automatically
32847based on the variable type (like decimal for an @code{int}, hex
32848for pointers, etc.).
32849
1c35a88f
LM
32850The zero-hexadecimal format has a representation similar to hexadecimal
32851but with padding zeroes to the left of the value. For example, a 32-bit
32852hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32853zero-hexadecimal format.
32854
c8b2f53c
VP
32855For a variable with children, the format is set only on the
32856variable itself, and the children are not affected.
a2c02241
NR
32857
32858@subheading The @code{-var-show-format} Command
32859@findex -var-show-format
922fbb7b
AC
32860
32861@subsubheading Synopsis
32862
32863@smallexample
a2c02241 32864 -var-show-format @var{name}
922fbb7b
AC
32865@end smallexample
32866
a2c02241 32867Returns the format used to display the value of the object @var{name}.
922fbb7b 32868
a2c02241
NR
32869@smallexample
32870 @var{format} @expansion{}
32871 @var{format-spec}
32872@end smallexample
922fbb7b 32873
922fbb7b 32874
a2c02241
NR
32875@subheading The @code{-var-info-num-children} Command
32876@findex -var-info-num-children
32877
32878@subsubheading Synopsis
32879
32880@smallexample
32881 -var-info-num-children @var{name}
32882@end smallexample
32883
32884Returns the number of children of a variable object @var{name}:
32885
32886@smallexample
32887 numchild=@var{n}
32888@end smallexample
32889
0cc7d26f
TT
32890Note that this number is not completely reliable for a dynamic varobj.
32891It will return the current number of children, but more children may
32892be available.
32893
a2c02241
NR
32894
32895@subheading The @code{-var-list-children} Command
32896@findex -var-list-children
32897
32898@subsubheading Synopsis
32899
32900@smallexample
0cc7d26f 32901 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32902@end smallexample
b569d230 32903@anchor{-var-list-children}
a2c02241
NR
32904
32905Return a list of the children of the specified variable object and
32906create variable objects for them, if they do not already exist. With
f5011d11 32907a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32908@code{--no-values}, print only the names of the variables; if
32909@var{print-values} is 1 or @code{--all-values}, also print their
32910values; and if it is 2 or @code{--simple-values} print the name and
32911value for simple data types and just the name for arrays, structures
32912and unions.
922fbb7b 32913
0cc7d26f
TT
32914@var{from} and @var{to}, if specified, indicate the range of children
32915to report. If @var{from} or @var{to} is less than zero, the range is
32916reset and all children will be reported. Otherwise, children starting
32917at @var{from} (zero-based) and up to and excluding @var{to} will be
32918reported.
32919
32920If a child range is requested, it will only affect the current call to
32921@code{-var-list-children}, but not future calls to @code{-var-update}.
32922For this, you must instead use @code{-var-set-update-range}. The
32923intent of this approach is to enable a front end to implement any
32924update approach it likes; for example, scrolling a view may cause the
32925front end to request more children with @code{-var-list-children}, and
32926then the front end could call @code{-var-set-update-range} with a
32927different range to ensure that future updates are restricted to just
32928the visible items.
32929
b569d230
EZ
32930For each child the following results are returned:
32931
32932@table @var
32933
32934@item name
32935Name of the variable object created for this child.
32936
32937@item exp
32938The expression to be shown to the user by the front end to designate this child.
32939For example this may be the name of a structure member.
32940
0cc7d26f
TT
32941For a dynamic varobj, this value cannot be used to form an
32942expression. There is no way to do this at all with a dynamic varobj.
32943
b569d230
EZ
32944For C/C@t{++} structures there are several pseudo children returned to
32945designate access qualifiers. For these pseudo children @var{exp} is
32946@samp{public}, @samp{private}, or @samp{protected}. In this case the
32947type and value are not present.
32948
0cc7d26f
TT
32949A dynamic varobj will not report the access qualifying
32950pseudo-children, regardless of the language. This information is not
32951available at all with a dynamic varobj.
32952
b569d230 32953@item numchild
0cc7d26f
TT
32954Number of children this child has. For a dynamic varobj, this will be
329550.
b569d230
EZ
32956
32957@item type
8264ba82
AG
32958The type of the child. If @samp{print object}
32959(@pxref{Print Settings, set print object}) is set to @code{on}, the
32960@emph{actual} (derived) type of the object is shown rather than the
32961@emph{declared} one.
b569d230
EZ
32962
32963@item value
32964If values were requested, this is the value.
32965
32966@item thread-id
5d5658a1
PA
32967If this variable object is associated with a thread, this is the
32968thread's global thread id. Otherwise this result is not present.
b569d230
EZ
32969
32970@item frozen
32971If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 32972
9df9dbe0
YQ
32973@item displayhint
32974A dynamic varobj can supply a display hint to the front end. The
32975value comes directly from the Python pretty-printer object's
32976@code{display_hint} method. @xref{Pretty Printing API}.
32977
c78feb39
YQ
32978@item dynamic
32979This attribute will be present and have the value @samp{1} if the
32980varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32981then this attribute will not be present.
32982
b569d230
EZ
32983@end table
32984
0cc7d26f
TT
32985The result may have its own attributes:
32986
32987@table @samp
32988@item displayhint
32989A dynamic varobj can supply a display hint to the front end. The
32990value comes directly from the Python pretty-printer object's
4c374409 32991@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32992
32993@item has_more
32994This is an integer attribute which is nonzero if there are children
32995remaining after the end of the selected range.
32996@end table
32997
922fbb7b
AC
32998@subsubheading Example
32999
33000@smallexample
594fe323 33001(gdb)
a2c02241 33002 -var-list-children n
b569d230 33003 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 33004 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 33005(gdb)
a2c02241 33006 -var-list-children --all-values n
b569d230 33007 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 33008 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
33009@end smallexample
33010
922fbb7b 33011
a2c02241
NR
33012@subheading The @code{-var-info-type} Command
33013@findex -var-info-type
922fbb7b 33014
a2c02241
NR
33015@subsubheading Synopsis
33016
33017@smallexample
33018 -var-info-type @var{name}
33019@end smallexample
33020
33021Returns the type of the specified variable @var{name}. The type is
33022returned as a string in the same format as it is output by the
33023@value{GDBN} CLI:
33024
33025@smallexample
33026 type=@var{typename}
33027@end smallexample
33028
33029
33030@subheading The @code{-var-info-expression} Command
33031@findex -var-info-expression
922fbb7b
AC
33032
33033@subsubheading Synopsis
33034
33035@smallexample
a2c02241 33036 -var-info-expression @var{name}
922fbb7b
AC
33037@end smallexample
33038
02142340
VP
33039Returns a string that is suitable for presenting this
33040variable object in user interface. The string is generally
33041not valid expression in the current language, and cannot be evaluated.
33042
33043For example, if @code{a} is an array, and variable object
33044@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 33045
a2c02241 33046@smallexample
02142340
VP
33047(gdb) -var-info-expression A.1
33048^done,lang="C",exp="1"
a2c02241 33049@end smallexample
922fbb7b 33050
a2c02241 33051@noindent
fa4d0c40
YQ
33052Here, the value of @code{lang} is the language name, which can be
33053found in @ref{Supported Languages}.
02142340
VP
33054
33055Note that the output of the @code{-var-list-children} command also
33056includes those expressions, so the @code{-var-info-expression} command
33057is of limited use.
33058
33059@subheading The @code{-var-info-path-expression} Command
33060@findex -var-info-path-expression
33061
33062@subsubheading Synopsis
33063
33064@smallexample
33065 -var-info-path-expression @var{name}
33066@end smallexample
33067
33068Returns an expression that can be evaluated in the current
33069context and will yield the same value that a variable object has.
33070Compare this with the @code{-var-info-expression} command, which
33071result can be used only for UI presentation. Typical use of
33072the @code{-var-info-path-expression} command is creating a
33073watchpoint from a variable object.
33074
0cc7d26f
TT
33075This command is currently not valid for children of a dynamic varobj,
33076and will give an error when invoked on one.
33077
02142340
VP
33078For example, suppose @code{C} is a C@t{++} class, derived from class
33079@code{Base}, and that the @code{Base} class has a member called
33080@code{m_size}. Assume a variable @code{c} is has the type of
33081@code{C} and a variable object @code{C} was created for variable
33082@code{c}. Then, we'll get this output:
33083@smallexample
33084(gdb) -var-info-path-expression C.Base.public.m_size
33085^done,path_expr=((Base)c).m_size)
33086@end smallexample
922fbb7b 33087
a2c02241
NR
33088@subheading The @code{-var-show-attributes} Command
33089@findex -var-show-attributes
922fbb7b 33090
a2c02241 33091@subsubheading Synopsis
922fbb7b 33092
a2c02241
NR
33093@smallexample
33094 -var-show-attributes @var{name}
33095@end smallexample
922fbb7b 33096
a2c02241 33097List attributes of the specified variable object @var{name}:
922fbb7b
AC
33098
33099@smallexample
a2c02241 33100 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
33101@end smallexample
33102
a2c02241
NR
33103@noindent
33104where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33105
33106@subheading The @code{-var-evaluate-expression} Command
33107@findex -var-evaluate-expression
33108
33109@subsubheading Synopsis
33110
33111@smallexample
de051565 33112 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
33113@end smallexample
33114
33115Evaluates the expression that is represented by the specified variable
de051565
MK
33116object and returns its value as a string. The format of the string
33117can be specified with the @samp{-f} option. The possible values of
33118this option are the same as for @code{-var-set-format}
33119(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33120the current display format will be used. The current display format
33121can be changed using the @code{-var-set-format} command.
a2c02241
NR
33122
33123@smallexample
33124 value=@var{value}
33125@end smallexample
33126
33127Note that one must invoke @code{-var-list-children} for a variable
33128before the value of a child variable can be evaluated.
33129
33130@subheading The @code{-var-assign} Command
33131@findex -var-assign
33132
33133@subsubheading Synopsis
33134
33135@smallexample
33136 -var-assign @var{name} @var{expression}
33137@end smallexample
33138
33139Assigns the value of @var{expression} to the variable object specified
33140by @var{name}. The object must be @samp{editable}. If the variable's
33141value is altered by the assign, the variable will show up in any
33142subsequent @code{-var-update} list.
33143
33144@subsubheading Example
922fbb7b
AC
33145
33146@smallexample
594fe323 33147(gdb)
a2c02241
NR
33148-var-assign var1 3
33149^done,value="3"
594fe323 33150(gdb)
a2c02241
NR
33151-var-update *
33152^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 33153(gdb)
922fbb7b
AC
33154@end smallexample
33155
a2c02241
NR
33156@subheading The @code{-var-update} Command
33157@findex -var-update
33158
33159@subsubheading Synopsis
33160
33161@smallexample
33162 -var-update [@var{print-values}] @{@var{name} | "*"@}
33163@end smallexample
33164
c8b2f53c
VP
33165Reevaluate the expressions corresponding to the variable object
33166@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
33167list of variable objects whose values have changed; @var{name} must
33168be a root variable object. Here, ``changed'' means that the result of
33169@code{-var-evaluate-expression} before and after the
33170@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
33171object names, all existing variable objects are updated, except
33172for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 33173@var{print-values} determines whether both names and values, or just
de051565 33174names are printed. The possible values of this option are the same
36ece8b3
NR
33175as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33176recommended to use the @samp{--all-values} option, to reduce the
33177number of MI commands needed on each program stop.
c8b2f53c 33178
c3b108f7
VP
33179With the @samp{*} parameter, if a variable object is bound to a
33180currently running thread, it will not be updated, without any
33181diagnostic.
a2c02241 33182
0cc7d26f
TT
33183If @code{-var-set-update-range} was previously used on a varobj, then
33184only the selected range of children will be reported.
922fbb7b 33185
0cc7d26f
TT
33186@code{-var-update} reports all the changed varobjs in a tuple named
33187@samp{changelist}.
33188
33189Each item in the change list is itself a tuple holding:
33190
33191@table @samp
33192@item name
33193The name of the varobj.
33194
33195@item value
33196If values were requested for this update, then this field will be
33197present and will hold the value of the varobj.
922fbb7b 33198
0cc7d26f 33199@item in_scope
9f708cb2 33200@anchor{-var-update}
0cc7d26f 33201This field is a string which may take one of three values:
36ece8b3
NR
33202
33203@table @code
33204@item "true"
33205The variable object's current value is valid.
33206
33207@item "false"
33208The variable object does not currently hold a valid value but it may
33209hold one in the future if its associated expression comes back into
33210scope.
33211
33212@item "invalid"
33213The variable object no longer holds a valid value.
33214This can occur when the executable file being debugged has changed,
33215either through recompilation or by using the @value{GDBN} @code{file}
33216command. The front end should normally choose to delete these variable
33217objects.
33218@end table
33219
33220In the future new values may be added to this list so the front should
33221be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33222
0cc7d26f
TT
33223@item type_changed
33224This is only present if the varobj is still valid. If the type
33225changed, then this will be the string @samp{true}; otherwise it will
33226be @samp{false}.
33227
7191c139
JB
33228When a varobj's type changes, its children are also likely to have
33229become incorrect. Therefore, the varobj's children are automatically
33230deleted when this attribute is @samp{true}. Also, the varobj's update
33231range, when set using the @code{-var-set-update-range} command, is
33232unset.
33233
0cc7d26f
TT
33234@item new_type
33235If the varobj's type changed, then this field will be present and will
33236hold the new type.
33237
33238@item new_num_children
33239For a dynamic varobj, if the number of children changed, or if the
33240type changed, this will be the new number of children.
33241
33242The @samp{numchild} field in other varobj responses is generally not
33243valid for a dynamic varobj -- it will show the number of children that
33244@value{GDBN} knows about, but because dynamic varobjs lazily
33245instantiate their children, this will not reflect the number of
33246children which may be available.
33247
33248The @samp{new_num_children} attribute only reports changes to the
33249number of children known by @value{GDBN}. This is the only way to
33250detect whether an update has removed children (which necessarily can
33251only happen at the end of the update range).
33252
33253@item displayhint
33254The display hint, if any.
33255
33256@item has_more
33257This is an integer value, which will be 1 if there are more children
33258available outside the varobj's update range.
33259
33260@item dynamic
33261This attribute will be present and have the value @samp{1} if the
33262varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33263then this attribute will not be present.
33264
33265@item new_children
33266If new children were added to a dynamic varobj within the selected
33267update range (as set by @code{-var-set-update-range}), then they will
33268be listed in this attribute.
33269@end table
33270
33271@subsubheading Example
33272
33273@smallexample
33274(gdb)
33275-var-assign var1 3
33276^done,value="3"
33277(gdb)
33278-var-update --all-values var1
33279^done,changelist=[@{name="var1",value="3",in_scope="true",
33280type_changed="false"@}]
33281(gdb)
33282@end smallexample
33283
25d5ea92
VP
33284@subheading The @code{-var-set-frozen} Command
33285@findex -var-set-frozen
9f708cb2 33286@anchor{-var-set-frozen}
25d5ea92
VP
33287
33288@subsubheading Synopsis
33289
33290@smallexample
9f708cb2 33291 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
33292@end smallexample
33293
9f708cb2 33294Set the frozenness flag on the variable object @var{name}. The
25d5ea92 33295@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 33296frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 33297frozen, then neither itself, nor any of its children, are
9f708cb2 33298implicitly updated by @code{-var-update} of
25d5ea92
VP
33299a parent variable or by @code{-var-update *}. Only
33300@code{-var-update} of the variable itself will update its value and
33301values of its children. After a variable object is unfrozen, it is
33302implicitly updated by all subsequent @code{-var-update} operations.
33303Unfreezing a variable does not update it, only subsequent
33304@code{-var-update} does.
33305
33306@subsubheading Example
33307
33308@smallexample
33309(gdb)
33310-var-set-frozen V 1
33311^done
33312(gdb)
33313@end smallexample
33314
0cc7d26f
TT
33315@subheading The @code{-var-set-update-range} command
33316@findex -var-set-update-range
33317@anchor{-var-set-update-range}
33318
33319@subsubheading Synopsis
33320
33321@smallexample
33322 -var-set-update-range @var{name} @var{from} @var{to}
33323@end smallexample
33324
33325Set the range of children to be returned by future invocations of
33326@code{-var-update}.
33327
33328@var{from} and @var{to} indicate the range of children to report. If
33329@var{from} or @var{to} is less than zero, the range is reset and all
33330children will be reported. Otherwise, children starting at @var{from}
33331(zero-based) and up to and excluding @var{to} will be reported.
33332
33333@subsubheading Example
33334
33335@smallexample
33336(gdb)
33337-var-set-update-range V 1 2
33338^done
33339@end smallexample
33340
b6313243
TT
33341@subheading The @code{-var-set-visualizer} command
33342@findex -var-set-visualizer
33343@anchor{-var-set-visualizer}
33344
33345@subsubheading Synopsis
33346
33347@smallexample
33348 -var-set-visualizer @var{name} @var{visualizer}
33349@end smallexample
33350
33351Set a visualizer for the variable object @var{name}.
33352
33353@var{visualizer} is the visualizer to use. The special value
33354@samp{None} means to disable any visualizer in use.
33355
33356If not @samp{None}, @var{visualizer} must be a Python expression.
33357This expression must evaluate to a callable object which accepts a
33358single argument. @value{GDBN} will call this object with the value of
33359the varobj @var{name} as an argument (this is done so that the same
33360Python pretty-printing code can be used for both the CLI and MI).
33361When called, this object must return an object which conforms to the
4c374409 33362pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
33363
33364The pre-defined function @code{gdb.default_visualizer} may be used to
33365select a visualizer by following the built-in process
33366(@pxref{Selecting Pretty-Printers}). This is done automatically when
33367a varobj is created, and so ordinarily is not needed.
33368
33369This feature is only available if Python support is enabled. The MI
d192b373 33370command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
33371can be used to check this.
33372
33373@subsubheading Example
33374
33375Resetting the visualizer:
33376
33377@smallexample
33378(gdb)
33379-var-set-visualizer V None
33380^done
33381@end smallexample
33382
33383Reselecting the default (type-based) visualizer:
33384
33385@smallexample
33386(gdb)
33387-var-set-visualizer V gdb.default_visualizer
33388^done
33389@end smallexample
33390
33391Suppose @code{SomeClass} is a visualizer class. A lambda expression
33392can be used to instantiate this class for a varobj:
33393
33394@smallexample
33395(gdb)
33396-var-set-visualizer V "lambda val: SomeClass()"
33397^done
33398@end smallexample
25d5ea92 33399
a2c02241
NR
33400@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33401@node GDB/MI Data Manipulation
33402@section @sc{gdb/mi} Data Manipulation
922fbb7b 33403
a2c02241
NR
33404@cindex data manipulation, in @sc{gdb/mi}
33405@cindex @sc{gdb/mi}, data manipulation
33406This section describes the @sc{gdb/mi} commands that manipulate data:
33407examine memory and registers, evaluate expressions, etc.
33408
a86c90e6
SM
33409For details about what an addressable memory unit is,
33410@pxref{addressable memory unit}.
33411
a2c02241
NR
33412@c REMOVED FROM THE INTERFACE.
33413@c @subheading -data-assign
33414@c Change the value of a program variable. Plenty of side effects.
79a6e687 33415@c @subsubheading GDB Command
a2c02241
NR
33416@c set variable
33417@c @subsubheading Example
33418@c N.A.
33419
33420@subheading The @code{-data-disassemble} Command
33421@findex -data-disassemble
922fbb7b
AC
33422
33423@subsubheading Synopsis
33424
33425@smallexample
a2c02241
NR
33426 -data-disassemble
33427 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 33428 | [ -a @var{addr} ]
a2c02241
NR
33429 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33430 -- @var{mode}
922fbb7b
AC
33431@end smallexample
33432
a2c02241
NR
33433@noindent
33434Where:
33435
33436@table @samp
33437@item @var{start-addr}
33438is the beginning address (or @code{$pc})
33439@item @var{end-addr}
33440is the end address
26fb3983
JV
33441@item @var{addr}
33442is an address anywhere within (or the name of) the function to
33443disassemble. If an address is specified, the whole function
33444surrounding that address will be disassembled. If a name is
33445specified, the whole function with that name will be disassembled.
a2c02241
NR
33446@item @var{filename}
33447is the name of the file to disassemble
33448@item @var{linenum}
33449is the line number to disassemble around
33450@item @var{lines}
d3e8051b 33451is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
33452the whole function will be disassembled, in case no @var{end-addr} is
33453specified. If @var{end-addr} is specified as a non-zero value, and
33454@var{lines} is lower than the number of disassembly lines between
33455@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33456displayed; if @var{lines} is higher than the number of lines between
33457@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33458are displayed.
33459@item @var{mode}
6ff0ba5f
DE
33460is one of:
33461@itemize @bullet
33462@item 0 disassembly only
33463@item 1 mixed source and disassembly (deprecated)
33464@item 2 disassembly with raw opcodes
33465@item 3 mixed source and disassembly with raw opcodes (deprecated)
33466@item 4 mixed source and disassembly
33467@item 5 mixed source and disassembly with raw opcodes
33468@end itemize
33469
33470Modes 1 and 3 are deprecated. The output is ``source centric''
33471which hasn't proved useful in practice.
33472@xref{Machine Code}, for a discussion of the difference between
33473@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
33474@end table
33475
33476@subsubheading Result
33477
ed8a1c2d
AB
33478The result of the @code{-data-disassemble} command will be a list named
33479@samp{asm_insns}, the contents of this list depend on the @var{mode}
33480used with the @code{-data-disassemble} command.
a2c02241 33481
ed8a1c2d
AB
33482For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33483following fields:
33484
33485@table @code
33486@item address
33487The address at which this instruction was disassembled.
33488
33489@item func-name
33490The name of the function this instruction is within.
33491
33492@item offset
33493The decimal offset in bytes from the start of @samp{func-name}.
33494
33495@item inst
33496The text disassembly for this @samp{address}.
33497
33498@item opcodes
6ff0ba5f 33499This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33500bytes for the @samp{inst} field.
33501
33502@end table
33503
6ff0ba5f 33504For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33505@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33506
ed8a1c2d
AB
33507@table @code
33508@item line
33509The line number within @samp{file}.
33510
33511@item file
33512The file name from the compilation unit. This might be an absolute
33513file name or a relative file name depending on the compile command
33514used.
33515
33516@item fullname
f35a17b5
JK
33517Absolute file name of @samp{file}. It is converted to a canonical form
33518using the source file search path
33519(@pxref{Source Path, ,Specifying Source Directories})
33520and after resolving all the symbolic links.
33521
33522If the source file is not found this field will contain the path as
33523present in the debug information.
ed8a1c2d
AB
33524
33525@item line_asm_insn
33526This is a list of tuples containing the disassembly for @samp{line} in
33527@samp{file}. The fields of each tuple are the same as for
33528@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33529@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33530@samp{opcodes}.
33531
33532@end table
33533
33534Note that whatever included in the @samp{inst} field, is not
33535manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33536adjust its format.
922fbb7b
AC
33537
33538@subsubheading @value{GDBN} Command
33539
ed8a1c2d 33540The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33541
33542@subsubheading Example
33543
a2c02241
NR
33544Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33545
922fbb7b 33546@smallexample
594fe323 33547(gdb)
a2c02241
NR
33548-data-disassemble -s $pc -e "$pc + 20" -- 0
33549^done,
33550asm_insns=[
33551@{address="0x000107c0",func-name="main",offset="4",
33552inst="mov 2, %o0"@},
33553@{address="0x000107c4",func-name="main",offset="8",
33554inst="sethi %hi(0x11800), %o2"@},
33555@{address="0x000107c8",func-name="main",offset="12",
33556inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33557@{address="0x000107cc",func-name="main",offset="16",
33558inst="sethi %hi(0x11800), %o2"@},
33559@{address="0x000107d0",func-name="main",offset="20",
33560inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33561(gdb)
a2c02241
NR
33562@end smallexample
33563
33564Disassemble the whole @code{main} function. Line 32 is part of
33565@code{main}.
33566
33567@smallexample
33568-data-disassemble -f basics.c -l 32 -- 0
33569^done,asm_insns=[
33570@{address="0x000107bc",func-name="main",offset="0",
33571inst="save %sp, -112, %sp"@},
33572@{address="0x000107c0",func-name="main",offset="4",
33573inst="mov 2, %o0"@},
33574@{address="0x000107c4",func-name="main",offset="8",
33575inst="sethi %hi(0x11800), %o2"@},
33576[@dots{}]
33577@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33578@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33579(gdb)
922fbb7b
AC
33580@end smallexample
33581
a2c02241 33582Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33583
a2c02241 33584@smallexample
594fe323 33585(gdb)
a2c02241
NR
33586-data-disassemble -f basics.c -l 32 -n 3 -- 0
33587^done,asm_insns=[
33588@{address="0x000107bc",func-name="main",offset="0",
33589inst="save %sp, -112, %sp"@},
33590@{address="0x000107c0",func-name="main",offset="4",
33591inst="mov 2, %o0"@},
33592@{address="0x000107c4",func-name="main",offset="8",
33593inst="sethi %hi(0x11800), %o2"@}]
594fe323 33594(gdb)
a2c02241
NR
33595@end smallexample
33596
33597Disassemble 3 instructions from the start of @code{main} in mixed mode:
33598
33599@smallexample
594fe323 33600(gdb)
a2c02241
NR
33601-data-disassemble -f basics.c -l 32 -n 3 -- 1
33602^done,asm_insns=[
33603src_and_asm_line=@{line="31",
ed8a1c2d
AB
33604file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33605fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33606line_asm_insn=[@{address="0x000107bc",
33607func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33608src_and_asm_line=@{line="32",
ed8a1c2d
AB
33609file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33610fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33611line_asm_insn=[@{address="0x000107c0",
33612func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33613@{address="0x000107c4",func-name="main",offset="8",
33614inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33615(gdb)
a2c02241
NR
33616@end smallexample
33617
33618
33619@subheading The @code{-data-evaluate-expression} Command
33620@findex -data-evaluate-expression
922fbb7b
AC
33621
33622@subsubheading Synopsis
33623
33624@smallexample
a2c02241 33625 -data-evaluate-expression @var{expr}
922fbb7b
AC
33626@end smallexample
33627
a2c02241
NR
33628Evaluate @var{expr} as an expression. The expression could contain an
33629inferior function call. The function call will execute synchronously.
33630If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33631
33632@subsubheading @value{GDBN} Command
33633
a2c02241
NR
33634The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33635@samp{call}. In @code{gdbtk} only, there's a corresponding
33636@samp{gdb_eval} command.
922fbb7b
AC
33637
33638@subsubheading Example
33639
a2c02241
NR
33640In the following example, the numbers that precede the commands are the
33641@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33642Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33643output.
33644
922fbb7b 33645@smallexample
a2c02241
NR
33646211-data-evaluate-expression A
33647211^done,value="1"
594fe323 33648(gdb)
a2c02241
NR
33649311-data-evaluate-expression &A
33650311^done,value="0xefffeb7c"
594fe323 33651(gdb)
a2c02241
NR
33652411-data-evaluate-expression A+3
33653411^done,value="4"
594fe323 33654(gdb)
a2c02241
NR
33655511-data-evaluate-expression "A + 3"
33656511^done,value="4"
594fe323 33657(gdb)
a2c02241 33658@end smallexample
922fbb7b
AC
33659
33660
a2c02241
NR
33661@subheading The @code{-data-list-changed-registers} Command
33662@findex -data-list-changed-registers
922fbb7b
AC
33663
33664@subsubheading Synopsis
33665
33666@smallexample
a2c02241 33667 -data-list-changed-registers
922fbb7b
AC
33668@end smallexample
33669
a2c02241 33670Display a list of the registers that have changed.
922fbb7b
AC
33671
33672@subsubheading @value{GDBN} Command
33673
a2c02241
NR
33674@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33675has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33676
33677@subsubheading Example
922fbb7b 33678
a2c02241 33679On a PPC MBX board:
922fbb7b
AC
33680
33681@smallexample
594fe323 33682(gdb)
a2c02241
NR
33683-exec-continue
33684^running
922fbb7b 33685
594fe323 33686(gdb)
a47ec5fe
AR
33687*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33688func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33689line="5",arch="powerpc"@}
594fe323 33690(gdb)
a2c02241
NR
33691-data-list-changed-registers
33692^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33693"10","11","13","14","15","16","17","18","19","20","21","22","23",
33694"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33695(gdb)
a2c02241 33696@end smallexample
922fbb7b
AC
33697
33698
a2c02241
NR
33699@subheading The @code{-data-list-register-names} Command
33700@findex -data-list-register-names
922fbb7b
AC
33701
33702@subsubheading Synopsis
33703
33704@smallexample
a2c02241 33705 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33706@end smallexample
33707
a2c02241
NR
33708Show a list of register names for the current target. If no arguments
33709are given, it shows a list of the names of all the registers. If
33710integer numbers are given as arguments, it will print a list of the
33711names of the registers corresponding to the arguments. To ensure
33712consistency between a register name and its number, the output list may
33713include empty register names.
922fbb7b
AC
33714
33715@subsubheading @value{GDBN} Command
33716
a2c02241
NR
33717@value{GDBN} does not have a command which corresponds to
33718@samp{-data-list-register-names}. In @code{gdbtk} there is a
33719corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33720
33721@subsubheading Example
922fbb7b 33722
a2c02241
NR
33723For the PPC MBX board:
33724@smallexample
594fe323 33725(gdb)
a2c02241
NR
33726-data-list-register-names
33727^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33728"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33729"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33730"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33731"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33732"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33733"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33734(gdb)
a2c02241
NR
33735-data-list-register-names 1 2 3
33736^done,register-names=["r1","r2","r3"]
594fe323 33737(gdb)
a2c02241 33738@end smallexample
922fbb7b 33739
a2c02241
NR
33740@subheading The @code{-data-list-register-values} Command
33741@findex -data-list-register-values
922fbb7b
AC
33742
33743@subsubheading Synopsis
33744
33745@smallexample
c898adb7
YQ
33746 -data-list-register-values
33747 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33748@end smallexample
33749
697aa1b7
EZ
33750Display the registers' contents. The format according to which the
33751registers' contents are to be returned is given by @var{fmt}, followed
33752by an optional list of numbers specifying the registers to display. A
33753missing list of numbers indicates that the contents of all the
33754registers must be returned. The @code{--skip-unavailable} option
33755indicates that only the available registers are to be returned.
a2c02241
NR
33756
33757Allowed formats for @var{fmt} are:
33758
33759@table @code
33760@item x
33761Hexadecimal
33762@item o
33763Octal
33764@item t
33765Binary
33766@item d
33767Decimal
33768@item r
33769Raw
33770@item N
33771Natural
33772@end table
922fbb7b
AC
33773
33774@subsubheading @value{GDBN} Command
33775
a2c02241
NR
33776The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33777all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33778
33779@subsubheading Example
922fbb7b 33780
a2c02241
NR
33781For a PPC MBX board (note: line breaks are for readability only, they
33782don't appear in the actual output):
33783
33784@smallexample
594fe323 33785(gdb)
a2c02241
NR
33786-data-list-register-values r 64 65
33787^done,register-values=[@{number="64",value="0xfe00a300"@},
33788@{number="65",value="0x00029002"@}]
594fe323 33789(gdb)
a2c02241
NR
33790-data-list-register-values x
33791^done,register-values=[@{number="0",value="0xfe0043c8"@},
33792@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33793@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33794@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33795@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33796@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33797@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33798@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33799@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33800@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33801@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33802@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33803@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33804@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33805@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33806@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33807@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33808@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33809@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33810@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33811@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33812@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33813@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33814@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33815@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33816@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33817@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33818@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33819@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33820@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33821@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33822@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33823@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33824@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33825@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33826@{number="69",value="0x20002b03"@}]
594fe323 33827(gdb)
a2c02241 33828@end smallexample
922fbb7b 33829
a2c02241
NR
33830
33831@subheading The @code{-data-read-memory} Command
33832@findex -data-read-memory
922fbb7b 33833
8dedea02
VP
33834This command is deprecated, use @code{-data-read-memory-bytes} instead.
33835
922fbb7b
AC
33836@subsubheading Synopsis
33837
33838@smallexample
a2c02241
NR
33839 -data-read-memory [ -o @var{byte-offset} ]
33840 @var{address} @var{word-format} @var{word-size}
33841 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33842@end smallexample
33843
a2c02241
NR
33844@noindent
33845where:
922fbb7b 33846
a2c02241
NR
33847@table @samp
33848@item @var{address}
33849An expression specifying the address of the first memory word to be
33850read. Complex expressions containing embedded white space should be
33851quoted using the C convention.
922fbb7b 33852
a2c02241
NR
33853@item @var{word-format}
33854The format to be used to print the memory words. The notation is the
33855same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33856,Output Formats}).
922fbb7b 33857
a2c02241
NR
33858@item @var{word-size}
33859The size of each memory word in bytes.
922fbb7b 33860
a2c02241
NR
33861@item @var{nr-rows}
33862The number of rows in the output table.
922fbb7b 33863
a2c02241
NR
33864@item @var{nr-cols}
33865The number of columns in the output table.
922fbb7b 33866
a2c02241
NR
33867@item @var{aschar}
33868If present, indicates that each row should include an @sc{ascii} dump. The
33869value of @var{aschar} is used as a padding character when a byte is not a
33870member of the printable @sc{ascii} character set (printable @sc{ascii}
33871characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33872
a2c02241
NR
33873@item @var{byte-offset}
33874An offset to add to the @var{address} before fetching memory.
33875@end table
922fbb7b 33876
a2c02241
NR
33877This command displays memory contents as a table of @var{nr-rows} by
33878@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33879@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33880(returned as @samp{total-bytes}). Should less than the requested number
33881of bytes be returned by the target, the missing words are identified
33882using @samp{N/A}. The number of bytes read from the target is returned
33883in @samp{nr-bytes} and the starting address used to read memory in
33884@samp{addr}.
33885
33886The address of the next/previous row or page is available in
33887@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33888@samp{prev-page}.
922fbb7b
AC
33889
33890@subsubheading @value{GDBN} Command
33891
a2c02241
NR
33892The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33893@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33894
33895@subsubheading Example
32e7087d 33896
a2c02241
NR
33897Read six bytes of memory starting at @code{bytes+6} but then offset by
33898@code{-6} bytes. Format as three rows of two columns. One byte per
33899word. Display each word in hex.
32e7087d
JB
33900
33901@smallexample
594fe323 33902(gdb)
a2c02241
NR
339039-data-read-memory -o -6 -- bytes+6 x 1 3 2
339049^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33905next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33906prev-page="0x0000138a",memory=[
33907@{addr="0x00001390",data=["0x00","0x01"]@},
33908@{addr="0x00001392",data=["0x02","0x03"]@},
33909@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33910(gdb)
32e7087d
JB
33911@end smallexample
33912
a2c02241
NR
33913Read two bytes of memory starting at address @code{shorts + 64} and
33914display as a single word formatted in decimal.
32e7087d 33915
32e7087d 33916@smallexample
594fe323 33917(gdb)
a2c02241
NR
339185-data-read-memory shorts+64 d 2 1 1
339195^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33920next-row="0x00001512",prev-row="0x0000150e",
33921next-page="0x00001512",prev-page="0x0000150e",memory=[
33922@{addr="0x00001510",data=["128"]@}]
594fe323 33923(gdb)
32e7087d
JB
33924@end smallexample
33925
a2c02241
NR
33926Read thirty two bytes of memory starting at @code{bytes+16} and format
33927as eight rows of four columns. Include a string encoding with @samp{x}
33928used as the non-printable character.
922fbb7b
AC
33929
33930@smallexample
594fe323 33931(gdb)
a2c02241
NR
339324-data-read-memory bytes+16 x 1 8 4 x
339334^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33934next-row="0x000013c0",prev-row="0x0000139c",
33935next-page="0x000013c0",prev-page="0x00001380",memory=[
33936@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33937@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33938@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33939@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33940@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33941@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33942@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33943@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33944(gdb)
922fbb7b
AC
33945@end smallexample
33946
8dedea02
VP
33947@subheading The @code{-data-read-memory-bytes} Command
33948@findex -data-read-memory-bytes
33949
33950@subsubheading Synopsis
33951
33952@smallexample
a86c90e6 33953 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33954 @var{address} @var{count}
33955@end smallexample
33956
33957@noindent
33958where:
33959
33960@table @samp
33961@item @var{address}
a86c90e6
SM
33962An expression specifying the address of the first addressable memory unit
33963to be read. Complex expressions containing embedded white space should be
8dedea02
VP
33964quoted using the C convention.
33965
33966@item @var{count}
a86c90e6
SM
33967The number of addressable memory units to read. This should be an integer
33968literal.
8dedea02 33969
a86c90e6
SM
33970@item @var{offset}
33971The offset relative to @var{address} at which to start reading. This
33972should be an integer literal. This option is provided so that a frontend
33973is not required to first evaluate address and then perform address
33974arithmetics itself.
8dedea02
VP
33975
33976@end table
33977
33978This command attempts to read all accessible memory regions in the
33979specified range. First, all regions marked as unreadable in the memory
33980map (if one is defined) will be skipped. @xref{Memory Region
33981Attributes}. Second, @value{GDBN} will attempt to read the remaining
33982regions. For each one, if reading full region results in an errors,
33983@value{GDBN} will try to read a subset of the region.
33984
a86c90e6
SM
33985In general, every single memory unit in the region may be readable or not,
33986and the only way to read every readable unit is to try a read at
8dedea02 33987every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 33988attempt to read all accessible memory units at either beginning or the end
8dedea02 33989of the region, using a binary division scheme. This heuristic works
6b92c0d3 33990well for reading across a memory map boundary. Note that if a region
8dedea02
VP
33991has a readable range that is neither at the beginning or the end,
33992@value{GDBN} will not read it.
33993
33994The result record (@pxref{GDB/MI Result Records}) that is output of
33995the command includes a field named @samp{memory} whose content is a
33996list of tuples. Each tuple represent a successfully read memory block
33997and has the following fields:
33998
33999@table @code
34000@item begin
34001The start address of the memory block, as hexadecimal literal.
34002
34003@item end
34004The end address of the memory block, as hexadecimal literal.
34005
34006@item offset
34007The offset of the memory block, as hexadecimal literal, relative to
34008the start address passed to @code{-data-read-memory-bytes}.
34009
34010@item contents
34011The contents of the memory block, in hex.
34012
34013@end table
34014
34015
34016
34017@subsubheading @value{GDBN} Command
34018
34019The corresponding @value{GDBN} command is @samp{x}.
34020
34021@subsubheading Example
34022
34023@smallexample
34024(gdb)
34025-data-read-memory-bytes &a 10
34026^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34027 end="0xbffff15e",
34028 contents="01000000020000000300"@}]
34029(gdb)
34030@end smallexample
34031
34032
34033@subheading The @code{-data-write-memory-bytes} Command
34034@findex -data-write-memory-bytes
34035
34036@subsubheading Synopsis
34037
34038@smallexample
34039 -data-write-memory-bytes @var{address} @var{contents}
62747a60 34040 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
34041@end smallexample
34042
34043@noindent
34044where:
34045
34046@table @samp
34047@item @var{address}
a86c90e6
SM
34048An expression specifying the address of the first addressable memory unit
34049to be written. Complex expressions containing embedded white space should
34050be quoted using the C convention.
8dedea02
VP
34051
34052@item @var{contents}
a86c90e6
SM
34053The hex-encoded data to write. It is an error if @var{contents} does
34054not represent an integral number of addressable memory units.
8dedea02 34055
62747a60 34056@item @var{count}
a86c90e6
SM
34057Optional argument indicating the number of addressable memory units to be
34058written. If @var{count} is greater than @var{contents}' length,
34059@value{GDBN} will repeatedly write @var{contents} until it fills
34060@var{count} memory units.
62747a60 34061
8dedea02
VP
34062@end table
34063
34064@subsubheading @value{GDBN} Command
34065
34066There's no corresponding @value{GDBN} command.
34067
34068@subsubheading Example
34069
34070@smallexample
34071(gdb)
34072-data-write-memory-bytes &a "aabbccdd"
34073^done
34074(gdb)
34075@end smallexample
34076
62747a60
TT
34077@smallexample
34078(gdb)
34079-data-write-memory-bytes &a "aabbccdd" 16e
34080^done
34081(gdb)
34082@end smallexample
8dedea02 34083
a2c02241
NR
34084@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34085@node GDB/MI Tracepoint Commands
34086@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 34087
18148017
VP
34088The commands defined in this section implement MI support for
34089tracepoints. For detailed introduction, see @ref{Tracepoints}.
34090
34091@subheading The @code{-trace-find} Command
34092@findex -trace-find
34093
34094@subsubheading Synopsis
34095
34096@smallexample
34097 -trace-find @var{mode} [@var{parameters}@dots{}]
34098@end smallexample
34099
34100Find a trace frame using criteria defined by @var{mode} and
34101@var{parameters}. The following table lists permissible
34102modes and their parameters. For details of operation, see @ref{tfind}.
34103
34104@table @samp
34105
34106@item none
34107No parameters are required. Stops examining trace frames.
34108
34109@item frame-number
34110An integer is required as parameter. Selects tracepoint frame with
34111that index.
34112
34113@item tracepoint-number
34114An integer is required as parameter. Finds next
34115trace frame that corresponds to tracepoint with the specified number.
34116
34117@item pc
34118An address is required as parameter. Finds
34119next trace frame that corresponds to any tracepoint at the specified
34120address.
34121
34122@item pc-inside-range
34123Two addresses are required as parameters. Finds next trace
34124frame that corresponds to a tracepoint at an address inside the
34125specified range. Both bounds are considered to be inside the range.
34126
34127@item pc-outside-range
34128Two addresses are required as parameters. Finds
34129next trace frame that corresponds to a tracepoint at an address outside
34130the specified range. Both bounds are considered to be inside the range.
34131
34132@item line
34133Line specification is required as parameter. @xref{Specify Location}.
34134Finds next trace frame that corresponds to a tracepoint at
34135the specified location.
34136
34137@end table
34138
34139If @samp{none} was passed as @var{mode}, the response does not
34140have fields. Otherwise, the response may have the following fields:
34141
34142@table @samp
34143@item found
34144This field has either @samp{0} or @samp{1} as the value, depending
34145on whether a matching tracepoint was found.
34146
34147@item traceframe
34148The index of the found traceframe. This field is present iff
34149the @samp{found} field has value of @samp{1}.
34150
34151@item tracepoint
34152The index of the found tracepoint. This field is present iff
34153the @samp{found} field has value of @samp{1}.
34154
34155@item frame
34156The information about the frame corresponding to the found trace
34157frame. This field is present only if a trace frame was found.
cd64ee31 34158@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
34159
34160@end table
34161
7d13fe92
SS
34162@subsubheading @value{GDBN} Command
34163
34164The corresponding @value{GDBN} command is @samp{tfind}.
34165
18148017
VP
34166@subheading -trace-define-variable
34167@findex -trace-define-variable
34168
34169@subsubheading Synopsis
34170
34171@smallexample
34172 -trace-define-variable @var{name} [ @var{value} ]
34173@end smallexample
34174
34175Create trace variable @var{name} if it does not exist. If
34176@var{value} is specified, sets the initial value of the specified
34177trace variable to that value. Note that the @var{name} should start
34178with the @samp{$} character.
34179
7d13fe92
SS
34180@subsubheading @value{GDBN} Command
34181
34182The corresponding @value{GDBN} command is @samp{tvariable}.
34183
dc673c81
YQ
34184@subheading The @code{-trace-frame-collected} Command
34185@findex -trace-frame-collected
34186
34187@subsubheading Synopsis
34188
34189@smallexample
34190 -trace-frame-collected
34191 [--var-print-values @var{var_pval}]
34192 [--comp-print-values @var{comp_pval}]
34193 [--registers-format @var{regformat}]
34194 [--memory-contents]
34195@end smallexample
34196
34197This command returns the set of collected objects, register names,
34198trace state variable names, memory ranges and computed expressions
34199that have been collected at a particular trace frame. The optional
34200parameters to the command affect the output format in different ways.
34201See the output description table below for more details.
34202
34203The reported names can be used in the normal manner to create
34204varobjs and inspect the objects themselves. The items returned by
34205this command are categorized so that it is clear which is a variable,
34206which is a register, which is a trace state variable, which is a
34207memory range and which is a computed expression.
34208
34209For instance, if the actions were
34210@smallexample
34211collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34212collect *(int*)0xaf02bef0@@40
34213@end smallexample
34214
34215@noindent
34216the object collected in its entirety would be @code{myVar}. The
34217object @code{myArray} would be partially collected, because only the
34218element at index @code{myIndex} would be collected. The remaining
34219objects would be computed expressions.
34220
34221An example output would be:
34222
34223@smallexample
34224(gdb)
34225-trace-frame-collected
34226^done,
34227 explicit-variables=[@{name="myVar",value="1"@}],
34228 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34229 @{name="myObj.field",value="0"@},
34230 @{name="myPtr->field",value="1"@},
34231 @{name="myCount + 2",value="3"@},
34232 @{name="$tvar1 + 1",value="43970027"@}],
34233 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34234 @{number="1",value="0x0"@},
34235 @{number="2",value="0x4"@},
34236 ...
34237 @{number="125",value="0x0"@}],
34238 tvars=[@{name="$tvar1",current="43970026"@}],
34239 memory=[@{address="0x0000000000602264",length="4"@},
34240 @{address="0x0000000000615bc0",length="4"@}]
34241(gdb)
34242@end smallexample
34243
34244Where:
34245
34246@table @code
34247@item explicit-variables
34248The set of objects that have been collected in their entirety (as
34249opposed to collecting just a few elements of an array or a few struct
34250members). For each object, its name and value are printed.
34251The @code{--var-print-values} option affects how or whether the value
34252field is output. If @var{var_pval} is 0, then print only the names;
34253if it is 1, print also their values; and if it is 2, print the name,
34254type and value for simple data types, and the name and type for
34255arrays, structures and unions.
34256
34257@item computed-expressions
34258The set of computed expressions that have been collected at the
34259current trace frame. The @code{--comp-print-values} option affects
34260this set like the @code{--var-print-values} option affects the
34261@code{explicit-variables} set. See above.
34262
34263@item registers
34264The registers that have been collected at the current trace frame.
34265For each register collected, the name and current value are returned.
34266The value is formatted according to the @code{--registers-format}
34267option. See the @command{-data-list-register-values} command for a
34268list of the allowed formats. The default is @samp{x}.
34269
34270@item tvars
34271The trace state variables that have been collected at the current
34272trace frame. For each trace state variable collected, the name and
34273current value are returned.
34274
34275@item memory
34276The set of memory ranges that have been collected at the current trace
34277frame. Its content is a list of tuples. Each tuple represents a
34278collected memory range and has the following fields:
34279
34280@table @code
34281@item address
34282The start address of the memory range, as hexadecimal literal.
34283
34284@item length
34285The length of the memory range, as decimal literal.
34286
34287@item contents
34288The contents of the memory block, in hex. This field is only present
34289if the @code{--memory-contents} option is specified.
34290
34291@end table
34292
34293@end table
34294
34295@subsubheading @value{GDBN} Command
34296
34297There is no corresponding @value{GDBN} command.
34298
34299@subsubheading Example
34300
18148017
VP
34301@subheading -trace-list-variables
34302@findex -trace-list-variables
922fbb7b 34303
18148017 34304@subsubheading Synopsis
922fbb7b 34305
18148017
VP
34306@smallexample
34307 -trace-list-variables
34308@end smallexample
922fbb7b 34309
18148017
VP
34310Return a table of all defined trace variables. Each element of the
34311table has the following fields:
922fbb7b 34312
18148017
VP
34313@table @samp
34314@item name
34315The name of the trace variable. This field is always present.
922fbb7b 34316
18148017
VP
34317@item initial
34318The initial value. This is a 64-bit signed integer. This
34319field is always present.
922fbb7b 34320
18148017
VP
34321@item current
34322The value the trace variable has at the moment. This is a 64-bit
34323signed integer. This field is absent iff current value is
34324not defined, for example if the trace was never run, or is
34325presently running.
922fbb7b 34326
18148017 34327@end table
922fbb7b 34328
7d13fe92
SS
34329@subsubheading @value{GDBN} Command
34330
34331The corresponding @value{GDBN} command is @samp{tvariables}.
34332
18148017 34333@subsubheading Example
922fbb7b 34334
18148017
VP
34335@smallexample
34336(gdb)
34337-trace-list-variables
34338^done,trace-variables=@{nr_rows="1",nr_cols="3",
34339hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34340 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34341 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34342body=[variable=@{name="$trace_timestamp",initial="0"@}
34343 variable=@{name="$foo",initial="10",current="15"@}]@}
34344(gdb)
34345@end smallexample
922fbb7b 34346
18148017
VP
34347@subheading -trace-save
34348@findex -trace-save
922fbb7b 34349
18148017
VP
34350@subsubheading Synopsis
34351
34352@smallexample
99e61eda 34353 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
34354@end smallexample
34355
34356Saves the collected trace data to @var{filename}. Without the
34357@samp{-r} option, the data is downloaded from the target and saved
34358in a local file. With the @samp{-r} option the target is asked
34359to perform the save.
34360
99e61eda
SM
34361By default, this command will save the trace in the tfile format. You can
34362supply the optional @samp{-ctf} argument to save it the CTF format. See
34363@ref{Trace Files} for more information about CTF.
34364
7d13fe92
SS
34365@subsubheading @value{GDBN} Command
34366
34367The corresponding @value{GDBN} command is @samp{tsave}.
34368
18148017
VP
34369
34370@subheading -trace-start
34371@findex -trace-start
34372
34373@subsubheading Synopsis
34374
34375@smallexample
34376 -trace-start
34377@end smallexample
922fbb7b 34378
be06ba8c 34379Starts a tracing experiment. The result of this command does not
18148017 34380have any fields.
922fbb7b 34381
7d13fe92
SS
34382@subsubheading @value{GDBN} Command
34383
34384The corresponding @value{GDBN} command is @samp{tstart}.
34385
18148017
VP
34386@subheading -trace-status
34387@findex -trace-status
922fbb7b 34388
18148017
VP
34389@subsubheading Synopsis
34390
34391@smallexample
34392 -trace-status
34393@end smallexample
34394
a97153c7 34395Obtains the status of a tracing experiment. The result may include
18148017
VP
34396the following fields:
34397
34398@table @samp
34399
34400@item supported
34401May have a value of either @samp{0}, when no tracing operations are
34402supported, @samp{1}, when all tracing operations are supported, or
34403@samp{file} when examining trace file. In the latter case, examining
34404of trace frame is possible but new tracing experiement cannot be
34405started. This field is always present.
34406
34407@item running
34408May have a value of either @samp{0} or @samp{1} depending on whether
34409tracing experiement is in progress on target. This field is present
34410if @samp{supported} field is not @samp{0}.
34411
34412@item stop-reason
34413Report the reason why the tracing was stopped last time. This field
34414may be absent iff tracing was never stopped on target yet. The
34415value of @samp{request} means the tracing was stopped as result of
34416the @code{-trace-stop} command. The value of @samp{overflow} means
34417the tracing buffer is full. The value of @samp{disconnection} means
34418tracing was automatically stopped when @value{GDBN} has disconnected.
34419The value of @samp{passcount} means tracing was stopped when a
34420tracepoint was passed a maximal number of times for that tracepoint.
34421This field is present if @samp{supported} field is not @samp{0}.
34422
34423@item stopping-tracepoint
34424The number of tracepoint whose passcount as exceeded. This field is
34425present iff the @samp{stop-reason} field has the value of
34426@samp{passcount}.
34427
34428@item frames
87290684
SS
34429@itemx frames-created
34430The @samp{frames} field is a count of the total number of trace frames
34431in the trace buffer, while @samp{frames-created} is the total created
34432during the run, including ones that were discarded, such as when a
34433circular trace buffer filled up. Both fields are optional.
18148017
VP
34434
34435@item buffer-size
34436@itemx buffer-free
34437These fields tell the current size of the tracing buffer and the
87290684 34438remaining space. These fields are optional.
18148017 34439
a97153c7
PA
34440@item circular
34441The value of the circular trace buffer flag. @code{1} means that the
34442trace buffer is circular and old trace frames will be discarded if
34443necessary to make room, @code{0} means that the trace buffer is linear
34444and may fill up.
34445
34446@item disconnected
34447The value of the disconnected tracing flag. @code{1} means that
34448tracing will continue after @value{GDBN} disconnects, @code{0} means
34449that the trace run will stop.
34450
f5911ea1
HAQ
34451@item trace-file
34452The filename of the trace file being examined. This field is
34453optional, and only present when examining a trace file.
34454
18148017
VP
34455@end table
34456
7d13fe92
SS
34457@subsubheading @value{GDBN} Command
34458
34459The corresponding @value{GDBN} command is @samp{tstatus}.
34460
18148017
VP
34461@subheading -trace-stop
34462@findex -trace-stop
34463
34464@subsubheading Synopsis
34465
34466@smallexample
34467 -trace-stop
34468@end smallexample
922fbb7b 34469
18148017
VP
34470Stops a tracing experiment. The result of this command has the same
34471fields as @code{-trace-status}, except that the @samp{supported} and
34472@samp{running} fields are not output.
922fbb7b 34473
7d13fe92
SS
34474@subsubheading @value{GDBN} Command
34475
34476The corresponding @value{GDBN} command is @samp{tstop}.
34477
922fbb7b 34478
a2c02241
NR
34479@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34480@node GDB/MI Symbol Query
34481@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34482
34483
9901a55b 34484@ignore
a2c02241
NR
34485@subheading The @code{-symbol-info-address} Command
34486@findex -symbol-info-address
922fbb7b
AC
34487
34488@subsubheading Synopsis
34489
34490@smallexample
a2c02241 34491 -symbol-info-address @var{symbol}
922fbb7b
AC
34492@end smallexample
34493
a2c02241 34494Describe where @var{symbol} is stored.
922fbb7b
AC
34495
34496@subsubheading @value{GDBN} Command
34497
a2c02241 34498The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34499
34500@subsubheading Example
34501N.A.
34502
34503
a2c02241
NR
34504@subheading The @code{-symbol-info-file} Command
34505@findex -symbol-info-file
922fbb7b
AC
34506
34507@subsubheading Synopsis
34508
34509@smallexample
a2c02241 34510 -symbol-info-file
922fbb7b
AC
34511@end smallexample
34512
a2c02241 34513Show the file for the symbol.
922fbb7b 34514
a2c02241 34515@subsubheading @value{GDBN} Command
922fbb7b 34516
a2c02241
NR
34517There's no equivalent @value{GDBN} command. @code{gdbtk} has
34518@samp{gdb_find_file}.
922fbb7b
AC
34519
34520@subsubheading Example
34521N.A.
7dc42066
AB
34522@end ignore
34523
34524@subheading The @code{-symbol-info-functions} Command
34525@findex -symbol-info-functions
34526@anchor{-symbol-info-functions}
34527
34528@subsubheading Synopsis
34529
34530@smallexample
34531 -symbol-info-functions [--include-nondebug]
34532 [--type @var{type_regexp}]
34533 [--name @var{name_regexp}]
c2512106 34534 [--max-results @var{limit}]
7dc42066
AB
34535@end smallexample
34536
34537@noindent
34538Return a list containing the names and types for all global functions
34539taken from the debug information. The functions are grouped by source
34540file, and shown with the line number on which each function is
34541defined.
922fbb7b 34542
7dc42066
AB
34543The @code{--include-nondebug} option causes the output to include
34544code symbols from the symbol table.
922fbb7b 34545
7dc42066
AB
34546The options @code{--type} and @code{--name} allow the symbols returned
34547to be filtered based on either the name of the function, or the type
34548signature of the function.
34549
c2512106
AB
34550The option @code{--max-results} restricts the command to return no
34551more than @var{limit} results. If exactly @var{limit} results are
34552returned then there might be additional results available if a higher
34553limit is used.
34554
7dc42066
AB
34555@subsubheading @value{GDBN} Command
34556
34557The corresponding @value{GDBN} command is @samp{info functions}.
34558
34559@subsubheading Example
34560@smallexample
34561@group
34562(gdb)
34563-symbol-info-functions
34564^done,symbols=
34565 @{debug=
34566 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34567 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34568 symbols=[@{line="36", name="f4", type="void (int *)",
34569 description="void f4(int *);"@},
34570 @{line="42", name="main", type="int ()",
34571 description="int main();"@},
34572 @{line="30", name="f1", type="my_int_t (int, int)",
34573 description="static my_int_t f1(int, int);"@}]@},
34574 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34575 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34576 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34577 description="float f2(another_float_t);"@},
34578 @{line="39", name="f3", type="int (another_int_t)",
34579 description="int f3(another_int_t);"@},
34580 @{line="27", name="f1", type="another_float_t (int)",
34581 description="static another_float_t f1(int);"@}]@}]@}
34582@end group
34583@group
34584(gdb)
34585-symbol-info-functions --name f1
34586^done,symbols=
34587 @{debug=
34588 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34589 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34590 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34591 description="static my_int_t f1(int, int);"@}]@},
34592 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34593 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34594 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34595 description="static another_float_t f1(int);"@}]@}]@}
34596@end group
34597@group
34598(gdb)
34599-symbol-info-functions --type void
34600^done,symbols=
34601 @{debug=
34602 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34603 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34604 symbols=[@{line="36", name="f4", type="void (int *)",
34605 description="void f4(int *);"@}]@}]@}
34606@end group
34607@group
34608(gdb)
34609-symbol-info-functions --include-nondebug
34610^done,symbols=
34611 @{debug=
34612 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34613 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34614 symbols=[@{line="36", name="f4", type="void (int *)",
34615 description="void f4(int *);"@},
34616 @{line="42", name="main", type="int ()",
34617 description="int main();"@},
34618 @{line="30", name="f1", type="my_int_t (int, int)",
34619 description="static my_int_t f1(int, int);"@}]@},
34620 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34621 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34622 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34623 description="float f2(another_float_t);"@},
34624 @{line="39", name="f3", type="int (another_int_t)",
34625 description="int f3(another_int_t);"@},
34626 @{line="27", name="f1", type="another_float_t (int)",
34627 description="static another_float_t f1(int);"@}]@}],
34628 nondebug=
34629 [@{address="0x0000000000400398",name="_init"@},
34630 @{address="0x00000000004003b0",name="_start"@},
34631 ...
34632 ]@}
34633@end group
34634@end smallexample
34635
293b38d6
AB
34636@subheading The @code{-symbol-info-module-functions} Command
34637@findex -symbol-info-module-functions
34638@anchor{-symbol-info-module-functions}
34639
34640@subsubheading Synopsis
34641
34642@smallexample
34643 -symbol-info-module-functions [--module @var{module_regexp}]
34644 [--name @var{name_regexp}]
34645 [--type @var{type_regexp}]
34646@end smallexample
34647
34648@noindent
34649Return a list containing the names of all known functions within all
34650know Fortran modules. The functions are grouped by source file and
34651containing module, and shown with the line number on which each
34652function is defined.
34653
34654The option @code{--module} only returns results for modules matching
34655@var{module_regexp}. The option @code{--name} only returns functions
34656whose name matches @var{name_regexp}, and @code{--type} only returns
34657functions whose type matches @var{type_regexp}.
34658
34659@subsubheading @value{GDBN} Command
34660
34661The corresponding @value{GDBN} command is @samp{info module functions}.
34662
34663@subsubheading Example
34664
34665@smallexample
34666@group
34667(gdb)
34668-symbol-info-module-functions
34669^done,symbols=
34670 [@{module="mod1",
34671 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34672 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34673 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34674 description="void mod1::check_all(void);"@}]@}]@},
34675 @{module="mod2",
34676 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34677 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34678 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34679 description="void mod2::check_var_i(void);"@}]@}]@},
34680 @{module="mod3",
34681 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34682 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34683 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34684 description="void mod3::check_all(void);"@},
34685 @{line="27",name="mod3::check_mod2",type="void (void)",
34686 description="void mod3::check_mod2(void);"@}]@}]@},
34687 @{module="modmany",
34688 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34689 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34690 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34691 description="void modmany::check_some(void);"@}]@}]@},
34692 @{module="moduse",
34693 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34694 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34695 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34696 description="void moduse::check_all(void);"@},
34697 @{line="49",name="moduse::check_var_x",type="void (void)",
34698 description="void moduse::check_var_x(void);"@}]@}]@}]
34699@end group
34700@end smallexample
34701
34702@subheading The @code{-symbol-info-module-variables} Command
34703@findex -symbol-info-module-variables
34704@anchor{-symbol-info-module-variables}
34705
34706@subsubheading Synopsis
34707
34708@smallexample
34709 -symbol-info-module-variables [--module @var{module_regexp}]
34710 [--name @var{name_regexp}]
34711 [--type @var{type_regexp}]
34712@end smallexample
34713
34714@noindent
34715Return a list containing the names of all known variables within all
34716know Fortran modules. The variables are grouped by source file and
34717containing module, and shown with the line number on which each
34718variable is defined.
34719
34720The option @code{--module} only returns results for modules matching
34721@var{module_regexp}. The option @code{--name} only returns variables
34722whose name matches @var{name_regexp}, and @code{--type} only returns
34723variables whose type matches @var{type_regexp}.
34724
34725@subsubheading @value{GDBN} Command
34726
34727The corresponding @value{GDBN} command is @samp{info module variables}.
34728
34729@subsubheading Example
34730
34731@smallexample
34732@group
34733(gdb)
34734-symbol-info-module-variables
34735^done,symbols=
34736 [@{module="mod1",
34737 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34738 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34739 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34740 description="integer(kind=4) mod1::var_const;"@},
34741 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34742 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34743 @{module="mod2",
34744 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34745 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34746 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34747 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34748 @{module="mod3",
34749 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34750 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34751 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34752 description="integer(kind=4) mod3::mod1;"@},
34753 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34754 description="integer(kind=4) mod3::mod2;"@},
34755 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34756 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34757 @{module="modmany",
34758 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34759 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34760 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34761 description="integer(kind=4) modmany::var_a;"@},
34762 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34763 description="integer(kind=4) modmany::var_b;"@},
34764 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34765 description="integer(kind=4) modmany::var_c;"@},
34766 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34767 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34768 @{module="moduse",
34769 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34770 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34771 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34772 description="integer(kind=4) moduse::var_x;"@},
34773 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34774 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34775@end group
34776@end smallexample
34777
db5960b4
AB
34778@subheading The @code{-symbol-info-modules} Command
34779@findex -symbol-info-modules
34780@anchor{-symbol-info-modules}
34781
34782@subsubheading Synopsis
34783
34784@smallexample
34785 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34786 [--max-results @var{limit}]
34787
db5960b4
AB
34788@end smallexample
34789
34790@noindent
34791Return a list containing the names of all known Fortran modules. The
34792modules are grouped by source file, and shown with the line number on
34793which each modules is defined.
34794
34795The option @code{--name} allows the modules returned to be filtered
34796based the name of the module.
34797
c2512106
AB
34798The option @code{--max-results} restricts the command to return no
34799more than @var{limit} results. If exactly @var{limit} results are
34800returned then there might be additional results available if a higher
34801limit is used.
34802
db5960b4
AB
34803@subsubheading @value{GDBN} Command
34804
34805The corresponding @value{GDBN} command is @samp{info modules}.
34806
34807@subsubheading Example
34808@smallexample
34809@group
34810(gdb)
34811-symbol-info-modules
34812^done,symbols=
34813 @{debug=
34814 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34815 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34816 symbols=[@{line="16",name="mod1"@},
34817 @{line="22",name="mod2"@}]@},
34818 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34819 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34820 symbols=[@{line="16",name="mod3"@},
34821 @{line="22",name="modmany"@},
34822 @{line="26",name="moduse"@}]@}]@}
34823@end group
34824@group
34825(gdb)
34826-symbol-info-modules --name mod[123]
34827^done,symbols=
34828 @{debug=
34829 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34830 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34831 symbols=[@{line="16",name="mod1"@},
34832 @{line="22",name="mod2"@}]@},
34833 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34834 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34835 symbols=[@{line="16",name="mod3"@}]@}]@}
34836@end group
34837@end smallexample
34838
7dc42066
AB
34839@subheading The @code{-symbol-info-types} Command
34840@findex -symbol-info-types
34841@anchor{-symbol-info-types}
922fbb7b
AC
34842
34843@subsubheading Synopsis
34844
34845@smallexample
7dc42066 34846 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34847 [--max-results @var{limit}]
34848
922fbb7b
AC
34849@end smallexample
34850
7dc42066
AB
34851@noindent
34852Return a list of all defined types. The types are grouped by source
34853file, and shown with the line number on which each user defined type
34854is defined. Some base types are not defined in the source code but
34855are added to the debug information by the compiler, for example
34856@code{int}, @code{float}, etc.; these types do not have an associated
34857line number.
34858
34859The option @code{--name} allows the list of types returned to be
34860filtered by name.
922fbb7b 34861
c2512106
AB
34862The option @code{--max-results} restricts the command to return no
34863more than @var{limit} results. If exactly @var{limit} results are
34864returned then there might be additional results available if a higher
34865limit is used.
34866
922fbb7b
AC
34867@subsubheading @value{GDBN} Command
34868
7dc42066 34869The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34870
34871@subsubheading Example
7dc42066
AB
34872@smallexample
34873@group
34874(gdb)
34875-symbol-info-types
34876^done,symbols=
34877 @{debug=
34878 [@{filename="gdb.mi/mi-sym-info-1.c",
34879 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34880 symbols=[@{name="float"@},
34881 @{name="int"@},
34882 @{line="27",name="typedef int my_int_t;"@}]@},
34883 @{filename="gdb.mi/mi-sym-info-2.c",
34884 fullname="/project/gdb.mi/mi-sym-info-2.c",
34885 symbols=[@{line="24",name="typedef float another_float_t;"@},
34886 @{line="23",name="typedef int another_int_t;"@},
34887 @{name="float"@},
34888 @{name="int"@}]@}]@}
34889@end group
34890@group
34891(gdb)
34892-symbol-info-types --name _int_
34893^done,symbols=
34894 @{debug=
34895 [@{filename="gdb.mi/mi-sym-info-1.c",
34896 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34897 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34898 @{filename="gdb.mi/mi-sym-info-2.c",
34899 fullname="/project/gdb.mi/mi-sym-info-2.c",
34900 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34901@end group
34902@end smallexample
34903
34904@subheading The @code{-symbol-info-variables} Command
34905@findex -symbol-info-variables
34906@anchor{-symbol-info-variables}
34907
34908@subsubheading Synopsis
34909
34910@smallexample
34911 -symbol-info-variables [--include-nondebug]
34912 [--type @var{type_regexp}]
34913 [--name @var{name_regexp}]
c2512106
AB
34914 [--max-results @var{limit}]
34915
7dc42066
AB
34916@end smallexample
34917
34918@noindent
34919Return a list containing the names and types for all global variables
34920taken from the debug information. The variables are grouped by source
34921file, and shown with the line number on which each variable is
34922defined.
34923
34924The @code{--include-nondebug} option causes the output to include
34925data symbols from the symbol table.
34926
34927The options @code{--type} and @code{--name} allow the symbols returned
34928to be filtered based on either the name of the variable, or the type
34929of the variable.
34930
c2512106
AB
34931The option @code{--max-results} restricts the command to return no
34932more than @var{limit} results. If exactly @var{limit} results are
34933returned then there might be additional results available if a higher
34934limit is used.
34935
7dc42066 34936@subsubheading @value{GDBN} Command
922fbb7b 34937
7dc42066 34938The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34939
7dc42066
AB
34940@subsubheading Example
34941@smallexample
34942@group
34943(gdb)
34944-symbol-info-variables
34945^done,symbols=
34946 @{debug=
34947 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34948 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34949 symbols=[@{line="25",name="global_f1",type="float",
34950 description="static float global_f1;"@},
34951 @{line="24",name="global_i1",type="int",
34952 description="static int global_i1;"@}]@},
34953 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34954 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34955 symbols=[@{line="21",name="global_f2",type="int",
34956 description="int global_f2;"@},
34957 @{line="20",name="global_i2",type="int",
34958 description="int global_i2;"@},
34959 @{line="19",name="global_f1",type="float",
34960 description="static float global_f1;"@},
34961 @{line="18",name="global_i1",type="int",
34962 description="static int global_i1;"@}]@}]@}
34963@end group
34964@group
34965(gdb)
34966-symbol-info-variables --name f1
34967^done,symbols=
34968 @{debug=
34969 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34970 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34971 symbols=[@{line="25",name="global_f1",type="float",
34972 description="static float global_f1;"@}]@},
34973 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34974 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34975 symbols=[@{line="19",name="global_f1",type="float",
34976 description="static float global_f1;"@}]@}]@}
34977@end group
34978@group
34979(gdb)
34980-symbol-info-variables --type float
34981^done,symbols=
34982 @{debug=
34983 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34984 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34985 symbols=[@{line="25",name="global_f1",type="float",
34986 description="static float global_f1;"@}]@},
34987 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34988 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34989 symbols=[@{line="19",name="global_f1",type="float",
34990 description="static float global_f1;"@}]@}]@}
34991@end group
34992@group
34993(gdb)
34994-symbol-info-variables --include-nondebug
34995^done,symbols=
34996 @{debug=
34997 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34998 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34999 symbols=[@{line="25",name="global_f1",type="float",
35000 description="static float global_f1;"@},
35001 @{line="24",name="global_i1",type="int",
35002 description="static int global_i1;"@}]@},
35003 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35004 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35005 symbols=[@{line="21",name="global_f2",type="int",
35006 description="int global_f2;"@},
35007 @{line="20",name="global_i2",type="int",
35008 description="int global_i2;"@},
35009 @{line="19",name="global_f1",type="float",
35010 description="static float global_f1;"@},
35011 @{line="18",name="global_i1",type="int",
35012 description="static int global_i1;"@}]@}],
35013 nondebug=
35014 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35015 @{address="0x00000000004005d8",name="__dso_handle"@}
35016 ...
35017 ]@}
35018@end group
35019@end smallexample
35020
35021@ignore
a2c02241
NR
35022@subheading The @code{-symbol-info-line} Command
35023@findex -symbol-info-line
922fbb7b
AC
35024
35025@subsubheading Synopsis
35026
35027@smallexample
a2c02241 35028 -symbol-info-line
922fbb7b
AC
35029@end smallexample
35030
a2c02241 35031Show the core addresses of the code for a source line.
922fbb7b 35032
a2c02241 35033@subsubheading @value{GDBN} Command
922fbb7b 35034
a2c02241
NR
35035The corresponding @value{GDBN} command is @samp{info line}.
35036@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
35037
35038@subsubheading Example
a2c02241 35039N.A.
922fbb7b
AC
35040
35041
a2c02241
NR
35042@subheading The @code{-symbol-info-symbol} Command
35043@findex -symbol-info-symbol
07f31aa6
DJ
35044
35045@subsubheading Synopsis
35046
a2c02241
NR
35047@smallexample
35048 -symbol-info-symbol @var{addr}
35049@end smallexample
07f31aa6 35050
a2c02241 35051Describe what symbol is at location @var{addr}.
07f31aa6 35052
a2c02241 35053@subsubheading @value{GDBN} Command
07f31aa6 35054
a2c02241 35055The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
35056
35057@subsubheading Example
a2c02241 35058N.A.
07f31aa6
DJ
35059
35060
a2c02241
NR
35061@subheading The @code{-symbol-list-functions} Command
35062@findex -symbol-list-functions
922fbb7b
AC
35063
35064@subsubheading Synopsis
35065
35066@smallexample
a2c02241 35067 -symbol-list-functions
922fbb7b
AC
35068@end smallexample
35069
a2c02241 35070List the functions in the executable.
922fbb7b
AC
35071
35072@subsubheading @value{GDBN} Command
35073
a2c02241
NR
35074@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35075@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35076
35077@subsubheading Example
a2c02241 35078N.A.
9901a55b 35079@end ignore
922fbb7b
AC
35080
35081
a2c02241
NR
35082@subheading The @code{-symbol-list-lines} Command
35083@findex -symbol-list-lines
922fbb7b
AC
35084
35085@subsubheading Synopsis
35086
35087@smallexample
a2c02241 35088 -symbol-list-lines @var{filename}
922fbb7b
AC
35089@end smallexample
35090
a2c02241
NR
35091Print the list of lines that contain code and their associated program
35092addresses for the given source filename. The entries are sorted in
35093ascending PC order.
922fbb7b
AC
35094
35095@subsubheading @value{GDBN} Command
35096
a2c02241 35097There is no corresponding @value{GDBN} command.
922fbb7b
AC
35098
35099@subsubheading Example
a2c02241 35100@smallexample
594fe323 35101(gdb)
a2c02241
NR
35102-symbol-list-lines basics.c
35103^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 35104(gdb)
a2c02241 35105@end smallexample
922fbb7b
AC
35106
35107
9901a55b 35108@ignore
a2c02241
NR
35109@subheading The @code{-symbol-list-types} Command
35110@findex -symbol-list-types
922fbb7b
AC
35111
35112@subsubheading Synopsis
35113
35114@smallexample
a2c02241 35115 -symbol-list-types
922fbb7b
AC
35116@end smallexample
35117
a2c02241 35118List all the type names.
922fbb7b
AC
35119
35120@subsubheading @value{GDBN} Command
35121
a2c02241
NR
35122The corresponding commands are @samp{info types} in @value{GDBN},
35123@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35124
35125@subsubheading Example
35126N.A.
35127
35128
a2c02241
NR
35129@subheading The @code{-symbol-list-variables} Command
35130@findex -symbol-list-variables
922fbb7b
AC
35131
35132@subsubheading Synopsis
35133
35134@smallexample
a2c02241 35135 -symbol-list-variables
922fbb7b
AC
35136@end smallexample
35137
a2c02241 35138List all the global and static variable names.
922fbb7b
AC
35139
35140@subsubheading @value{GDBN} Command
35141
a2c02241 35142@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
35143
35144@subsubheading Example
35145N.A.
35146
35147
a2c02241
NR
35148@subheading The @code{-symbol-locate} Command
35149@findex -symbol-locate
922fbb7b
AC
35150
35151@subsubheading Synopsis
35152
35153@smallexample
a2c02241 35154 -symbol-locate
922fbb7b
AC
35155@end smallexample
35156
922fbb7b
AC
35157@subsubheading @value{GDBN} Command
35158
a2c02241 35159@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
35160
35161@subsubheading Example
35162N.A.
35163
35164
a2c02241
NR
35165@subheading The @code{-symbol-type} Command
35166@findex -symbol-type
922fbb7b
AC
35167
35168@subsubheading Synopsis
35169
35170@smallexample
a2c02241 35171 -symbol-type @var{variable}
922fbb7b
AC
35172@end smallexample
35173
a2c02241 35174Show type of @var{variable}.
922fbb7b 35175
a2c02241 35176@subsubheading @value{GDBN} Command
922fbb7b 35177
a2c02241
NR
35178The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35179@samp{gdb_obj_variable}.
35180
35181@subsubheading Example
35182N.A.
9901a55b 35183@end ignore
a2c02241
NR
35184
35185
35186@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35187@node GDB/MI File Commands
35188@section @sc{gdb/mi} File Commands
35189
35190This section describes the GDB/MI commands to specify executable file names
35191and to read in and obtain symbol table information.
35192
35193@subheading The @code{-file-exec-and-symbols} Command
35194@findex -file-exec-and-symbols
35195
35196@subsubheading Synopsis
922fbb7b
AC
35197
35198@smallexample
a2c02241 35199 -file-exec-and-symbols @var{file}
922fbb7b
AC
35200@end smallexample
35201
a2c02241
NR
35202Specify the executable file to be debugged. This file is the one from
35203which the symbol table is also read. If no file is specified, the
35204command clears the executable and symbol information. If breakpoints
35205are set when using this command with no arguments, @value{GDBN} will produce
35206error messages. Otherwise, no output is produced, except a completion
35207notification.
35208
922fbb7b
AC
35209@subsubheading @value{GDBN} Command
35210
a2c02241 35211The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
35212
35213@subsubheading Example
35214
35215@smallexample
594fe323 35216(gdb)
a2c02241
NR
35217-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35218^done
594fe323 35219(gdb)
922fbb7b
AC
35220@end smallexample
35221
922fbb7b 35222
a2c02241
NR
35223@subheading The @code{-file-exec-file} Command
35224@findex -file-exec-file
922fbb7b
AC
35225
35226@subsubheading Synopsis
35227
35228@smallexample
a2c02241 35229 -file-exec-file @var{file}
922fbb7b
AC
35230@end smallexample
35231
a2c02241
NR
35232Specify the executable file to be debugged. Unlike
35233@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35234from this file. If used without argument, @value{GDBN} clears the information
35235about the executable file. No output is produced, except a completion
35236notification.
922fbb7b 35237
a2c02241
NR
35238@subsubheading @value{GDBN} Command
35239
35240The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
35241
35242@subsubheading Example
a2c02241
NR
35243
35244@smallexample
594fe323 35245(gdb)
a2c02241
NR
35246-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35247^done
594fe323 35248(gdb)
a2c02241 35249@end smallexample
922fbb7b
AC
35250
35251
9901a55b 35252@ignore
a2c02241
NR
35253@subheading The @code{-file-list-exec-sections} Command
35254@findex -file-list-exec-sections
922fbb7b
AC
35255
35256@subsubheading Synopsis
35257
35258@smallexample
a2c02241 35259 -file-list-exec-sections
922fbb7b
AC
35260@end smallexample
35261
a2c02241
NR
35262List the sections of the current executable file.
35263
922fbb7b
AC
35264@subsubheading @value{GDBN} Command
35265
a2c02241
NR
35266The @value{GDBN} command @samp{info file} shows, among the rest, the same
35267information as this command. @code{gdbtk} has a corresponding command
35268@samp{gdb_load_info}.
922fbb7b
AC
35269
35270@subsubheading Example
35271N.A.
9901a55b 35272@end ignore
922fbb7b
AC
35273
35274
a2c02241
NR
35275@subheading The @code{-file-list-exec-source-file} Command
35276@findex -file-list-exec-source-file
922fbb7b
AC
35277
35278@subsubheading Synopsis
35279
35280@smallexample
a2c02241 35281 -file-list-exec-source-file
922fbb7b
AC
35282@end smallexample
35283
a2c02241 35284List the line number, the current source file, and the absolute path
44288b44
NR
35285to the current source file for the current executable. The macro
35286information field has a value of @samp{1} or @samp{0} depending on
35287whether or not the file includes preprocessor macro information.
922fbb7b
AC
35288
35289@subsubheading @value{GDBN} Command
35290
a2c02241 35291The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
35292
35293@subsubheading Example
35294
922fbb7b 35295@smallexample
594fe323 35296(gdb)
a2c02241 35297123-file-list-exec-source-file
44288b44 35298123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 35299(gdb)
922fbb7b
AC
35300@end smallexample
35301
35302
a2c02241
NR
35303@subheading The @code{-file-list-exec-source-files} Command
35304@findex -file-list-exec-source-files
922fbb7b
AC
35305
35306@subsubheading Synopsis
35307
35308@smallexample
a2c02241 35309 -file-list-exec-source-files
922fbb7b
AC
35310@end smallexample
35311
a2c02241
NR
35312List the source files for the current executable.
35313
f35a17b5
JK
35314It will always output both the filename and fullname (absolute file
35315name) of a source file.
922fbb7b
AC
35316
35317@subsubheading @value{GDBN} Command
35318
a2c02241
NR
35319The @value{GDBN} equivalent is @samp{info sources}.
35320@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
35321
35322@subsubheading Example
922fbb7b 35323@smallexample
594fe323 35324(gdb)
a2c02241
NR
35325-file-list-exec-source-files
35326^done,files=[
35327@{file=foo.c,fullname=/home/foo.c@},
35328@{file=/home/bar.c,fullname=/home/bar.c@},
35329@{file=gdb_could_not_find_fullpath.c@}]
594fe323 35330(gdb)
922fbb7b
AC
35331@end smallexample
35332
a2c02241
NR
35333@subheading The @code{-file-list-shared-libraries} Command
35334@findex -file-list-shared-libraries
922fbb7b 35335
a2c02241 35336@subsubheading Synopsis
922fbb7b 35337
a2c02241 35338@smallexample
51457a05 35339 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 35340@end smallexample
922fbb7b 35341
a2c02241 35342List the shared libraries in the program.
51457a05
MAL
35343With a regular expression @var{regexp}, only those libraries whose
35344names match @var{regexp} are listed.
922fbb7b 35345
a2c02241 35346@subsubheading @value{GDBN} Command
922fbb7b 35347
51457a05
MAL
35348The corresponding @value{GDBN} command is @samp{info shared}. The fields
35349have a similar meaning to the @code{=library-loaded} notification.
35350The @code{ranges} field specifies the multiple segments belonging to this
35351library. Each range has the following fields:
35352
35353@table @samp
35354@item from
35355The address defining the inclusive lower bound of the segment.
35356@item to
35357The address defining the exclusive upper bound of the segment.
35358@end table
922fbb7b 35359
a2c02241 35360@subsubheading Example
51457a05
MAL
35361@smallexample
35362(gdb)
35363-file-list-exec-source-files
35364^done,shared-libraries=[
35365@{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"@}]@},
35366@{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"@}]@}]
35367(gdb)
35368@end smallexample
922fbb7b
AC
35369
35370
51457a05 35371@ignore
a2c02241
NR
35372@subheading The @code{-file-list-symbol-files} Command
35373@findex -file-list-symbol-files
922fbb7b 35374
a2c02241 35375@subsubheading Synopsis
922fbb7b 35376
a2c02241
NR
35377@smallexample
35378 -file-list-symbol-files
35379@end smallexample
922fbb7b 35380
a2c02241 35381List symbol files.
922fbb7b 35382
a2c02241 35383@subsubheading @value{GDBN} Command
922fbb7b 35384
a2c02241 35385The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 35386
a2c02241
NR
35387@subsubheading Example
35388N.A.
9901a55b 35389@end ignore
922fbb7b 35390
922fbb7b 35391
a2c02241
NR
35392@subheading The @code{-file-symbol-file} Command
35393@findex -file-symbol-file
922fbb7b 35394
a2c02241 35395@subsubheading Synopsis
922fbb7b 35396
a2c02241
NR
35397@smallexample
35398 -file-symbol-file @var{file}
35399@end smallexample
922fbb7b 35400
a2c02241
NR
35401Read symbol table info from the specified @var{file} argument. When
35402used without arguments, clears @value{GDBN}'s symbol table info. No output is
35403produced, except for a completion notification.
922fbb7b 35404
a2c02241 35405@subsubheading @value{GDBN} Command
922fbb7b 35406
a2c02241 35407The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 35408
a2c02241 35409@subsubheading Example
922fbb7b 35410
a2c02241 35411@smallexample
594fe323 35412(gdb)
a2c02241
NR
35413-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35414^done
594fe323 35415(gdb)
a2c02241 35416@end smallexample
922fbb7b 35417
a2c02241 35418@ignore
a2c02241
NR
35419@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35420@node GDB/MI Memory Overlay Commands
35421@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 35422
a2c02241 35423The memory overlay commands are not implemented.
922fbb7b 35424
a2c02241 35425@c @subheading -overlay-auto
922fbb7b 35426
a2c02241 35427@c @subheading -overlay-list-mapping-state
922fbb7b 35428
a2c02241 35429@c @subheading -overlay-list-overlays
922fbb7b 35430
a2c02241 35431@c @subheading -overlay-map
922fbb7b 35432
a2c02241 35433@c @subheading -overlay-off
922fbb7b 35434
a2c02241 35435@c @subheading -overlay-on
922fbb7b 35436
a2c02241 35437@c @subheading -overlay-unmap
922fbb7b 35438
a2c02241
NR
35439@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35440@node GDB/MI Signal Handling Commands
35441@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 35442
a2c02241 35443Signal handling commands are not implemented.
922fbb7b 35444
a2c02241 35445@c @subheading -signal-handle
922fbb7b 35446
a2c02241 35447@c @subheading -signal-list-handle-actions
922fbb7b 35448
a2c02241
NR
35449@c @subheading -signal-list-signal-types
35450@end ignore
922fbb7b 35451
922fbb7b 35452
a2c02241
NR
35453@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35454@node GDB/MI Target Manipulation
35455@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
35456
35457
a2c02241
NR
35458@subheading The @code{-target-attach} Command
35459@findex -target-attach
922fbb7b
AC
35460
35461@subsubheading Synopsis
35462
35463@smallexample
c3b108f7 35464 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
35465@end smallexample
35466
c3b108f7
VP
35467Attach to a process @var{pid} or a file @var{file} outside of
35468@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35469group, the id previously returned by
35470@samp{-list-thread-groups --available} must be used.
922fbb7b 35471
79a6e687 35472@subsubheading @value{GDBN} Command
922fbb7b 35473
a2c02241 35474The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 35475
a2c02241 35476@subsubheading Example
b56e7235
VP
35477@smallexample
35478(gdb)
35479-target-attach 34
35480=thread-created,id="1"
5ae4183a 35481*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35482^done
35483(gdb)
35484@end smallexample
a2c02241 35485
9901a55b 35486@ignore
a2c02241
NR
35487@subheading The @code{-target-compare-sections} Command
35488@findex -target-compare-sections
922fbb7b
AC
35489
35490@subsubheading Synopsis
35491
35492@smallexample
a2c02241 35493 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35494@end smallexample
35495
a2c02241
NR
35496Compare data of section @var{section} on target to the exec file.
35497Without the argument, all sections are compared.
922fbb7b 35498
a2c02241 35499@subsubheading @value{GDBN} Command
922fbb7b 35500
a2c02241 35501The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35502
a2c02241
NR
35503@subsubheading Example
35504N.A.
9901a55b 35505@end ignore
a2c02241
NR
35506
35507
35508@subheading The @code{-target-detach} Command
35509@findex -target-detach
922fbb7b
AC
35510
35511@subsubheading Synopsis
35512
35513@smallexample
c3b108f7 35514 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35515@end smallexample
35516
a2c02241 35517Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35518If either @var{pid} or @var{gid} is specified, detaches from either
35519the specified process, or specified thread group. There's no output.
a2c02241 35520
79a6e687 35521@subsubheading @value{GDBN} Command
a2c02241
NR
35522
35523The corresponding @value{GDBN} command is @samp{detach}.
35524
35525@subsubheading Example
922fbb7b
AC
35526
35527@smallexample
594fe323 35528(gdb)
a2c02241
NR
35529-target-detach
35530^done
594fe323 35531(gdb)
922fbb7b
AC
35532@end smallexample
35533
35534
a2c02241
NR
35535@subheading The @code{-target-disconnect} Command
35536@findex -target-disconnect
922fbb7b
AC
35537
35538@subsubheading Synopsis
35539
123dc839 35540@smallexample
a2c02241 35541 -target-disconnect
123dc839 35542@end smallexample
922fbb7b 35543
a2c02241
NR
35544Disconnect from the remote target. There's no output and the target is
35545generally not resumed.
35546
79a6e687 35547@subsubheading @value{GDBN} Command
a2c02241
NR
35548
35549The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35550
35551@subsubheading Example
922fbb7b
AC
35552
35553@smallexample
594fe323 35554(gdb)
a2c02241
NR
35555-target-disconnect
35556^done
594fe323 35557(gdb)
922fbb7b
AC
35558@end smallexample
35559
35560
a2c02241
NR
35561@subheading The @code{-target-download} Command
35562@findex -target-download
922fbb7b
AC
35563
35564@subsubheading Synopsis
35565
35566@smallexample
a2c02241 35567 -target-download
922fbb7b
AC
35568@end smallexample
35569
a2c02241
NR
35570Loads the executable onto the remote target.
35571It prints out an update message every half second, which includes the fields:
35572
35573@table @samp
35574@item section
35575The name of the section.
35576@item section-sent
35577The size of what has been sent so far for that section.
35578@item section-size
35579The size of the section.
35580@item total-sent
35581The total size of what was sent so far (the current and the previous sections).
35582@item total-size
35583The size of the overall executable to download.
35584@end table
35585
35586@noindent
35587Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35588@sc{gdb/mi} Output Syntax}).
35589
35590In addition, it prints the name and size of the sections, as they are
35591downloaded. These messages include the following fields:
35592
35593@table @samp
35594@item section
35595The name of the section.
35596@item section-size
35597The size of the section.
35598@item total-size
35599The size of the overall executable to download.
35600@end table
35601
35602@noindent
35603At the end, a summary is printed.
35604
35605@subsubheading @value{GDBN} Command
35606
35607The corresponding @value{GDBN} command is @samp{load}.
35608
35609@subsubheading Example
35610
35611Note: each status message appears on a single line. Here the messages
35612have been broken down so that they can fit onto a page.
922fbb7b
AC
35613
35614@smallexample
594fe323 35615(gdb)
a2c02241
NR
35616-target-download
35617+download,@{section=".text",section-size="6668",total-size="9880"@}
35618+download,@{section=".text",section-sent="512",section-size="6668",
35619total-sent="512",total-size="9880"@}
35620+download,@{section=".text",section-sent="1024",section-size="6668",
35621total-sent="1024",total-size="9880"@}
35622+download,@{section=".text",section-sent="1536",section-size="6668",
35623total-sent="1536",total-size="9880"@}
35624+download,@{section=".text",section-sent="2048",section-size="6668",
35625total-sent="2048",total-size="9880"@}
35626+download,@{section=".text",section-sent="2560",section-size="6668",
35627total-sent="2560",total-size="9880"@}
35628+download,@{section=".text",section-sent="3072",section-size="6668",
35629total-sent="3072",total-size="9880"@}
35630+download,@{section=".text",section-sent="3584",section-size="6668",
35631total-sent="3584",total-size="9880"@}
35632+download,@{section=".text",section-sent="4096",section-size="6668",
35633total-sent="4096",total-size="9880"@}
35634+download,@{section=".text",section-sent="4608",section-size="6668",
35635total-sent="4608",total-size="9880"@}
35636+download,@{section=".text",section-sent="5120",section-size="6668",
35637total-sent="5120",total-size="9880"@}
35638+download,@{section=".text",section-sent="5632",section-size="6668",
35639total-sent="5632",total-size="9880"@}
35640+download,@{section=".text",section-sent="6144",section-size="6668",
35641total-sent="6144",total-size="9880"@}
35642+download,@{section=".text",section-sent="6656",section-size="6668",
35643total-sent="6656",total-size="9880"@}
35644+download,@{section=".init",section-size="28",total-size="9880"@}
35645+download,@{section=".fini",section-size="28",total-size="9880"@}
35646+download,@{section=".data",section-size="3156",total-size="9880"@}
35647+download,@{section=".data",section-sent="512",section-size="3156",
35648total-sent="7236",total-size="9880"@}
35649+download,@{section=".data",section-sent="1024",section-size="3156",
35650total-sent="7748",total-size="9880"@}
35651+download,@{section=".data",section-sent="1536",section-size="3156",
35652total-sent="8260",total-size="9880"@}
35653+download,@{section=".data",section-sent="2048",section-size="3156",
35654total-sent="8772",total-size="9880"@}
35655+download,@{section=".data",section-sent="2560",section-size="3156",
35656total-sent="9284",total-size="9880"@}
35657+download,@{section=".data",section-sent="3072",section-size="3156",
35658total-sent="9796",total-size="9880"@}
35659^done,address="0x10004",load-size="9880",transfer-rate="6586",
35660write-rate="429"
594fe323 35661(gdb)
922fbb7b
AC
35662@end smallexample
35663
35664
9901a55b 35665@ignore
a2c02241
NR
35666@subheading The @code{-target-exec-status} Command
35667@findex -target-exec-status
922fbb7b
AC
35668
35669@subsubheading Synopsis
35670
35671@smallexample
a2c02241 35672 -target-exec-status
922fbb7b
AC
35673@end smallexample
35674
a2c02241
NR
35675Provide information on the state of the target (whether it is running or
35676not, for instance).
922fbb7b 35677
a2c02241 35678@subsubheading @value{GDBN} Command
922fbb7b 35679
a2c02241
NR
35680There's no equivalent @value{GDBN} command.
35681
35682@subsubheading Example
35683N.A.
922fbb7b 35684
a2c02241
NR
35685
35686@subheading The @code{-target-list-available-targets} Command
35687@findex -target-list-available-targets
922fbb7b
AC
35688
35689@subsubheading Synopsis
35690
35691@smallexample
a2c02241 35692 -target-list-available-targets
922fbb7b
AC
35693@end smallexample
35694
a2c02241 35695List the possible targets to connect to.
922fbb7b 35696
a2c02241 35697@subsubheading @value{GDBN} Command
922fbb7b 35698
a2c02241 35699The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35700
a2c02241
NR
35701@subsubheading Example
35702N.A.
35703
35704
35705@subheading The @code{-target-list-current-targets} Command
35706@findex -target-list-current-targets
922fbb7b
AC
35707
35708@subsubheading Synopsis
35709
35710@smallexample
a2c02241 35711 -target-list-current-targets
922fbb7b
AC
35712@end smallexample
35713
a2c02241 35714Describe the current target.
922fbb7b 35715
a2c02241 35716@subsubheading @value{GDBN} Command
922fbb7b 35717
a2c02241
NR
35718The corresponding information is printed by @samp{info file} (among
35719other things).
922fbb7b 35720
a2c02241
NR
35721@subsubheading Example
35722N.A.
35723
35724
35725@subheading The @code{-target-list-parameters} Command
35726@findex -target-list-parameters
922fbb7b
AC
35727
35728@subsubheading Synopsis
35729
35730@smallexample
a2c02241 35731 -target-list-parameters
922fbb7b
AC
35732@end smallexample
35733
a2c02241 35734@c ????
9901a55b 35735@end ignore
a2c02241
NR
35736
35737@subsubheading @value{GDBN} Command
35738
35739No equivalent.
922fbb7b
AC
35740
35741@subsubheading Example
a2c02241
NR
35742N.A.
35743
78cbbba8
LM
35744@subheading The @code{-target-flash-erase} Command
35745@findex -target-flash-erase
35746
35747@subsubheading Synopsis
35748
35749@smallexample
35750 -target-flash-erase
35751@end smallexample
35752
35753Erases all known flash memory regions on the target.
35754
35755The corresponding @value{GDBN} command is @samp{flash-erase}.
35756
35757The output is a list of flash regions that have been erased, with starting
35758addresses and memory region sizes.
35759
35760@smallexample
35761(gdb)
35762-target-flash-erase
35763^done,erased-regions=@{address="0x0",size="0x40000"@}
35764(gdb)
35765@end smallexample
a2c02241
NR
35766
35767@subheading The @code{-target-select} Command
35768@findex -target-select
35769
35770@subsubheading Synopsis
922fbb7b
AC
35771
35772@smallexample
a2c02241 35773 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35774@end smallexample
35775
a2c02241 35776Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35777
a2c02241
NR
35778@table @samp
35779@item @var{type}
75c99385 35780The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35781@item @var{parameters}
35782Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35783Commands for Managing Targets}, for more details.
a2c02241
NR
35784@end table
35785
35786The output is a connection notification, followed by the address at
35787which the target program is, in the following form:
922fbb7b
AC
35788
35789@smallexample
a2c02241
NR
35790^connected,addr="@var{address}",func="@var{function name}",
35791 args=[@var{arg list}]
922fbb7b
AC
35792@end smallexample
35793
a2c02241
NR
35794@subsubheading @value{GDBN} Command
35795
35796The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35797
35798@subsubheading Example
922fbb7b 35799
265eeb58 35800@smallexample
594fe323 35801(gdb)
75c99385 35802-target-select remote /dev/ttya
a2c02241 35803^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35804(gdb)
265eeb58 35805@end smallexample
ef21caaf 35806
a6b151f1
DJ
35807@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35808@node GDB/MI File Transfer Commands
35809@section @sc{gdb/mi} File Transfer Commands
35810
35811
35812@subheading The @code{-target-file-put} Command
35813@findex -target-file-put
35814
35815@subsubheading Synopsis
35816
35817@smallexample
35818 -target-file-put @var{hostfile} @var{targetfile}
35819@end smallexample
35820
35821Copy file @var{hostfile} from the host system (the machine running
35822@value{GDBN}) to @var{targetfile} on the target system.
35823
35824@subsubheading @value{GDBN} Command
35825
35826The corresponding @value{GDBN} command is @samp{remote put}.
35827
35828@subsubheading Example
35829
35830@smallexample
35831(gdb)
35832-target-file-put localfile remotefile
35833^done
35834(gdb)
35835@end smallexample
35836
35837
1763a388 35838@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35839@findex -target-file-get
35840
35841@subsubheading Synopsis
35842
35843@smallexample
35844 -target-file-get @var{targetfile} @var{hostfile}
35845@end smallexample
35846
35847Copy file @var{targetfile} from the target system to @var{hostfile}
35848on the host system.
35849
35850@subsubheading @value{GDBN} Command
35851
35852The corresponding @value{GDBN} command is @samp{remote get}.
35853
35854@subsubheading Example
35855
35856@smallexample
35857(gdb)
35858-target-file-get remotefile localfile
35859^done
35860(gdb)
35861@end smallexample
35862
35863
35864@subheading The @code{-target-file-delete} Command
35865@findex -target-file-delete
35866
35867@subsubheading Synopsis
35868
35869@smallexample
35870 -target-file-delete @var{targetfile}
35871@end smallexample
35872
35873Delete @var{targetfile} from the target system.
35874
35875@subsubheading @value{GDBN} Command
35876
35877The corresponding @value{GDBN} command is @samp{remote delete}.
35878
35879@subsubheading Example
35880
35881@smallexample
35882(gdb)
35883-target-file-delete remotefile
35884^done
35885(gdb)
35886@end smallexample
35887
35888
58d06528
JB
35889@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35890@node GDB/MI Ada Exceptions Commands
35891@section Ada Exceptions @sc{gdb/mi} Commands
35892
35893@subheading The @code{-info-ada-exceptions} Command
35894@findex -info-ada-exceptions
35895
35896@subsubheading Synopsis
35897
35898@smallexample
35899 -info-ada-exceptions [ @var{regexp}]
35900@end smallexample
35901
35902List all Ada exceptions defined within the program being debugged.
35903With a regular expression @var{regexp}, only those exceptions whose
35904names match @var{regexp} are listed.
35905
35906@subsubheading @value{GDBN} Command
35907
35908The corresponding @value{GDBN} command is @samp{info exceptions}.
35909
35910@subsubheading Result
35911
35912The result is a table of Ada exceptions. The following columns are
35913defined for each exception:
35914
35915@table @samp
35916@item name
35917The name of the exception.
35918
35919@item address
35920The address of the exception.
35921
35922@end table
35923
35924@subsubheading Example
35925
35926@smallexample
35927-info-ada-exceptions aint
35928^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35929hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35930@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35931body=[@{name="constraint_error",address="0x0000000000613da0"@},
35932@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35933@end smallexample
35934
35935@subheading Catching Ada Exceptions
35936
35937The commands describing how to ask @value{GDBN} to stop when a program
35938raises an exception are described at @ref{Ada Exception GDB/MI
35939Catchpoint Commands}.
35940
35941
ef21caaf 35942@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35943@node GDB/MI Support Commands
35944@section @sc{gdb/mi} Support Commands
ef21caaf 35945
d192b373
JB
35946Since new commands and features get regularly added to @sc{gdb/mi},
35947some commands are available to help front-ends query the debugger
35948about support for these capabilities. Similarly, it is also possible
35949to query @value{GDBN} about target support of certain features.
ef21caaf 35950
6b7cbff1
JB
35951@subheading The @code{-info-gdb-mi-command} Command
35952@cindex @code{-info-gdb-mi-command}
35953@findex -info-gdb-mi-command
35954
35955@subsubheading Synopsis
35956
35957@smallexample
35958 -info-gdb-mi-command @var{cmd_name}
35959@end smallexample
35960
35961Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35962
35963Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35964is technically not part of the command name (@pxref{GDB/MI Input
35965Syntax}), and thus should be omitted in @var{cmd_name}. However,
35966for ease of use, this command also accepts the form with the leading
35967dash.
35968
35969@subsubheading @value{GDBN} Command
35970
35971There is no corresponding @value{GDBN} command.
35972
35973@subsubheading Result
35974
35975The result is a tuple. There is currently only one field:
35976
35977@table @samp
35978@item exists
35979This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35980@code{"false"} otherwise.
35981
35982@end table
35983
35984@subsubheading Example
35985
35986Here is an example where the @sc{gdb/mi} command does not exist:
35987
35988@smallexample
35989-info-gdb-mi-command unsupported-command
35990^done,command=@{exists="false"@}
35991@end smallexample
35992
35993@noindent
35994And here is an example where the @sc{gdb/mi} command is known
35995to the debugger:
35996
35997@smallexample
35998-info-gdb-mi-command symbol-list-lines
35999^done,command=@{exists="true"@}
36000@end smallexample
36001
084344da
VP
36002@subheading The @code{-list-features} Command
36003@findex -list-features
9b26f0fb 36004@cindex supported @sc{gdb/mi} features, list
084344da
VP
36005
36006Returns a list of particular features of the MI protocol that
36007this version of gdb implements. A feature can be a command,
36008or a new field in an output of some command, or even an
36009important bugfix. While a frontend can sometimes detect presence
36010of a feature at runtime, it is easier to perform detection at debugger
d192b373 36011startup.
084344da
VP
36012
36013The command returns a list of strings, with each string naming an
36014available feature. Each returned string is just a name, it does not
d192b373 36015have any internal structure. The list of possible feature names
084344da
VP
36016is given below.
36017
36018Example output:
36019
36020@smallexample
36021(gdb) -list-features
36022^done,result=["feature1","feature2"]
36023@end smallexample
36024
36025The current list of features is:
36026
edef6000 36027@ftable @samp
30e026bb 36028@item frozen-varobjs
a05336a1 36029Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 36030as possible presence of the @code{frozen} field in the output
30e026bb
VP
36031of @code{-varobj-create}.
36032@item pending-breakpoints
a05336a1
JB
36033Indicates support for the @option{-f} option to the @code{-break-insert}
36034command.
b6313243 36035@item python
a05336a1 36036Indicates Python scripting support, Python-based
b6313243
TT
36037pretty-printing commands, and possible presence of the
36038@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 36039@item thread-info
a05336a1 36040Indicates support for the @code{-thread-info} command.
8dedea02 36041@item data-read-memory-bytes
a05336a1 36042Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 36043@code{-data-write-memory-bytes} commands.
39c4d40a
TT
36044@item breakpoint-notifications
36045Indicates that changes to breakpoints and breakpoints created via the
36046CLI will be announced via async records.
5d77fe44 36047@item ada-task-info
6adcee18 36048Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
36049@item language-option
36050Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36051option (@pxref{Context management}).
6b7cbff1
JB
36052@item info-gdb-mi-command
36053Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
36054@item undefined-command-error-code
36055Indicates support for the "undefined-command" error code in error result
36056records, produced when trying to execute an undefined @sc{gdb/mi} command
36057(@pxref{GDB/MI Result Records}).
72bfa06c
JB
36058@item exec-run-start-option
36059Indicates that the @code{-exec-run} command supports the @option{--start}
36060option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
36061@item data-disassemble-a-option
36062Indicates that the @code{-data-disassemble} command supports the @option{-a}
36063option (@pxref{GDB/MI Data Manipulation}).
edef6000 36064@end ftable
084344da 36065
c6ebd6cf
VP
36066@subheading The @code{-list-target-features} Command
36067@findex -list-target-features
36068
36069Returns a list of particular features that are supported by the
36070target. Those features affect the permitted MI commands, but
36071unlike the features reported by the @code{-list-features} command, the
36072features depend on which target GDB is using at the moment. Whenever
36073a target can change, due to commands such as @code{-target-select},
36074@code{-target-attach} or @code{-exec-run}, the list of target features
36075may change, and the frontend should obtain it again.
36076Example output:
36077
36078@smallexample
b3d3b4bd 36079(gdb) -list-target-features
c6ebd6cf
VP
36080^done,result=["async"]
36081@end smallexample
36082
36083The current list of features is:
36084
36085@table @samp
36086@item async
36087Indicates that the target is capable of asynchronous command
36088execution, which means that @value{GDBN} will accept further commands
36089while the target is running.
36090
f75d858b
MK
36091@item reverse
36092Indicates that the target is capable of reverse execution.
36093@xref{Reverse Execution}, for more information.
36094
c6ebd6cf
VP
36095@end table
36096
d192b373
JB
36097@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36098@node GDB/MI Miscellaneous Commands
36099@section Miscellaneous @sc{gdb/mi} Commands
36100
36101@c @subheading -gdb-complete
36102
36103@subheading The @code{-gdb-exit} Command
36104@findex -gdb-exit
36105
36106@subsubheading Synopsis
36107
36108@smallexample
36109 -gdb-exit
36110@end smallexample
36111
36112Exit @value{GDBN} immediately.
36113
36114@subsubheading @value{GDBN} Command
36115
36116Approximately corresponds to @samp{quit}.
36117
36118@subsubheading Example
36119
36120@smallexample
36121(gdb)
36122-gdb-exit
36123^exit
36124@end smallexample
36125
36126
36127@ignore
36128@subheading The @code{-exec-abort} Command
36129@findex -exec-abort
36130
36131@subsubheading Synopsis
36132
36133@smallexample
36134 -exec-abort
36135@end smallexample
36136
36137Kill the inferior running program.
36138
36139@subsubheading @value{GDBN} Command
36140
36141The corresponding @value{GDBN} command is @samp{kill}.
36142
36143@subsubheading Example
36144N.A.
36145@end ignore
36146
36147
36148@subheading The @code{-gdb-set} Command
36149@findex -gdb-set
36150
36151@subsubheading Synopsis
36152
36153@smallexample
36154 -gdb-set
36155@end smallexample
36156
36157Set an internal @value{GDBN} variable.
36158@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36159
36160@subsubheading @value{GDBN} Command
36161
36162The corresponding @value{GDBN} command is @samp{set}.
36163
36164@subsubheading Example
36165
36166@smallexample
36167(gdb)
36168-gdb-set $foo=3
36169^done
36170(gdb)
36171@end smallexample
36172
36173
36174@subheading The @code{-gdb-show} Command
36175@findex -gdb-show
36176
36177@subsubheading Synopsis
36178
36179@smallexample
36180 -gdb-show
36181@end smallexample
36182
36183Show the current value of a @value{GDBN} variable.
36184
36185@subsubheading @value{GDBN} Command
36186
36187The corresponding @value{GDBN} command is @samp{show}.
36188
36189@subsubheading Example
36190
36191@smallexample
36192(gdb)
36193-gdb-show annotate
36194^done,value="0"
36195(gdb)
36196@end smallexample
36197
36198@c @subheading -gdb-source
36199
36200
36201@subheading The @code{-gdb-version} Command
36202@findex -gdb-version
36203
36204@subsubheading Synopsis
36205
36206@smallexample
36207 -gdb-version
36208@end smallexample
36209
36210Show version information for @value{GDBN}. Used mostly in testing.
36211
36212@subsubheading @value{GDBN} Command
36213
36214The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36215default shows this information when you start an interactive session.
36216
36217@subsubheading Example
36218
36219@c This example modifies the actual output from GDB to avoid overfull
36220@c box in TeX.
36221@smallexample
36222(gdb)
36223-gdb-version
36224~GNU gdb 5.2.1
36225~Copyright 2000 Free Software Foundation, Inc.
36226~GDB is free software, covered by the GNU General Public License, and
36227~you are welcome to change it and/or distribute copies of it under
36228~ certain conditions.
36229~Type "show copying" to see the conditions.
36230~There is absolutely no warranty for GDB. Type "show warranty" for
36231~ details.
36232~This GDB was configured as
36233 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36234^done
36235(gdb)
36236@end smallexample
36237
c3b108f7
VP
36238@subheading The @code{-list-thread-groups} Command
36239@findex -list-thread-groups
36240
36241@subheading Synopsis
36242
36243@smallexample
dc146f7c 36244-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
36245@end smallexample
36246
dc146f7c
VP
36247Lists thread groups (@pxref{Thread groups}). When a single thread
36248group is passed as the argument, lists the children of that group.
36249When several thread group are passed, lists information about those
36250thread groups. Without any parameters, lists information about all
36251top-level thread groups.
36252
36253Normally, thread groups that are being debugged are reported.
36254With the @samp{--available} option, @value{GDBN} reports thread groups
36255available on the target.
36256
36257The output of this command may have either a @samp{threads} result or
36258a @samp{groups} result. The @samp{thread} result has a list of tuples
36259as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36260Information}). The @samp{groups} result has a list of tuples as value,
36261each tuple describing a thread group. If top-level groups are
36262requested (that is, no parameter is passed), or when several groups
36263are passed, the output always has a @samp{groups} result. The format
36264of the @samp{group} result is described below.
36265
36266To reduce the number of roundtrips it's possible to list thread groups
36267together with their children, by passing the @samp{--recurse} option
36268and the recursion depth. Presently, only recursion depth of 1 is
36269permitted. If this option is present, then every reported thread group
36270will also include its children, either as @samp{group} or
36271@samp{threads} field.
36272
36273In general, any combination of option and parameters is permitted, with
36274the following caveats:
36275
36276@itemize @bullet
36277@item
36278When a single thread group is passed, the output will typically
36279be the @samp{threads} result. Because threads may not contain
36280anything, the @samp{recurse} option will be ignored.
36281
36282@item
36283When the @samp{--available} option is passed, limited information may
36284be available. In particular, the list of threads of a process might
36285be inaccessible. Further, specifying specific thread groups might
36286not give any performance advantage over listing all thread groups.
36287The frontend should assume that @samp{-list-thread-groups --available}
36288is always an expensive operation and cache the results.
36289
36290@end itemize
36291
36292The @samp{groups} result is a list of tuples, where each tuple may
36293have the following fields:
36294
36295@table @code
36296@item id
36297Identifier of the thread group. This field is always present.
a79b8f6e
VP
36298The identifier is an opaque string; frontends should not try to
36299convert it to an integer, even though it might look like one.
dc146f7c
VP
36300
36301@item type
36302The type of the thread group. At present, only @samp{process} is a
36303valid type.
36304
36305@item pid
36306The target-specific process identifier. This field is only present
a79b8f6e 36307for thread groups of type @samp{process} and only if the process exists.
c3b108f7 36308
2ddf4301
SM
36309@item exit-code
36310The exit code of this group's last exited thread, formatted in octal.
36311This field is only present for thread groups of type @samp{process} and
36312only if the process is not running.
36313
dc146f7c
VP
36314@item num_children
36315The number of children this thread group has. This field may be
36316absent for an available thread group.
36317
36318@item threads
36319This field has a list of tuples as value, each tuple describing a
36320thread. It may be present if the @samp{--recurse} option is
36321specified, and it's actually possible to obtain the threads.
36322
36323@item cores
36324This field is a list of integers, each identifying a core that one
36325thread of the group is running on. This field may be absent if
36326such information is not available.
36327
a79b8f6e
VP
36328@item executable
36329The name of the executable file that corresponds to this thread group.
36330The field is only present for thread groups of type @samp{process},
36331and only if there is a corresponding executable file.
36332
dc146f7c 36333@end table
c3b108f7
VP
36334
36335@subheading Example
36336
36337@smallexample
36338@value{GDBP}
36339-list-thread-groups
36340^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36341-list-thread-groups 17
36342^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36343 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36344@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36345 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 36346 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
36347-list-thread-groups --available
36348^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36349-list-thread-groups --available --recurse 1
36350 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36351 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36352 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36353-list-thread-groups --available --recurse 1 17 18
36354^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36355 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36356 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 36357@end smallexample
c6ebd6cf 36358
f3e0e960
SS
36359@subheading The @code{-info-os} Command
36360@findex -info-os
36361
36362@subsubheading Synopsis
36363
36364@smallexample
36365-info-os [ @var{type} ]
36366@end smallexample
36367
36368If no argument is supplied, the command returns a table of available
36369operating-system-specific information types. If one of these types is
36370supplied as an argument @var{type}, then the command returns a table
36371of data of that type.
36372
36373The types of information available depend on the target operating
36374system.
36375
36376@subsubheading @value{GDBN} Command
36377
36378The corresponding @value{GDBN} command is @samp{info os}.
36379
36380@subsubheading Example
36381
36382When run on a @sc{gnu}/Linux system, the output will look something
36383like this:
36384
36385@smallexample
36386@value{GDBP}
36387-info-os
d33279b3 36388^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 36389hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
36390 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36391 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
36392body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36393 col2="CPUs"@},
36394 item=@{col0="files",col1="Listing of all file descriptors",
36395 col2="File descriptors"@},
36396 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36397 col2="Kernel modules"@},
36398 item=@{col0="msg",col1="Listing of all message queues",
36399 col2="Message queues"@},
36400 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
36401 col2="Processes"@},
36402 item=@{col0="procgroups",col1="Listing of all process groups",
36403 col2="Process groups"@},
71caed83
SS
36404 item=@{col0="semaphores",col1="Listing of all semaphores",
36405 col2="Semaphores"@},
d33279b3
AT
36406 item=@{col0="shm",col1="Listing of all shared-memory regions",
36407 col2="Shared-memory regions"@},
36408 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36409 col2="Sockets"@},
36410 item=@{col0="threads",col1="Listing of all threads",
36411 col2="Threads"@}]
f3e0e960
SS
36412@value{GDBP}
36413-info-os processes
36414^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36415hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36416 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36417 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36418 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36419body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36420 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36421 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36422 ...
36423 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36424 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36425(gdb)
36426@end smallexample
a79b8f6e 36427
71caed83
SS
36428(Note that the MI output here includes a @code{"Title"} column that
36429does not appear in command-line @code{info os}; this column is useful
36430for MI clients that want to enumerate the types of data, such as in a
36431popup menu, but is needless clutter on the command line, and
36432@code{info os} omits it.)
36433
a79b8f6e
VP
36434@subheading The @code{-add-inferior} Command
36435@findex -add-inferior
36436
36437@subheading Synopsis
36438
36439@smallexample
36440-add-inferior
36441@end smallexample
36442
65c574f6 36443Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
36444inferior is not associated with any executable. Such association may
36445be established with the @samp{-file-exec-and-symbols} command
36446(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 36447field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
36448thread group corresponding to the new inferior.
36449
36450@subheading Example
36451
36452@smallexample
36453@value{GDBP}
36454-add-inferior
b7742092 36455^done,inferior="i3"
a79b8f6e
VP
36456@end smallexample
36457
ef21caaf
NR
36458@subheading The @code{-interpreter-exec} Command
36459@findex -interpreter-exec
36460
36461@subheading Synopsis
36462
36463@smallexample
36464-interpreter-exec @var{interpreter} @var{command}
36465@end smallexample
a2c02241 36466@anchor{-interpreter-exec}
ef21caaf
NR
36467
36468Execute the specified @var{command} in the given @var{interpreter}.
36469
36470@subheading @value{GDBN} Command
36471
36472The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36473
36474@subheading Example
36475
36476@smallexample
594fe323 36477(gdb)
ef21caaf
NR
36478-interpreter-exec console "break main"
36479&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36480&"During symbol reading, bad structure-type format.\n"
36481~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36482^done
594fe323 36483(gdb)
ef21caaf
NR
36484@end smallexample
36485
36486@subheading The @code{-inferior-tty-set} Command
36487@findex -inferior-tty-set
36488
36489@subheading Synopsis
36490
36491@smallexample
36492-inferior-tty-set /dev/pts/1
36493@end smallexample
36494
36495Set terminal for future runs of the program being debugged.
36496
36497@subheading @value{GDBN} Command
36498
36499The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36500
36501@subheading Example
36502
36503@smallexample
594fe323 36504(gdb)
ef21caaf
NR
36505-inferior-tty-set /dev/pts/1
36506^done
594fe323 36507(gdb)
ef21caaf
NR
36508@end smallexample
36509
36510@subheading The @code{-inferior-tty-show} Command
36511@findex -inferior-tty-show
36512
36513@subheading Synopsis
36514
36515@smallexample
36516-inferior-tty-show
36517@end smallexample
36518
36519Show terminal for future runs of program being debugged.
36520
36521@subheading @value{GDBN} Command
36522
36523The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36524
36525@subheading Example
36526
36527@smallexample
594fe323 36528(gdb)
ef21caaf
NR
36529-inferior-tty-set /dev/pts/1
36530^done
594fe323 36531(gdb)
ef21caaf
NR
36532-inferior-tty-show
36533^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36534(gdb)
ef21caaf 36535@end smallexample
922fbb7b 36536
a4eefcd8
NR
36537@subheading The @code{-enable-timings} Command
36538@findex -enable-timings
36539
36540@subheading Synopsis
36541
36542@smallexample
36543-enable-timings [yes | no]
36544@end smallexample
36545
36546Toggle the printing of the wallclock, user and system times for an MI
36547command as a field in its output. This command is to help frontend
36548developers optimize the performance of their code. No argument is
36549equivalent to @samp{yes}.
36550
36551@subheading @value{GDBN} Command
36552
36553No equivalent.
36554
36555@subheading Example
36556
36557@smallexample
36558(gdb)
36559-enable-timings
36560^done
36561(gdb)
36562-break-insert main
36563^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36564addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36565fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36566times="0"@},
a4eefcd8
NR
36567time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36568(gdb)
36569-enable-timings no
36570^done
36571(gdb)
36572-exec-run
36573^running
36574(gdb)
a47ec5fe 36575*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36576frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36577@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36578fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36579(gdb)
36580@end smallexample
36581
26648588
JV
36582@subheading The @code{-complete} Command
36583@findex -complete
36584
36585@subheading Synopsis
36586
36587@smallexample
36588-complete @var{command}
36589@end smallexample
36590
36591Show a list of completions for partially typed CLI @var{command}.
36592
36593This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36594CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36595because @value{GDBN} is used remotely via a SSH connection.
36596
36597@subheading Result
36598
36599The result consists of two or three fields:
36600
36601@table @samp
36602@item completion
36603This field contains the completed @var{command}. If @var{command}
36604has no known completions, this field is omitted.
36605
36606@item matches
36607This field contains a (possibly empty) array of matches. It is always present.
36608
36609@item max_completions_reached
36610This field contains @code{1} if number of known completions is above
7166f90a 36611@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36612@code{0}. It is always present.
36613
36614@end table
36615
36616@subheading @value{GDBN} Command
36617
36618The corresponding @value{GDBN} command is @samp{complete}.
36619
36620@subheading Example
36621
36622@smallexample
36623(gdb)
36624-complete br
36625^done,completion="break",
36626 matches=["break","break-range"],
36627 max_completions_reached="0"
36628(gdb)
36629-complete "b ma"
36630^done,completion="b ma",
36631 matches=["b madvise","b main"],max_completions_reached="0"
36632(gdb)
36633-complete "b push_b"
36634^done,completion="b push_back(",
36635 matches=[
36636 "b A::push_back(void*)",
36637 "b std::string::push_back(char)",
36638 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36639 max_completions_reached="0"
36640(gdb)
36641-complete "nonexist"
36642^done,matches=[],max_completions_reached="0"
36643(gdb)
36644
36645@end smallexample
36646
922fbb7b
AC
36647@node Annotations
36648@chapter @value{GDBN} Annotations
36649
086432e2
AC
36650This chapter describes annotations in @value{GDBN}. Annotations were
36651designed to interface @value{GDBN} to graphical user interfaces or other
36652similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36653relatively high level.
36654
d3e8051b 36655The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36656(@pxref{GDB/MI}).
36657
922fbb7b
AC
36658@ignore
36659This is Edition @value{EDITION}, @value{DATE}.
36660@end ignore
36661
36662@menu
36663* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36664* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36665* Prompting:: Annotations marking @value{GDBN}'s need for input.
36666* Errors:: Annotations for error messages.
922fbb7b
AC
36667* Invalidation:: Some annotations describe things now invalid.
36668* Annotations for Running::
36669 Whether the program is running, how it stopped, etc.
36670* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36671@end menu
36672
36673@node Annotations Overview
36674@section What is an Annotation?
36675@cindex annotations
36676
922fbb7b
AC
36677Annotations start with a newline character, two @samp{control-z}
36678characters, and the name of the annotation. If there is no additional
36679information associated with this annotation, the name of the annotation
36680is followed immediately by a newline. If there is additional
36681information, the name of the annotation is followed by a space, the
36682additional information, and a newline. The additional information
36683cannot contain newline characters.
36684
36685Any output not beginning with a newline and two @samp{control-z}
36686characters denotes literal output from @value{GDBN}. Currently there is
36687no need for @value{GDBN} to output a newline followed by two
36688@samp{control-z} characters, but if there was such a need, the
36689annotations could be extended with an @samp{escape} annotation which
36690means those three characters as output.
36691
086432e2
AC
36692The annotation @var{level}, which is specified using the
36693@option{--annotate} command line option (@pxref{Mode Options}), controls
36694how much information @value{GDBN} prints together with its prompt,
36695values of expressions, source lines, and other types of output. Level 0
d3e8051b 36696is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36697subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36698for programs that control @value{GDBN}, and level 2 annotations have
36699been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36700Interface, annotate, GDB's Obsolete Annotations}).
36701
36702@table @code
36703@kindex set annotate
36704@item set annotate @var{level}
e09f16f9 36705The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36706annotations to the specified @var{level}.
9c16f35a
EZ
36707
36708@item show annotate
36709@kindex show annotate
36710Show the current annotation level.
09d4efe1
EZ
36711@end table
36712
36713This chapter describes level 3 annotations.
086432e2 36714
922fbb7b
AC
36715A simple example of starting up @value{GDBN} with annotations is:
36716
36717@smallexample
086432e2
AC
36718$ @kbd{gdb --annotate=3}
36719GNU gdb 6.0
36720Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36721GDB is free software, covered by the GNU General Public License,
36722and you are welcome to change it and/or distribute copies of it
36723under certain conditions.
36724Type "show copying" to see the conditions.
36725There is absolutely no warranty for GDB. Type "show warranty"
36726for details.
086432e2 36727This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36728
36729^Z^Zpre-prompt
f7dc1244 36730(@value{GDBP})
922fbb7b 36731^Z^Zprompt
086432e2 36732@kbd{quit}
922fbb7b
AC
36733
36734^Z^Zpost-prompt
b383017d 36735$
922fbb7b
AC
36736@end smallexample
36737
36738Here @samp{quit} is input to @value{GDBN}; the rest is output from
36739@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36740denotes a @samp{control-z} character) are annotations; the rest is
36741output from @value{GDBN}.
36742
9e6c4bd5
NR
36743@node Server Prefix
36744@section The Server Prefix
36745@cindex server prefix
36746
36747If you prefix a command with @samp{server } then it will not affect
36748the command history, nor will it affect @value{GDBN}'s notion of which
36749command to repeat if @key{RET} is pressed on a line by itself. This
36750means that commands can be run behind a user's back by a front-end in
36751a transparent manner.
36752
d837706a
NR
36753The @code{server } prefix does not affect the recording of values into
36754the value history; to print a value without recording it into the
36755value history, use the @code{output} command instead of the
36756@code{print} command.
36757
36758Using this prefix also disables confirmation requests
36759(@pxref{confirmation requests}).
9e6c4bd5 36760
922fbb7b
AC
36761@node Prompting
36762@section Annotation for @value{GDBN} Input
36763
36764@cindex annotations for prompts
36765When @value{GDBN} prompts for input, it annotates this fact so it is possible
36766to know when to send output, when the output from a given command is
36767over, etc.
36768
36769Different kinds of input each have a different @dfn{input type}. Each
36770input type has three annotations: a @code{pre-} annotation, which
36771denotes the beginning of any prompt which is being output, a plain
36772annotation, which denotes the end of the prompt, and then a @code{post-}
36773annotation which denotes the end of any echo which may (or may not) be
36774associated with the input. For example, the @code{prompt} input type
36775features the following annotations:
36776
36777@smallexample
36778^Z^Zpre-prompt
36779^Z^Zprompt
36780^Z^Zpost-prompt
36781@end smallexample
36782
36783The input types are
36784
36785@table @code
e5ac9b53
EZ
36786@findex pre-prompt annotation
36787@findex prompt annotation
36788@findex post-prompt annotation
922fbb7b
AC
36789@item prompt
36790When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36791
e5ac9b53
EZ
36792@findex pre-commands annotation
36793@findex commands annotation
36794@findex post-commands annotation
922fbb7b
AC
36795@item commands
36796When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36797command. The annotations are repeated for each command which is input.
36798
e5ac9b53
EZ
36799@findex pre-overload-choice annotation
36800@findex overload-choice annotation
36801@findex post-overload-choice annotation
922fbb7b
AC
36802@item overload-choice
36803When @value{GDBN} wants the user to select between various overloaded functions.
36804
e5ac9b53
EZ
36805@findex pre-query annotation
36806@findex query annotation
36807@findex post-query annotation
922fbb7b
AC
36808@item query
36809When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36810
e5ac9b53
EZ
36811@findex pre-prompt-for-continue annotation
36812@findex prompt-for-continue annotation
36813@findex post-prompt-for-continue annotation
922fbb7b
AC
36814@item prompt-for-continue
36815When @value{GDBN} is asking the user to press return to continue. Note: Don't
36816expect this to work well; instead use @code{set height 0} to disable
36817prompting. This is because the counting of lines is buggy in the
36818presence of annotations.
36819@end table
36820
36821@node Errors
36822@section Errors
36823@cindex annotations for errors, warnings and interrupts
36824
e5ac9b53 36825@findex quit annotation
922fbb7b
AC
36826@smallexample
36827^Z^Zquit
36828@end smallexample
36829
36830This annotation occurs right before @value{GDBN} responds to an interrupt.
36831
e5ac9b53 36832@findex error annotation
922fbb7b
AC
36833@smallexample
36834^Z^Zerror
36835@end smallexample
36836
36837This annotation occurs right before @value{GDBN} responds to an error.
36838
36839Quit and error annotations indicate that any annotations which @value{GDBN} was
36840in the middle of may end abruptly. For example, if a
36841@code{value-history-begin} annotation is followed by a @code{error}, one
36842cannot expect to receive the matching @code{value-history-end}. One
36843cannot expect not to receive it either, however; an error annotation
36844does not necessarily mean that @value{GDBN} is immediately returning all the way
36845to the top level.
36846
e5ac9b53 36847@findex error-begin annotation
922fbb7b
AC
36848A quit or error annotation may be preceded by
36849
36850@smallexample
36851^Z^Zerror-begin
36852@end smallexample
36853
36854Any output between that and the quit or error annotation is the error
36855message.
36856
36857Warning messages are not yet annotated.
36858@c If we want to change that, need to fix warning(), type_error(),
36859@c range_error(), and possibly other places.
36860
922fbb7b
AC
36861@node Invalidation
36862@section Invalidation Notices
36863
36864@cindex annotations for invalidation messages
36865The following annotations say that certain pieces of state may have
36866changed.
36867
36868@table @code
e5ac9b53 36869@findex frames-invalid annotation
922fbb7b
AC
36870@item ^Z^Zframes-invalid
36871
36872The frames (for example, output from the @code{backtrace} command) may
36873have changed.
36874
e5ac9b53 36875@findex breakpoints-invalid annotation
922fbb7b
AC
36876@item ^Z^Zbreakpoints-invalid
36877
36878The breakpoints may have changed. For example, the user just added or
36879deleted a breakpoint.
36880@end table
36881
36882@node Annotations for Running
36883@section Running the Program
36884@cindex annotations for running programs
36885
e5ac9b53
EZ
36886@findex starting annotation
36887@findex stopping annotation
922fbb7b 36888When the program starts executing due to a @value{GDBN} command such as
b383017d 36889@code{step} or @code{continue},
922fbb7b
AC
36890
36891@smallexample
36892^Z^Zstarting
36893@end smallexample
36894
b383017d 36895is output. When the program stops,
922fbb7b
AC
36896
36897@smallexample
36898^Z^Zstopped
36899@end smallexample
36900
36901is output. Before the @code{stopped} annotation, a variety of
36902annotations describe how the program stopped.
36903
36904@table @code
e5ac9b53 36905@findex exited annotation
922fbb7b
AC
36906@item ^Z^Zexited @var{exit-status}
36907The program exited, and @var{exit-status} is the exit status (zero for
36908successful exit, otherwise nonzero).
36909
e5ac9b53
EZ
36910@findex signalled annotation
36911@findex signal-name annotation
36912@findex signal-name-end annotation
36913@findex signal-string annotation
36914@findex signal-string-end annotation
922fbb7b
AC
36915@item ^Z^Zsignalled
36916The program exited with a signal. After the @code{^Z^Zsignalled}, the
36917annotation continues:
36918
36919@smallexample
36920@var{intro-text}
36921^Z^Zsignal-name
36922@var{name}
36923^Z^Zsignal-name-end
36924@var{middle-text}
36925^Z^Zsignal-string
36926@var{string}
36927^Z^Zsignal-string-end
36928@var{end-text}
36929@end smallexample
36930
36931@noindent
36932where @var{name} is the name of the signal, such as @code{SIGILL} or
36933@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36934as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36935@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36936user's benefit and have no particular format.
36937
e5ac9b53 36938@findex signal annotation
922fbb7b
AC
36939@item ^Z^Zsignal
36940The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36941just saying that the program received the signal, not that it was
36942terminated with it.
36943
e5ac9b53 36944@findex breakpoint annotation
922fbb7b
AC
36945@item ^Z^Zbreakpoint @var{number}
36946The program hit breakpoint number @var{number}.
36947
e5ac9b53 36948@findex watchpoint annotation
922fbb7b
AC
36949@item ^Z^Zwatchpoint @var{number}
36950The program hit watchpoint number @var{number}.
36951@end table
36952
36953@node Source Annotations
36954@section Displaying Source
36955@cindex annotations for source display
36956
e5ac9b53 36957@findex source annotation
922fbb7b
AC
36958The following annotation is used instead of displaying source code:
36959
36960@smallexample
36961^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36962@end smallexample
36963
36964where @var{filename} is an absolute file name indicating which source
36965file, @var{line} is the line number within that file (where 1 is the
36966first line in the file), @var{character} is the character position
36967within the file (where 0 is the first character in the file) (for most
36968debug formats this will necessarily point to the beginning of a line),
36969@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36970line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36971@var{addr} is the address in the target program associated with the
697aa1b7 36972source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
36973followed by one or more lowercase hex digits (note that this does not
36974depend on the language).
36975
4efc6507
DE
36976@node JIT Interface
36977@chapter JIT Compilation Interface
36978@cindex just-in-time compilation
36979@cindex JIT compilation interface
36980
36981This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36982interface. A JIT compiler is a program or library that generates native
36983executable code at runtime and executes it, usually in order to achieve good
36984performance while maintaining platform independence.
36985
36986Programs that use JIT compilation are normally difficult to debug because
36987portions of their code are generated at runtime, instead of being loaded from
36988object files, which is where @value{GDBN} normally finds the program's symbols
36989and debug information. In order to debug programs that use JIT compilation,
36990@value{GDBN} has an interface that allows the program to register in-memory
36991symbol files with @value{GDBN} at runtime.
36992
36993If you are using @value{GDBN} to debug a program that uses this interface, then
36994it should work transparently so long as you have not stripped the binary. If
36995you are developing a JIT compiler, then the interface is documented in the rest
36996of this chapter. At this time, the only known client of this interface is the
36997LLVM JIT.
36998
36999Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37000JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 37001variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
37002attaches, it reads a linked list of symbol files from the global variable to
37003find existing code, and puts a breakpoint in the function so that it can find
37004out about additional code.
37005
37006@menu
37007* Declarations:: Relevant C struct declarations
37008* Registering Code:: Steps to register code
37009* Unregistering Code:: Steps to unregister code
f85b53f8 37010* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
37011@end menu
37012
37013@node Declarations
37014@section JIT Declarations
37015
37016These are the relevant struct declarations that a C program should include to
37017implement the interface:
37018
37019@smallexample
37020typedef enum
37021@{
37022 JIT_NOACTION = 0,
37023 JIT_REGISTER_FN,
37024 JIT_UNREGISTER_FN
37025@} jit_actions_t;
37026
37027struct jit_code_entry
37028@{
37029 struct jit_code_entry *next_entry;
37030 struct jit_code_entry *prev_entry;
37031 const char *symfile_addr;
37032 uint64_t symfile_size;
37033@};
37034
37035struct jit_descriptor
37036@{
37037 uint32_t version;
37038 /* This type should be jit_actions_t, but we use uint32_t
37039 to be explicit about the bitwidth. */
37040 uint32_t action_flag;
37041 struct jit_code_entry *relevant_entry;
37042 struct jit_code_entry *first_entry;
37043@};
37044
37045/* GDB puts a breakpoint in this function. */
37046void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37047
37048/* Make sure to specify the version statically, because the
37049 debugger may check the version before we can set it. */
37050struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37051@end smallexample
37052
37053If the JIT is multi-threaded, then it is important that the JIT synchronize any
37054modifications to this global data properly, which can easily be done by putting
37055a global mutex around modifications to these structures.
37056
37057@node Registering Code
37058@section Registering Code
37059
37060To register code with @value{GDBN}, the JIT should follow this protocol:
37061
37062@itemize @bullet
37063@item
37064Generate an object file in memory with symbols and other desired debug
37065information. The file must include the virtual addresses of the sections.
37066
37067@item
37068Create a code entry for the file, which gives the start and size of the symbol
37069file.
37070
37071@item
37072Add it to the linked list in the JIT descriptor.
37073
37074@item
37075Point the relevant_entry field of the descriptor at the entry.
37076
37077@item
37078Set @code{action_flag} to @code{JIT_REGISTER} and call
37079@code{__jit_debug_register_code}.
37080@end itemize
37081
37082When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37083@code{relevant_entry} pointer so it doesn't have to walk the list looking for
37084new code. However, the linked list must still be maintained in order to allow
37085@value{GDBN} to attach to a running process and still find the symbol files.
37086
37087@node Unregistering Code
37088@section Unregistering Code
37089
37090If code is freed, then the JIT should use the following protocol:
37091
37092@itemize @bullet
37093@item
37094Remove the code entry corresponding to the code from the linked list.
37095
37096@item
37097Point the @code{relevant_entry} field of the descriptor at the code entry.
37098
37099@item
37100Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37101@code{__jit_debug_register_code}.
37102@end itemize
37103
37104If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37105and the JIT will leak the memory used for the associated symbol files.
37106
f85b53f8
SD
37107@node Custom Debug Info
37108@section Custom Debug Info
37109@cindex custom JIT debug info
37110@cindex JIT debug info reader
37111
37112Generating debug information in platform-native file formats (like ELF
37113or COFF) may be an overkill for JIT compilers; especially if all the
37114debug info is used for is displaying a meaningful backtrace. The
37115issue can be resolved by having the JIT writers decide on a debug info
37116format and also provide a reader that parses the debug info generated
37117by the JIT compiler. This section gives a brief overview on writing
37118such a parser. More specific details can be found in the source file
37119@file{gdb/jit-reader.in}, which is also installed as a header at
37120@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37121
37122The reader is implemented as a shared object (so this functionality is
37123not available on platforms which don't allow loading shared objects at
37124runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37125@code{jit-reader-unload} are provided, to be used to load and unload
37126the readers from a preconfigured directory. Once loaded, the shared
37127object is used the parse the debug information emitted by the JIT
37128compiler.
37129
37130@menu
37131* Using JIT Debug Info Readers:: How to use supplied readers correctly
37132* Writing JIT Debug Info Readers:: Creating a debug-info reader
37133@end menu
37134
37135@node Using JIT Debug Info Readers
37136@subsection Using JIT Debug Info Readers
37137@kindex jit-reader-load
37138@kindex jit-reader-unload
37139
37140Readers can be loaded and unloaded using the @code{jit-reader-load}
37141and @code{jit-reader-unload} commands.
37142
37143@table @code
c9fb1240 37144@item jit-reader-load @var{reader}
697aa1b7 37145Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
37146object specified as either an absolute or a relative file name. In
37147the latter case, @value{GDBN} will try to load the reader from a
37148pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37149system (here @var{libdir} is the system library directory, often
37150@file{/usr/local/lib}).
37151
37152Only one reader can be active at a time; trying to load a second
37153reader when one is already loaded will result in @value{GDBN}
37154reporting an error. A new JIT reader can be loaded by first unloading
37155the current one using @code{jit-reader-unload} and then invoking
37156@code{jit-reader-load}.
f85b53f8
SD
37157
37158@item jit-reader-unload
37159Unload the currently loaded JIT reader.
37160
37161@end table
37162
37163@node Writing JIT Debug Info Readers
37164@subsection Writing JIT Debug Info Readers
37165@cindex writing JIT debug info readers
37166
37167As mentioned, a reader is essentially a shared object conforming to a
37168certain ABI. This ABI is described in @file{jit-reader.h}.
37169
37170@file{jit-reader.h} defines the structures, macros and functions
37171required to write a reader. It is installed (along with
37172@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37173the system include directory.
37174
37175Readers need to be released under a GPL compatible license. A reader
37176can be declared as released under such a license by placing the macro
37177@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37178
37179The entry point for readers is the symbol @code{gdb_init_reader},
37180which is expected to be a function with the prototype
37181
37182@findex gdb_init_reader
37183@smallexample
37184extern struct gdb_reader_funcs *gdb_init_reader (void);
37185@end smallexample
37186
37187@cindex @code{struct gdb_reader_funcs}
37188
37189@code{struct gdb_reader_funcs} contains a set of pointers to callback
37190functions. These functions are executed to read the debug info
37191generated by the JIT compiler (@code{read}), to unwind stack frames
37192(@code{unwind}) and to create canonical frame IDs
27f7b2f6 37193(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
37194reader is being unloaded (@code{destroy}). The struct looks like this
37195
37196@smallexample
37197struct gdb_reader_funcs
37198@{
37199 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37200 int reader_version;
37201
37202 /* For use by the reader. */
37203 void *priv_data;
37204
37205 gdb_read_debug_info *read;
37206 gdb_unwind_frame *unwind;
37207 gdb_get_frame_id *get_frame_id;
37208 gdb_destroy_reader *destroy;
37209@};
37210@end smallexample
37211
37212@cindex @code{struct gdb_symbol_callbacks}
37213@cindex @code{struct gdb_unwind_callbacks}
37214
37215The callbacks are provided with another set of callbacks by
37216@value{GDBN} to do their job. For @code{read}, these callbacks are
37217passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37218and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37219@code{struct gdb_symbol_callbacks} has callbacks to create new object
37220files and new symbol tables inside those object files. @code{struct
37221gdb_unwind_callbacks} has callbacks to read registers off the current
37222frame and to write out the values of the registers in the previous
37223frame. Both have a callback (@code{target_read}) to read bytes off the
37224target's address space.
37225
d1feda86
YQ
37226@node In-Process Agent
37227@chapter In-Process Agent
37228@cindex debugging agent
37229The traditional debugging model is conceptually low-speed, but works fine,
37230because most bugs can be reproduced in debugging-mode execution. However,
37231as multi-core or many-core processors are becoming mainstream, and
37232multi-threaded programs become more and more popular, there should be more
37233and more bugs that only manifest themselves at normal-mode execution, for
37234example, thread races, because debugger's interference with the program's
37235timing may conceal the bugs. On the other hand, in some applications,
37236it is not feasible for the debugger to interrupt the program's execution
37237long enough for the developer to learn anything helpful about its behavior.
37238If the program's correctness depends on its real-time behavior, delays
37239introduced by a debugger might cause the program to fail, even when the
37240code itself is correct. It is useful to be able to observe the program's
37241behavior without interrupting it.
37242
37243Therefore, traditional debugging model is too intrusive to reproduce
37244some bugs. In order to reduce the interference with the program, we can
37245reduce the number of operations performed by debugger. The
37246@dfn{In-Process Agent}, a shared library, is running within the same
37247process with inferior, and is able to perform some debugging operations
37248itself. As a result, debugger is only involved when necessary, and
37249performance of debugging can be improved accordingly. Note that
37250interference with program can be reduced but can't be removed completely,
37251because the in-process agent will still stop or slow down the program.
37252
37253The in-process agent can interpret and execute Agent Expressions
37254(@pxref{Agent Expressions}) during performing debugging operations. The
37255agent expressions can be used for different purposes, such as collecting
37256data in tracepoints, and condition evaluation in breakpoints.
37257
37258@anchor{Control Agent}
37259You can control whether the in-process agent is used as an aid for
37260debugging with the following commands:
37261
37262@table @code
37263@kindex set agent on
37264@item set agent on
37265Causes the in-process agent to perform some operations on behalf of the
37266debugger. Just which operations requested by the user will be done
37267by the in-process agent depends on the its capabilities. For example,
37268if you request to evaluate breakpoint conditions in the in-process agent,
37269and the in-process agent has such capability as well, then breakpoint
37270conditions will be evaluated in the in-process agent.
37271
37272@kindex set agent off
37273@item set agent off
37274Disables execution of debugging operations by the in-process agent. All
37275of the operations will be performed by @value{GDBN}.
37276
37277@kindex show agent
37278@item show agent
37279Display the current setting of execution of debugging operations by
37280the in-process agent.
37281@end table
37282
16bdd41f
YQ
37283@menu
37284* In-Process Agent Protocol::
37285@end menu
37286
37287@node In-Process Agent Protocol
37288@section In-Process Agent Protocol
37289@cindex in-process agent protocol
37290
37291The in-process agent is able to communicate with both @value{GDBN} and
37292GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37293used for communications between @value{GDBN} or GDBserver and the IPA.
37294In general, @value{GDBN} or GDBserver sends commands
37295(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37296in-process agent replies back with the return result of the command, or
37297some other information. The data sent to in-process agent is composed
37298of primitive data types, such as 4-byte or 8-byte type, and composite
37299types, which are called objects (@pxref{IPA Protocol Objects}).
37300
37301@menu
37302* IPA Protocol Objects::
37303* IPA Protocol Commands::
37304@end menu
37305
37306@node IPA Protocol Objects
37307@subsection IPA Protocol Objects
37308@cindex ipa protocol objects
37309
37310The commands sent to and results received from agent may contain some
37311complex data types called @dfn{objects}.
37312
37313The in-process agent is running on the same machine with @value{GDBN}
37314or GDBserver, so it doesn't have to handle as much differences between
37315two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37316However, there are still some differences of two ends in two processes:
37317
37318@enumerate
37319@item
37320word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37321compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37322@item
37323ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37324GDBserver is compiled with one, and in-process agent is compiled with
37325the other one.
37326@end enumerate
37327
37328Here are the IPA Protocol Objects:
37329
37330@enumerate
37331@item
37332agent expression object. It represents an agent expression
37333(@pxref{Agent Expressions}).
37334@anchor{agent expression object}
37335@item
37336tracepoint action object. It represents a tracepoint action
37337(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37338memory, static trace data and to evaluate expression.
37339@anchor{tracepoint action object}
37340@item
37341tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37342@anchor{tracepoint object}
37343
37344@end enumerate
37345
37346The following table describes important attributes of each IPA protocol
37347object:
37348
37349@multitable @columnfractions .30 .20 .50
37350@headitem Name @tab Size @tab Description
37351@item @emph{agent expression object} @tab @tab
37352@item length @tab 4 @tab length of bytes code
37353@item byte code @tab @var{length} @tab contents of byte code
37354@item @emph{tracepoint action for collecting memory} @tab @tab
37355@item 'M' @tab 1 @tab type of tracepoint action
37356@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37357address of the lowest byte to collect, otherwise @var{addr} is the offset
37358of @var{basereg} for memory collecting.
37359@item len @tab 8 @tab length of memory for collecting
37360@item basereg @tab 4 @tab the register number containing the starting
37361memory address for collecting.
37362@item @emph{tracepoint action for collecting registers} @tab @tab
37363@item 'R' @tab 1 @tab type of tracepoint action
37364@item @emph{tracepoint action for collecting static trace data} @tab @tab
37365@item 'L' @tab 1 @tab type of tracepoint action
37366@item @emph{tracepoint action for expression evaluation} @tab @tab
37367@item 'X' @tab 1 @tab type of tracepoint action
37368@item agent expression @tab length of @tab @ref{agent expression object}
37369@item @emph{tracepoint object} @tab @tab
37370@item number @tab 4 @tab number of tracepoint
37371@item address @tab 8 @tab address of tracepoint inserted on
37372@item type @tab 4 @tab type of tracepoint
37373@item enabled @tab 1 @tab enable or disable of tracepoint
37374@item step_count @tab 8 @tab step
37375@item pass_count @tab 8 @tab pass
37376@item numactions @tab 4 @tab number of tracepoint actions
37377@item hit count @tab 8 @tab hit count
37378@item trace frame usage @tab 8 @tab trace frame usage
37379@item compiled_cond @tab 8 @tab compiled condition
37380@item orig_size @tab 8 @tab orig size
37381@item condition @tab 4 if condition is NULL otherwise length of
37382@ref{agent expression object}
37383@tab zero if condition is NULL, otherwise is
37384@ref{agent expression object}
37385@item actions @tab variable
37386@tab numactions number of @ref{tracepoint action object}
37387@end multitable
37388
37389@node IPA Protocol Commands
37390@subsection IPA Protocol Commands
37391@cindex ipa protocol commands
37392
37393The spaces in each command are delimiters to ease reading this commands
37394specification. They don't exist in real commands.
37395
37396@table @samp
37397
37398@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37399Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 37400(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
37401head of @dfn{jumppad}, which is used to jump to data collection routine
37402in IPA finally.
37403
37404Replies:
37405@table @samp
37406@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37407@var{target_address} is address of tracepoint in the inferior.
697aa1b7 37408The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 37409@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
37410The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37411The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
37412@item E @var{NN}
37413for an error
37414
37415@end table
37416
7255706c
YQ
37417@item close
37418Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37419is about to kill inferiors.
37420
16bdd41f
YQ
37421@item qTfSTM
37422@xref{qTfSTM}.
37423@item qTsSTM
37424@xref{qTsSTM}.
37425@item qTSTMat
37426@xref{qTSTMat}.
37427@item probe_marker_at:@var{address}
37428Asks in-process agent to probe the marker at @var{address}.
37429
37430Replies:
37431@table @samp
37432@item E @var{NN}
37433for an error
37434@end table
37435@item unprobe_marker_at:@var{address}
37436Asks in-process agent to unprobe the marker at @var{address}.
37437@end table
37438
8e04817f
AC
37439@node GDB Bugs
37440@chapter Reporting Bugs in @value{GDBN}
37441@cindex bugs in @value{GDBN}
37442@cindex reporting bugs in @value{GDBN}
c906108c 37443
8e04817f 37444Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 37445
8e04817f
AC
37446Reporting a bug may help you by bringing a solution to your problem, or it
37447may not. But in any case the principal function of a bug report is to help
37448the entire community by making the next version of @value{GDBN} work better. Bug
37449reports are your contribution to the maintenance of @value{GDBN}.
c906108c 37450
8e04817f
AC
37451In order for a bug report to serve its purpose, you must include the
37452information that enables us to fix the bug.
c4555f82
SC
37453
37454@menu
8e04817f
AC
37455* Bug Criteria:: Have you found a bug?
37456* Bug Reporting:: How to report bugs
c4555f82
SC
37457@end menu
37458
8e04817f 37459@node Bug Criteria
79a6e687 37460@section Have You Found a Bug?
8e04817f 37461@cindex bug criteria
c4555f82 37462
8e04817f 37463If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
37464
37465@itemize @bullet
8e04817f
AC
37466@cindex fatal signal
37467@cindex debugger crash
37468@cindex crash of debugger
c4555f82 37469@item
8e04817f
AC
37470If the debugger gets a fatal signal, for any input whatever, that is a
37471@value{GDBN} bug. Reliable debuggers never crash.
37472
37473@cindex error on valid input
37474@item
37475If @value{GDBN} produces an error message for valid input, that is a
37476bug. (Note that if you're cross debugging, the problem may also be
37477somewhere in the connection to the target.)
c4555f82 37478
8e04817f 37479@cindex invalid input
c4555f82 37480@item
8e04817f
AC
37481If @value{GDBN} does not produce an error message for invalid input,
37482that is a bug. However, you should note that your idea of
37483``invalid input'' might be our idea of ``an extension'' or ``support
37484for traditional practice''.
37485
37486@item
37487If you are an experienced user of debugging tools, your suggestions
37488for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37489@end itemize
37490
8e04817f 37491@node Bug Reporting
79a6e687 37492@section How to Report Bugs
8e04817f
AC
37493@cindex bug reports
37494@cindex @value{GDBN} bugs, reporting
37495
37496A number of companies and individuals offer support for @sc{gnu} products.
37497If you obtained @value{GDBN} from a support organization, we recommend you
37498contact that organization first.
37499
37500You can find contact information for many support companies and
37501individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37502distribution.
37503@c should add a web page ref...
37504
c16158bc
JM
37505@ifset BUGURL
37506@ifset BUGURL_DEFAULT
129188f6 37507In any event, we also recommend that you submit bug reports for
d3e8051b 37508@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37509@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37510page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37511be used.
8e04817f
AC
37512
37513@strong{Do not send bug reports to @samp{info-gdb}, or to
37514@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37515not want to receive bug reports. Those that do have arranged to receive
37516@samp{bug-gdb}.
37517
37518The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37519serves as a repeater. The mailing list and the newsgroup carry exactly
37520the same messages. Often people think of posting bug reports to the
37521newsgroup instead of mailing them. This appears to work, but it has one
37522problem which can be crucial: a newsgroup posting often lacks a mail
37523path back to the sender. Thus, if we need to ask for more information,
37524we may be unable to reach you. For this reason, it is better to send
37525bug reports to the mailing list.
c16158bc
JM
37526@end ifset
37527@ifclear BUGURL_DEFAULT
37528In any event, we also recommend that you submit bug reports for
37529@value{GDBN} to @value{BUGURL}.
37530@end ifclear
37531@end ifset
c4555f82 37532
8e04817f
AC
37533The fundamental principle of reporting bugs usefully is this:
37534@strong{report all the facts}. If you are not sure whether to state a
37535fact or leave it out, state it!
c4555f82 37536
8e04817f
AC
37537Often people omit facts because they think they know what causes the
37538problem and assume that some details do not matter. Thus, you might
37539assume that the name of the variable you use in an example does not matter.
37540Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37541stray memory reference which happens to fetch from the location where that
37542name is stored in memory; perhaps, if the name were different, the contents
37543of that location would fool the debugger into doing the right thing despite
37544the bug. Play it safe and give a specific, complete example. That is the
37545easiest thing for you to do, and the most helpful.
c4555f82 37546
8e04817f
AC
37547Keep in mind that the purpose of a bug report is to enable us to fix the
37548bug. It may be that the bug has been reported previously, but neither
37549you nor we can know that unless your bug report is complete and
37550self-contained.
c4555f82 37551
8e04817f
AC
37552Sometimes people give a few sketchy facts and ask, ``Does this ring a
37553bell?'' Those bug reports are useless, and we urge everyone to
37554@emph{refuse to respond to them} except to chide the sender to report
37555bugs properly.
37556
37557To enable us to fix the bug, you should include all these things:
c4555f82
SC
37558
37559@itemize @bullet
37560@item
8e04817f
AC
37561The version of @value{GDBN}. @value{GDBN} announces it if you start
37562with no arguments; you can also print it at any time using @code{show
37563version}.
c4555f82 37564
8e04817f
AC
37565Without this, we will not know whether there is any point in looking for
37566the bug in the current version of @value{GDBN}.
c4555f82
SC
37567
37568@item
8e04817f
AC
37569The type of machine you are using, and the operating system name and
37570version number.
c4555f82 37571
6eaaf48b
EZ
37572@item
37573The details of the @value{GDBN} build-time configuration.
37574@value{GDBN} shows these details if you invoke it with the
37575@option{--configuration} command-line option, or if you type
37576@code{show configuration} at @value{GDBN}'s prompt.
37577
c4555f82 37578@item
c1468174 37579What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37580``@value{GCC}--2.8.1''.
c4555f82
SC
37581
37582@item
8e04817f 37583What compiler (and its version) was used to compile the program you are
c1468174 37584debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37585C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37586to get this information; for other compilers, see the documentation for
37587those compilers.
c4555f82 37588
8e04817f
AC
37589@item
37590The command arguments you gave the compiler to compile your example and
37591observe the bug. For example, did you use @samp{-O}? To guarantee
37592you will not omit something important, list them all. A copy of the
37593Makefile (or the output from make) is sufficient.
c4555f82 37594
8e04817f
AC
37595If we were to try to guess the arguments, we would probably guess wrong
37596and then we might not encounter the bug.
c4555f82 37597
8e04817f
AC
37598@item
37599A complete input script, and all necessary source files, that will
37600reproduce the bug.
c4555f82 37601
8e04817f
AC
37602@item
37603A description of what behavior you observe that you believe is
37604incorrect. For example, ``It gets a fatal signal.''
c4555f82 37605
8e04817f
AC
37606Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37607will certainly notice it. But if the bug is incorrect output, we might
37608not notice unless it is glaringly wrong. You might as well not give us
37609a chance to make a mistake.
c4555f82 37610
8e04817f
AC
37611Even if the problem you experience is a fatal signal, you should still
37612say so explicitly. Suppose something strange is going on, such as, your
37613copy of @value{GDBN} is out of synch, or you have encountered a bug in
37614the C library on your system. (This has happened!) Your copy might
37615crash and ours would not. If you told us to expect a crash, then when
37616ours fails to crash, we would know that the bug was not happening for
37617us. If you had not told us to expect a crash, then we would not be able
37618to draw any conclusion from our observations.
c4555f82 37619
e0c07bf0
MC
37620@pindex script
37621@cindex recording a session script
37622To collect all this information, you can use a session recording program
37623such as @command{script}, which is available on many Unix systems.
37624Just run your @value{GDBN} session inside @command{script} and then
37625include the @file{typescript} file with your bug report.
37626
37627Another way to record a @value{GDBN} session is to run @value{GDBN}
37628inside Emacs and then save the entire buffer to a file.
37629
8e04817f
AC
37630@item
37631If you wish to suggest changes to the @value{GDBN} source, send us context
37632diffs. If you even discuss something in the @value{GDBN} source, refer to
37633it by context, not by line number.
c4555f82 37634
8e04817f
AC
37635The line numbers in our development sources will not match those in your
37636sources. Your line numbers would convey no useful information to us.
c4555f82 37637
8e04817f 37638@end itemize
c4555f82 37639
8e04817f 37640Here are some things that are not necessary:
c4555f82 37641
8e04817f
AC
37642@itemize @bullet
37643@item
37644A description of the envelope of the bug.
c4555f82 37645
8e04817f
AC
37646Often people who encounter a bug spend a lot of time investigating
37647which changes to the input file will make the bug go away and which
37648changes will not affect it.
c4555f82 37649
8e04817f
AC
37650This is often time consuming and not very useful, because the way we
37651will find the bug is by running a single example under the debugger
37652with breakpoints, not by pure deduction from a series of examples.
37653We recommend that you save your time for something else.
c4555f82 37654
8e04817f
AC
37655Of course, if you can find a simpler example to report @emph{instead}
37656of the original one, that is a convenience for us. Errors in the
37657output will be easier to spot, running under the debugger will take
37658less time, and so on.
c4555f82 37659
8e04817f
AC
37660However, simplification is not vital; if you do not want to do this,
37661report the bug anyway and send us the entire test case you used.
c4555f82 37662
8e04817f
AC
37663@item
37664A patch for the bug.
c4555f82 37665
8e04817f
AC
37666A patch for the bug does help us if it is a good one. But do not omit
37667the necessary information, such as the test case, on the assumption that
37668a patch is all we need. We might see problems with your patch and decide
37669to fix the problem another way, or we might not understand it at all.
c4555f82 37670
8e04817f
AC
37671Sometimes with a program as complicated as @value{GDBN} it is very hard to
37672construct an example that will make the program follow a certain path
37673through the code. If you do not send us the example, we will not be able
37674to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37675
8e04817f
AC
37676And if we cannot understand what bug you are trying to fix, or why your
37677patch should be an improvement, we will not install it. A test case will
37678help us to understand.
c4555f82 37679
8e04817f
AC
37680@item
37681A guess about what the bug is or what it depends on.
c4555f82 37682
8e04817f
AC
37683Such guesses are usually wrong. Even we cannot guess right about such
37684things without first using the debugger to find the facts.
37685@end itemize
c4555f82 37686
8e04817f
AC
37687@c The readline documentation is distributed with the readline code
37688@c and consists of the two following files:
cc88a640
JK
37689@c rluser.texi
37690@c hsuser.texi
8e04817f
AC
37691@c Use -I with makeinfo to point to the appropriate directory,
37692@c environment var TEXINPUTS with TeX.
39037522 37693@ifclear SYSTEM_READLINE
5bdf8622 37694@include rluser.texi
cc88a640 37695@include hsuser.texi
39037522 37696@end ifclear
c4555f82 37697
4ceed123
JB
37698@node In Memoriam
37699@appendix In Memoriam
37700
9ed350ad
JB
37701The @value{GDBN} project mourns the loss of the following long-time
37702contributors:
4ceed123
JB
37703
37704@table @code
37705@item Fred Fish
9ed350ad
JB
37706Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37707to Free Software in general. Outside of @value{GDBN}, he was known in
37708the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37709
37710@item Michael Snyder
9ed350ad
JB
37711Michael was one of the Global Maintainers of the @value{GDBN} project,
37712with contributions recorded as early as 1996, until 2011. In addition
37713to his day to day participation, he was a large driving force behind
37714adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37715@end table
37716
37717Beyond their technical contributions to the project, they were also
37718enjoyable members of the Free Software Community. We will miss them.
c4555f82 37719
8e04817f
AC
37720@node Formatting Documentation
37721@appendix Formatting Documentation
c4555f82 37722
8e04817f
AC
37723@cindex @value{GDBN} reference card
37724@cindex reference card
37725The @value{GDBN} 4 release includes an already-formatted reference card, ready
37726for printing with PostScript or Ghostscript, in the @file{gdb}
37727subdirectory of the main source directory@footnote{In
37728@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37729release.}. If you can use PostScript or Ghostscript with your printer,
37730you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37731
8e04817f
AC
37732The release also includes the source for the reference card. You
37733can format it, using @TeX{}, by typing:
c4555f82 37734
474c8240 37735@smallexample
8e04817f 37736make refcard.dvi
474c8240 37737@end smallexample
c4555f82 37738
8e04817f
AC
37739The @value{GDBN} reference card is designed to print in @dfn{landscape}
37740mode on US ``letter'' size paper;
37741that is, on a sheet 11 inches wide by 8.5 inches
37742high. You will need to specify this form of printing as an option to
37743your @sc{dvi} output program.
c4555f82 37744
8e04817f 37745@cindex documentation
c4555f82 37746
8e04817f
AC
37747All the documentation for @value{GDBN} comes as part of the machine-readable
37748distribution. The documentation is written in Texinfo format, which is
37749a documentation system that uses a single source file to produce both
37750on-line information and a printed manual. You can use one of the Info
37751formatting commands to create the on-line version of the documentation
37752and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37753
8e04817f
AC
37754@value{GDBN} includes an already formatted copy of the on-line Info
37755version of this manual in the @file{gdb} subdirectory. The main Info
37756file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37757subordinate files matching @samp{gdb.info*} in the same directory. If
37758necessary, you can print out these files, or read them with any editor;
37759but they are easier to read using the @code{info} subsystem in @sc{gnu}
37760Emacs or the standalone @code{info} program, available as part of the
37761@sc{gnu} Texinfo distribution.
c4555f82 37762
8e04817f
AC
37763If you want to format these Info files yourself, you need one of the
37764Info formatting programs, such as @code{texinfo-format-buffer} or
37765@code{makeinfo}.
c4555f82 37766
8e04817f
AC
37767If you have @code{makeinfo} installed, and are in the top level
37768@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37769version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37770
474c8240 37771@smallexample
8e04817f
AC
37772cd gdb
37773make gdb.info
474c8240 37774@end smallexample
c4555f82 37775
8e04817f
AC
37776If you want to typeset and print copies of this manual, you need @TeX{},
37777a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37778Texinfo definitions file.
c4555f82 37779
8e04817f
AC
37780@TeX{} is a typesetting program; it does not print files directly, but
37781produces output files called @sc{dvi} files. To print a typeset
37782document, you need a program to print @sc{dvi} files. If your system
37783has @TeX{} installed, chances are it has such a program. The precise
37784command to use depends on your system; @kbd{lpr -d} is common; another
37785(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37786require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37787
8e04817f
AC
37788@TeX{} also requires a macro definitions file called
37789@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37790written in Texinfo format. On its own, @TeX{} cannot either read or
37791typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37792and is located in the @file{gdb-@var{version-number}/texinfo}
37793directory.
c4555f82 37794
8e04817f 37795If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37796typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37797subdirectory of the main source directory (for example, to
37798@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37799
474c8240 37800@smallexample
8e04817f 37801make gdb.dvi
474c8240 37802@end smallexample
c4555f82 37803
8e04817f 37804Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37805
8e04817f
AC
37806@node Installing GDB
37807@appendix Installing @value{GDBN}
8e04817f 37808@cindex installation
c4555f82 37809
7fa2210b
DJ
37810@menu
37811* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37812* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37813* Separate Objdir:: Compiling @value{GDBN} in another directory
37814* Config Names:: Specifying names for hosts and targets
37815* Configure Options:: Summary of options for configure
098b41a6 37816* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37817@end menu
37818
37819@node Requirements
79a6e687 37820@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37821@cindex building @value{GDBN}, requirements for
37822
37823Building @value{GDBN} requires various tools and packages to be available.
37824Other packages will be used only if they are found.
37825
79a6e687 37826@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37827@table @asis
7f0bd420
TT
37828@item C@t{++}11 compiler
37829@value{GDBN} is written in C@t{++}11. It should be buildable with any
37830recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37831
7f0bd420
TT
37832@item GNU make
37833@value{GDBN}'s build system relies on features only found in the GNU
37834make program. Other variants of @code{make} will not work.
904cb749
JB
37835
37836@item GMP (The GNU Multiple Precision Arithmetic Library)
37837@value{GDBN} now uses GMP to perform some of its arithmetics.
37838This library may be included with your operating system distribution;
37839if it is not, you can get the latest version from
37840@url{https://gmplib.org/}. If GMP is installed at an unusual path,
37841you can use the @option{--with-libgmp-prefix} option to specify
37842its location.
37843
7fa2210b
DJ
37844@end table
37845
79a6e687 37846@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37847@table @asis
37848@item Expat
123dc839 37849@anchor{Expat}
7fa2210b
DJ
37850@value{GDBN} can use the Expat XML parsing library. This library may be
37851included with your operating system distribution; if it is not, you
37852can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37853The @file{configure} script will search for this library in several
7fa2210b
DJ
37854standard locations; if it is installed in an unusual path, you can
37855use the @option{--with-libexpat-prefix} option to specify its location.
37856
9cceb671
DJ
37857Expat is used for:
37858
37859@itemize @bullet
37860@item
37861Remote protocol memory maps (@pxref{Memory Map Format})
37862@item
37863Target descriptions (@pxref{Target Descriptions})
37864@item
2268b414
JK
37865Remote shared library lists (@xref{Library List Format},
37866or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37867@item
37868MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37869@item
37870Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37871@item
f4abbc16
MM
37872Branch trace (@pxref{Branch Trace Format},
37873@pxref{Branch Trace Configuration Format})
9cceb671 37874@end itemize
7fa2210b 37875
7f0bd420
TT
37876@item Guile
37877@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37878default, @value{GDBN} will be compiled if the Guile libraries are
37879installed and are found by @file{configure}. You can use the
37880@code{--with-guile} option to request Guile, and pass either the Guile
37881version number or the file name of the relevant @code{pkg-config}
37882program to choose a particular version of Guile.
37883
37884@item iconv
37885@value{GDBN}'s features related to character sets (@pxref{Character
37886Sets}) require a functioning @code{iconv} implementation. If you are
37887on a GNU system, then this is provided by the GNU C Library. Some
37888other systems also provide a working @code{iconv}.
37889
37890If @value{GDBN} is using the @code{iconv} program which is installed
37891in a non-standard place, you will need to tell @value{GDBN} where to
37892find it. This is done with @option{--with-iconv-bin} which specifies
37893the directory that contains the @code{iconv} program. This program is
37894run in order to make a list of the available character sets.
37895
37896On systems without @code{iconv}, you can install GNU Libiconv. If
37897Libiconv is installed in a standard place, @value{GDBN} will
37898automatically use it if it is needed. If you have previously
37899installed Libiconv in a non-standard place, you can use the
37900@option{--with-libiconv-prefix} option to @file{configure}.
37901
37902@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37903arrange to build Libiconv if a directory named @file{libiconv} appears
37904in the top-most source directory. If Libiconv is built this way, and
37905if the operating system does not provide a suitable @code{iconv}
37906implementation, then the just-built library will automatically be used
37907by @value{GDBN}. One easy way to set this up is to download GNU
37908Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37909source tree, and then rename the directory holding the Libiconv source
37910code to @samp{libiconv}.
37911
37912@item lzma
37913@value{GDBN} can support debugging sections that are compressed with
37914the LZMA library. @xref{MiniDebugInfo}. If this library is not
37915included with your operating system, you can find it in the xz package
37916at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37917the usual place, then the @file{configure} script will use it
37918automatically. If it is installed in an unusual path, you can use the
37919@option{--with-lzma-prefix} option to specify its location.
37920
2400729e
UW
37921@item MPFR
37922@anchor{MPFR}
37923@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37924library. This library may be included with your operating system
37925distribution; if it is not, you can get the latest version from
37926@url{http://www.mpfr.org}. The @file{configure} script will search
37927for this library in several standard locations; if it is installed
37928in an unusual path, you can use the @option{--with-libmpfr-prefix}
37929option to specify its location.
37930
37931GNU MPFR is used to emulate target floating-point arithmetic during
37932expression evaluation when the target uses different floating-point
37933formats than the host. If GNU MPFR it is not available, @value{GDBN}
37934will fall back to using host floating-point arithmetic.
37935
7f0bd420
TT
37936@item Python
37937@value{GDBN} can be scripted using Python language. @xref{Python}.
37938By default, @value{GDBN} will be compiled if the Python libraries are
37939installed and are found by @file{configure}. You can use the
37940@code{--with-python} option to request Python, and pass either the
37941file name of the relevant @code{python} executable, or the name of the
37942directory in which Python is installed, to choose a particular
37943installation of Python.
37944
31fffb02
CS
37945@item zlib
37946@cindex compressed debug sections
37947@value{GDBN} will use the @samp{zlib} library, if available, to read
37948compressed debug sections. Some linkers, such as GNU gold, are capable
37949of producing binaries with compressed debug sections. If @value{GDBN}
37950is compiled with @samp{zlib}, it will be able to read the debug
37951information in such binaries.
37952
37953The @samp{zlib} library is likely included with your operating system
37954distribution; if it is not, you can get the latest version from
37955@url{http://zlib.net}.
7fa2210b
DJ
37956@end table
37957
37958@node Running Configure
db2e3e2e 37959@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 37960@cindex configuring @value{GDBN}
db2e3e2e 37961@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
37962of preparing @value{GDBN} for installation; you can then use @code{make} to
37963build the @code{gdb} program.
37964@iftex
37965@c irrelevant in info file; it's as current as the code it lives with.
37966@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37967look at the @file{README} file in the sources; we may have improved the
37968installation procedures since publishing this manual.}
37969@end iftex
c4555f82 37970
8e04817f
AC
37971The @value{GDBN} distribution includes all the source code you need for
37972@value{GDBN} in a single directory, whose name is usually composed by
37973appending the version number to @samp{gdb}.
c4555f82 37974
8e04817f
AC
37975For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37976@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 37977
8e04817f
AC
37978@table @code
37979@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37980script for configuring @value{GDBN} and all its supporting libraries
c4555f82 37981
8e04817f
AC
37982@item gdb-@value{GDBVN}/gdb
37983the source specific to @value{GDBN} itself
c4555f82 37984
8e04817f
AC
37985@item gdb-@value{GDBVN}/bfd
37986source for the Binary File Descriptor library
c906108c 37987
8e04817f
AC
37988@item gdb-@value{GDBVN}/include
37989@sc{gnu} include files
c906108c 37990
8e04817f
AC
37991@item gdb-@value{GDBVN}/libiberty
37992source for the @samp{-liberty} free software library
c906108c 37993
8e04817f
AC
37994@item gdb-@value{GDBVN}/opcodes
37995source for the library of opcode tables and disassemblers
c906108c 37996
8e04817f
AC
37997@item gdb-@value{GDBVN}/readline
37998source for the @sc{gnu} command-line interface
8e04817f 37999@end table
c906108c 38000
7f0bd420
TT
38001There may be other subdirectories as well.
38002
db2e3e2e 38003The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
38004from the @file{gdb-@var{version-number}} source directory, which in
38005this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 38006
8e04817f 38007First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 38008if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
38009identifier for the platform on which @value{GDBN} will run as an
38010argument.
c906108c 38011
8e04817f 38012For example:
c906108c 38013
474c8240 38014@smallexample
8e04817f 38015cd gdb-@value{GDBVN}
7f0bd420 38016./configure
8e04817f 38017make
474c8240 38018@end smallexample
c906108c 38019
7f0bd420
TT
38020Running @samp{configure} and then running @code{make} builds the
38021included supporting libraries, then @code{gdb} itself. The configured
38022source files, and the binaries, are left in the corresponding source
38023directories.
c906108c 38024
8e04817f 38025@need 750
db2e3e2e 38026@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
38027system does not recognize this automatically when you run a different
38028shell, you may need to run @code{sh} on it explicitly:
c906108c 38029
474c8240 38030@smallexample
7f0bd420 38031sh configure
474c8240 38032@end smallexample
c906108c 38033
db2e3e2e 38034You should run the @file{configure} script from the top directory in the
94e91d6d 38035source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 38036@file{configure} from one of the subdirectories, you will configure only
94e91d6d 38037that subdirectory. That is usually not what you want. In particular,
db2e3e2e 38038if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
38039of the @file{gdb-@var{version-number}} directory, you will omit the
38040configuration of @file{bfd}, @file{readline}, and other sibling
38041directories of the @file{gdb} subdirectory. This leads to build errors
38042about missing include files such as @file{bfd/bfd.h}.
c906108c 38043
7f0bd420
TT
38044You can install @code{@value{GDBN}} anywhere. The best way to do this
38045is to pass the @code{--prefix} option to @code{configure}, and then
38046install it with @code{make install}.
c906108c 38047
8e04817f 38048@node Separate Objdir
79a6e687 38049@section Compiling @value{GDBN} in Another Directory
c906108c 38050
8e04817f
AC
38051If you want to run @value{GDBN} versions for several host or target machines,
38052you need a different @code{gdb} compiled for each combination of
db2e3e2e 38053host and target. @file{configure} is designed to make this easy by
8e04817f
AC
38054allowing you to generate each configuration in a separate subdirectory,
38055rather than in the source directory. If your @code{make} program
38056handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38057@code{make} in each of these directories builds the @code{gdb}
38058program specified there.
c906108c 38059
db2e3e2e 38060To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 38061with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
38062(You also need to specify a path to find @file{configure}
38063itself from your working directory. If the path to @file{configure}
8e04817f
AC
38064would be the same as the argument to @samp{--srcdir}, you can leave out
38065the @samp{--srcdir} option; it is assumed.)
c906108c 38066
8e04817f
AC
38067For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38068separate directory for a Sun 4 like this:
c906108c 38069
474c8240 38070@smallexample
8e04817f
AC
38071@group
38072cd gdb-@value{GDBVN}
38073mkdir ../gdb-sun4
38074cd ../gdb-sun4
7f0bd420 38075../gdb-@value{GDBVN}/configure
8e04817f
AC
38076make
38077@end group
474c8240 38078@end smallexample
c906108c 38079
db2e3e2e 38080When @file{configure} builds a configuration using a remote source
8e04817f
AC
38081directory, it creates a tree for the binaries with the same structure
38082(and using the same names) as the tree under the source directory. In
38083the example, you'd find the Sun 4 library @file{libiberty.a} in the
38084directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38085@file{gdb-sun4/gdb}.
c906108c 38086
94e91d6d
MC
38087Make sure that your path to the @file{configure} script has just one
38088instance of @file{gdb} in it. If your path to @file{configure} looks
38089like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38090one subdirectory of @value{GDBN}, not the whole package. This leads to
38091build errors about missing include files such as @file{bfd/bfd.h}.
38092
8e04817f
AC
38093One popular reason to build several @value{GDBN} configurations in separate
38094directories is to configure @value{GDBN} for cross-compiling (where
38095@value{GDBN} runs on one machine---the @dfn{host}---while debugging
38096programs that run on another machine---the @dfn{target}).
38097You specify a cross-debugging target by
db2e3e2e 38098giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 38099
8e04817f
AC
38100When you run @code{make} to build a program or library, you must run
38101it in a configured directory---whatever directory you were in when you
db2e3e2e 38102called @file{configure} (or one of its subdirectories).
c906108c 38103
db2e3e2e 38104The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
38105directory also runs recursively. If you type @code{make} in a source
38106directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38107directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38108will build all the required libraries, and then build GDB.
c906108c 38109
8e04817f
AC
38110When you have multiple hosts or targets configured in separate
38111directories, you can run @code{make} on them in parallel (for example,
38112if they are NFS-mounted on each of the hosts); they will not interfere
38113with each other.
c906108c 38114
8e04817f 38115@node Config Names
79a6e687 38116@section Specifying Names for Hosts and Targets
c906108c 38117
db2e3e2e 38118The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
38119script are based on a three-part naming scheme, but some short predefined
38120aliases are also supported. The full naming scheme encodes three pieces
38121of information in the following pattern:
c906108c 38122
474c8240 38123@smallexample
8e04817f 38124@var{architecture}-@var{vendor}-@var{os}
474c8240 38125@end smallexample
c906108c 38126
8e04817f
AC
38127For example, you can use the alias @code{sun4} as a @var{host} argument,
38128or as the value for @var{target} in a @code{--target=@var{target}}
38129option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 38130
db2e3e2e 38131The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 38132any query facility to list all supported host and target names or
db2e3e2e 38133aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
38134@code{config.sub} to map abbreviations to full names; you can read the
38135script, if you wish, or you can use it to test your guesses on
38136abbreviations---for example:
c906108c 38137
8e04817f
AC
38138@smallexample
38139% sh config.sub i386-linux
38140i386-pc-linux-gnu
38141% sh config.sub alpha-linux
38142alpha-unknown-linux-gnu
38143% sh config.sub hp9k700
38144hppa1.1-hp-hpux
38145% sh config.sub sun4
38146sparc-sun-sunos4.1.1
38147% sh config.sub sun3
38148m68k-sun-sunos4.1.1
38149% sh config.sub i986v
38150Invalid configuration `i986v': machine `i986v' not recognized
38151@end smallexample
c906108c 38152
8e04817f
AC
38153@noindent
38154@code{config.sub} is also distributed in the @value{GDBN} source
38155directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 38156
8e04817f 38157@node Configure Options
db2e3e2e 38158@section @file{configure} Options
c906108c 38159
db2e3e2e 38160Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
38161are most often useful for building @value{GDBN}. @file{configure}
38162also has several other options not listed here. @inforef{Running
38163configure scripts,,autoconf.info}, for a full
38164explanation of @file{configure}.
c906108c 38165
474c8240 38166@smallexample
8e04817f
AC
38167configure @r{[}--help@r{]}
38168 @r{[}--prefix=@var{dir}@r{]}
38169 @r{[}--exec-prefix=@var{dir}@r{]}
38170 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 38171 @r{[}--target=@var{target}@r{]}
474c8240 38172@end smallexample
c906108c 38173
8e04817f
AC
38174@noindent
38175You may introduce options with a single @samp{-} rather than
38176@samp{--} if you prefer; but you may abbreviate option names if you use
38177@samp{--}.
c906108c 38178
8e04817f
AC
38179@table @code
38180@item --help
db2e3e2e 38181Display a quick summary of how to invoke @file{configure}.
c906108c 38182
8e04817f
AC
38183@item --prefix=@var{dir}
38184Configure the source to install programs and files under directory
38185@file{@var{dir}}.
c906108c 38186
8e04817f
AC
38187@item --exec-prefix=@var{dir}
38188Configure the source to install programs under directory
38189@file{@var{dir}}.
c906108c 38190
8e04817f
AC
38191@c avoid splitting the warning from the explanation:
38192@need 2000
38193@item --srcdir=@var{dirname}
8e04817f
AC
38194Use this option to make configurations in directories separate from the
38195@value{GDBN} source directories. Among other things, you can use this to
38196build (or maintain) several configurations simultaneously, in separate
db2e3e2e 38197directories. @file{configure} writes configuration-specific files in
8e04817f 38198the current directory, but arranges for them to use the source in the
db2e3e2e 38199directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
38200the working directory in parallel to the source directories below
38201@var{dirname}.
c906108c 38202
8e04817f
AC
38203@item --target=@var{target}
38204Configure @value{GDBN} for cross-debugging programs running on the specified
38205@var{target}. Without this option, @value{GDBN} is configured to debug
38206programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 38207
a95746f9
TT
38208There is no convenient way to generate a list of all available
38209targets. Also see the @code{--enable-targets} option, below.
8e04817f 38210@end table
c906108c 38211
a95746f9
TT
38212There are many other options that are specific to @value{GDBN}. This
38213lists just the most common ones; there are some very specialized
38214options not described here.
38215
38216@table @code
38217@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38218@itemx --enable-targets=all
38219Configure @value{GDBN} for cross-debugging programs running on the
38220specified list of targets. The special value @samp{all} configures
38221@value{GDBN} for debugging programs running on any target it supports.
38222
38223@item --with-gdb-datadir=@var{path}
38224Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38225here for certain supporting files or scripts. This defaults to the
6b92c0d3 38226@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
38227@code{--datadir}).
38228
38229@item --with-relocated-sources=@var{dir}
38230Sets up the default source path substitution rule so that directory
38231names recorded in debug information will be automatically adjusted for
38232any directory under @var{dir}. @var{dir} should be a subdirectory of
38233@value{GDBN}'s configured prefix, the one mentioned in the
38234@code{--prefix} or @code{--exec-prefix} options to configure. This
38235option is useful if GDB is supposed to be moved to a different place
38236after it is built.
38237
38238@item --enable-64-bit-bfd
38239Enable 64-bit support in BFD on 32-bit hosts.
38240
38241@item --disable-gdbmi
38242Build @value{GDBN} without the GDB/MI machine interface
38243(@pxref{GDB/MI}).
38244
38245@item --enable-tui
38246Build @value{GDBN} with the text-mode full-screen user interface
38247(TUI). Requires a curses library (ncurses and cursesX are also
38248supported).
38249
38250@item --with-curses
38251Use the curses library instead of the termcap library, for text-mode
38252terminal operations.
38253
0d79cdc4
AM
38254@item --with-debuginfod
38255Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38256Used to automatically fetch source files and separate debug files from
38257debuginfod servers using the associated executable's build ID. Enabled
38258by default if libdebuginfod is installed and found at configure time.
38259debuginfod is packaged with elfutils, starting with version 0.178. You
38260can get the latest version from `https://sourceware.org/elfutils/'.
38261
a95746f9
TT
38262@item --with-libunwind-ia64
38263Use the libunwind library for unwinding function call stack on ia64
38264target platforms. See http://www.nongnu.org/libunwind/index.html for
38265details.
38266
38267@item --with-system-readline
38268Use the readline library installed on the host, rather than the
86c6b807
TT
38269library supplied as part of @value{GDBN}. Readline 7 or newer is
38270required; this is enforced by the build system.
a95746f9
TT
38271
38272@item --with-system-zlib
38273Use the zlib library installed on the host, rather than the library
38274supplied as part of @value{GDBN}.
38275
38276@item --with-expat
38277Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38278default if libexpat is installed and found at configure time.) This
38279library is used to read XML files supplied with @value{GDBN}. If it
38280is unavailable, some features, such as remote protocol memory maps,
38281target descriptions, and shared library lists, that are based on XML
38282files, will not be available in @value{GDBN}. If your host does not
38283have libexpat installed, you can get the latest version from
38284`http://expat.sourceforge.net'.
38285
38286@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38287
38288Build @value{GDBN} with GNU libiconv, a character set encoding
38289conversion library. This is not done by default, as on GNU systems
38290the @code{iconv} that is built in to the C library is sufficient. If
38291your host does not have a working @code{iconv}, you can get the latest
38292version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38293
38294@value{GDBN}'s build system also supports building GNU libiconv as
38295part of the overall build. @xref{Requirements}.
38296
38297@item --with-lzma
38298Build @value{GDBN} with LZMA, a compression library. (Done by default
38299if liblzma is installed and found at configure time.) LZMA is used by
38300@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38301platforms using the ELF object file format. If your host does not
38302have liblzma installed, you can get the latest version from
38303`https://tukaani.org/xz/'.
38304
38305@item --with-mpfr
38306Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38307floating-point computation with correct rounding. (Done by default if
38308GNU MPFR is installed and found at configure time.) This library is
38309used to emulate target floating-point arithmetic during expression
38310evaluation when the target uses different floating-point formats than
38311the host. If GNU MPFR is not available, @value{GDBN} will fall back
38312to using host floating-point arithmetic. If your host does not have
38313GNU MPFR installed, you can get the latest version from
38314`http://www.mpfr.org'.
38315
38316@item --with-python@r{[}=@var{python}@r{]}
38317Build @value{GDBN} with Python scripting support. (Done by default if
38318libpython is present and found at configure time.) Python makes
38319@value{GDBN} scripting much more powerful than the restricted CLI
38320scripting language. If your host does not have Python installed, you
38321can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 38322of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
38323is used to find the Python headers and libraries. It can be either
38324the name of a Python executable, or the name of the directory in which
38325Python is installed.
38326
38327@item --with-guile[=GUILE]'
38328Build @value{GDBN} with GNU Guile scripting support. (Done by default
38329if libguile is present and found at configure time.) If your host
38330does not have Guile installed, you can find it at
38331`https://www.gnu.org/software/guile/'. The optional argument GUILE
38332can be a version number, which will cause @code{configure} to try to
38333use that version of Guile; or the file name of a @code{pkg-config}
38334executable, which will be queried to find the information needed to
38335compile and link against Guile.
38336
38337@item --without-included-regex
38338Don't use the regex library included with @value{GDBN} (as part of the
38339libiberty library). This is the default on hosts with version 2 of
38340the GNU C library.
38341
38342@item --with-sysroot=@var{dir}
38343Use @var{dir} as the default system root directory for libraries whose
38344file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38345@var{dir} can be modified at run time by using the @command{set
38346sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38347prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38348default system root will be automatically adjusted if and when
38349@value{GDBN} is moved to a different location.
38350
38351@item --with-system-gdbinit=@var{file}
38352Configure @value{GDBN} to automatically load a system-wide init file.
38353@var{file} should be an absolute file name. If @var{file} is in a
38354directory under the configured prefix, and @value{GDBN} is moved to
38355another location after being built, the location of the system-wide
38356init file will be adjusted accordingly.
38357
ed2a2229
CB
38358@item --with-system-gdbinit-dir=@var{directory}
38359Configure @value{GDBN} to automatically load init files from a
38360system-wide directory. @var{directory} should be an absolute directory
38361name. If @var{directory} is in a directory under the configured
38362prefix, and @value{GDBN} is moved to another location after being
38363built, the location of the system-wide init directory will be
38364adjusted accordingly.
38365
a95746f9
TT
38366@item --enable-build-warnings
38367When building the @value{GDBN} sources, ask the compiler to warn about
38368any code which looks even vaguely suspicious. It passes many
38369different warning flags, depending on the exact version of the
38370compiler you are using.
38371
38372@item --enable-werror
38373Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38374to the compiler, which will fail the compilation if the compiler
38375outputs any warning messages.
f35d5ade
TT
38376
38377@item --enable-ubsan
eff98030
TT
38378Enable the GCC undefined behavior sanitizer. This is disabled by
38379default, but passing @code{--enable-ubsan=yes} or
38380@code{--enable-ubsan=auto} to @code{configure} will enable it. The
38381undefined behavior sanitizer checks for C@t{++} undefined behavior.
38382It has a performance cost, so if you are looking at @value{GDBN}'s
38383performance, you should disable it. The undefined behavior sanitizer
38384was first introduced in GCC 4.9.
a95746f9 38385@end table
c906108c 38386
098b41a6
JG
38387@node System-wide configuration
38388@section System-wide configuration and settings
38389@cindex system-wide init file
38390
ed2a2229
CB
38391@value{GDBN} can be configured to have a system-wide init file and a
38392system-wide init file directory; this file and files in that directory
38393(if they have a recognized file extension) will be read and executed at
38394startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 38395
ed2a2229 38396Here are the corresponding configure options:
098b41a6
JG
38397
38398@table @code
38399@item --with-system-gdbinit=@var{file}
38400Specify that the default location of the system-wide init file is
38401@var{file}.
ed2a2229
CB
38402@item --with-system-gdbinit-dir=@var{directory}
38403Specify that the default location of the system-wide init file directory
38404is @var{directory}.
098b41a6
JG
38405@end table
38406
38407If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 38408they may be subject to relocation. Two possible cases:
098b41a6
JG
38409
38410@itemize @bullet
38411@item
ed2a2229 38412If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
38413it will be subject to relocation. Suppose that the configure options
38414are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38415if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38416init file is looked for as @file{$install/etc/gdbinit} instead of
38417@file{$prefix/etc/gdbinit}.
38418
38419@item
38420By contrast, if the default location does not contain the prefix,
38421it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38422@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38423then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38424wherever @value{GDBN} is installed.
38425@end itemize
38426
e64e0392
DE
38427If the configured location of the system-wide init file (as given by the
38428@option{--with-system-gdbinit} option at configure time) is in the
38429data-directory (as specified by @option{--with-gdb-datadir} at configure
38430time) or in one of its subdirectories, then @value{GDBN} will look for the
38431system-wide init file in the directory specified by the
38432@option{--data-directory} command-line option.
38433Note that the system-wide init file is only read once, during @value{GDBN}
38434initialization. If the data-directory is changed after @value{GDBN} has
38435started with the @code{set data-directory} command, the file will not be
38436reread.
38437
ed2a2229
CB
38438This applies similarly to the system-wide directory specified in
38439@option{--with-system-gdbinit-dir}.
38440
38441Any supported scripting language can be used for these init files, as long
38442as the file extension matches the scripting language. To be interpreted
38443as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38444extension.
38445
5901af59
JB
38446@menu
38447* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38448@end menu
38449
38450@node System-wide Configuration Scripts
0201faac
JB
38451@subsection Installed System-wide Configuration Scripts
38452@cindex system-wide configuration scripts
38453
38454The @file{system-gdbinit} directory, located inside the data-directory
38455(as specified by @option{--with-gdb-datadir} at configure time) contains
38456a number of scripts which can be used as system-wide init files. To
38457automatically source those scripts at startup, @value{GDBN} should be
38458configured with @option{--with-system-gdbinit}. Otherwise, any user
38459should be able to source them by hand as needed.
38460
38461The following scripts are currently available:
38462@itemize @bullet
38463
38464@item @file{elinos.py}
38465@pindex elinos.py
38466@cindex ELinOS system-wide configuration script
38467This script is useful when debugging a program on an ELinOS target.
38468It takes advantage of the environment variables defined in a standard
38469ELinOS environment in order to determine the location of the system
38470shared libraries, and then sets the @samp{solib-absolute-prefix}
38471and @samp{solib-search-path} variables appropriately.
38472
38473@item @file{wrs-linux.py}
38474@pindex wrs-linux.py
38475@cindex Wind River Linux system-wide configuration script
38476This script is useful when debugging a program on a target running
38477Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38478the host-side sysroot used by the target system.
38479
38480@end itemize
38481
8e04817f
AC
38482@node Maintenance Commands
38483@appendix Maintenance Commands
38484@cindex maintenance commands
38485@cindex internal commands
c906108c 38486
8e04817f 38487In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
38488includes a number of commands intended for @value{GDBN} developers,
38489that are not documented elsewhere in this manual. These commands are
da316a69
EZ
38490provided here for reference. (For commands that turn on debugging
38491messages, see @ref{Debugging Output}.)
c906108c 38492
8e04817f 38493@table @code
09d4efe1 38494@kindex maint agent
782b2b07 38495@kindex maint agent-eval
f77cc5f0
HZ
38496@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38497@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38498Translate the given @var{expression} into remote agent bytecodes.
38499This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38500(@pxref{Agent Expressions}). The @samp{agent} version produces an
38501expression useful for data collection, such as by tracepoints, while
38502@samp{maint agent-eval} produces an expression that evaluates directly
38503to a result. For instance, a collection expression for @code{globa +
38504globb} will include bytecodes to record four bytes of memory at each
38505of the addresses of @code{globa} and @code{globb}, while discarding
38506the result of the addition, while an evaluation expression will do the
38507addition and return the sum.
f77cc5f0
HZ
38508If @code{-at} is given, generate remote agent bytecode for @var{location}.
38509If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38510
d3ce09f5
SS
38511@kindex maint agent-printf
38512@item maint agent-printf @var{format},@var{expr},...
38513Translate the given format string and list of argument expressions
38514into remote agent bytecodes and display them as a disassembled list.
38515This command is useful for debugging the agent version of dynamic
6dd24dfa 38516printf (@pxref{Dynamic Printf}).
d3ce09f5 38517
8e04817f
AC
38518@kindex maint info breakpoints
38519@item @anchor{maint info breakpoints}maint info breakpoints
38520Using the same format as @samp{info breakpoints}, display both the
38521breakpoints you've set explicitly, and those @value{GDBN} is using for
38522internal purposes. Internal breakpoints are shown with negative
38523breakpoint numbers. The type column identifies what kind of breakpoint
38524is shown:
c906108c 38525
8e04817f
AC
38526@table @code
38527@item breakpoint
38528Normal, explicitly set breakpoint.
c906108c 38529
8e04817f
AC
38530@item watchpoint
38531Normal, explicitly set watchpoint.
c906108c 38532
8e04817f
AC
38533@item longjmp
38534Internal breakpoint, used to handle correctly stepping through
38535@code{longjmp} calls.
c906108c 38536
8e04817f
AC
38537@item longjmp resume
38538Internal breakpoint at the target of a @code{longjmp}.
c906108c 38539
8e04817f
AC
38540@item until
38541Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38542
8e04817f
AC
38543@item finish
38544Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38545
8e04817f
AC
38546@item shlib events
38547Shared library events.
c906108c 38548
8e04817f 38549@end table
c906108c 38550
b0627500
MM
38551@kindex maint info btrace
38552@item maint info btrace
38553Pint information about raw branch tracing data.
38554
38555@kindex maint btrace packet-history
38556@item maint btrace packet-history
38557Print the raw branch trace packets that are used to compute the
38558execution history for the @samp{record btrace} command. Both the
38559information and the format in which it is printed depend on the btrace
38560recording format.
38561
38562@table @code
38563@item bts
38564For the BTS recording format, print a list of blocks of sequential
38565code. For each block, the following information is printed:
38566
38567@table @asis
38568@item Block number
38569Newer blocks have higher numbers. The oldest block has number zero.
38570@item Lowest @samp{PC}
38571@item Highest @samp{PC}
38572@end table
38573
38574@item pt
bc504a31
PA
38575For the Intel Processor Trace recording format, print a list of
38576Intel Processor Trace packets. For each packet, the following
b0627500
MM
38577information is printed:
38578
38579@table @asis
38580@item Packet number
38581Newer packets have higher numbers. The oldest packet has number zero.
38582@item Trace offset
38583The packet's offset in the trace stream.
38584@item Packet opcode and payload
38585@end table
38586@end table
38587
38588@kindex maint btrace clear-packet-history
38589@item maint btrace clear-packet-history
38590Discards the cached packet history printed by the @samp{maint btrace
38591packet-history} command. The history will be computed again when
38592needed.
38593
38594@kindex maint btrace clear
38595@item maint btrace clear
38596Discard the branch trace data. The data will be fetched anew and the
38597branch trace will be recomputed when needed.
38598
38599This implicitly truncates the branch trace to a single branch trace
38600buffer. When updating branch trace incrementally, the branch trace
38601available to @value{GDBN} may be bigger than a single branch trace
38602buffer.
38603
38604@kindex maint set btrace pt skip-pad
38605@item maint set btrace pt skip-pad
38606@kindex maint show btrace pt skip-pad
38607@item maint show btrace pt skip-pad
38608Control whether @value{GDBN} will skip PAD packets when computing the
38609packet history.
38610
fff08868
HZ
38611@kindex set displaced-stepping
38612@kindex show displaced-stepping
237fc4c9
PA
38613@cindex displaced stepping support
38614@cindex out-of-line single-stepping
fff08868
HZ
38615@item set displaced-stepping
38616@itemx show displaced-stepping
237fc4c9 38617Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38618if the target supports it. Displaced stepping is a way to single-step
38619over breakpoints without removing them from the inferior, by executing
38620an out-of-line copy of the instruction that was originally at the
38621breakpoint location. It is also known as out-of-line single-stepping.
38622
38623@table @code
38624@item set displaced-stepping on
38625If the target architecture supports it, @value{GDBN} will use
38626displaced stepping to step over breakpoints.
38627
38628@item set displaced-stepping off
38629@value{GDBN} will not use displaced stepping to step over breakpoints,
38630even if such is supported by the target architecture.
38631
38632@cindex non-stop mode, and @samp{set displaced-stepping}
38633@item set displaced-stepping auto
38634This is the default mode. @value{GDBN} will use displaced stepping
38635only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38636architecture supports displaced stepping.
38637@end table
237fc4c9 38638
7d0c9981
DE
38639@kindex maint check-psymtabs
38640@item maint check-psymtabs
38641Check the consistency of currently expanded psymtabs versus symtabs.
38642Use this to check, for example, whether a symbol is in one but not the other.
38643
09d4efe1
EZ
38644@kindex maint check-symtabs
38645@item maint check-symtabs
7d0c9981
DE
38646Check the consistency of currently expanded symtabs.
38647
38648@kindex maint expand-symtabs
38649@item maint expand-symtabs [@var{regexp}]
38650Expand symbol tables.
38651If @var{regexp} is specified, only expand symbol tables for file
38652names matching @var{regexp}.
09d4efe1 38653
992c7d70
GB
38654@kindex maint set catch-demangler-crashes
38655@kindex maint show catch-demangler-crashes
38656@cindex demangler crashes
38657@item maint set catch-demangler-crashes [on|off]
38658@itemx maint show catch-demangler-crashes
38659Control whether @value{GDBN} should attempt to catch crashes in the
38660symbol name demangler. The default is to attempt to catch crashes.
38661If enabled, the first time a crash is caught, a core file is created,
38662the offending symbol is displayed and the user is presented with the
38663option to terminate the current session.
38664
09d4efe1
EZ
38665@kindex maint cplus first_component
38666@item maint cplus first_component @var{name}
38667Print the first C@t{++} class/namespace component of @var{name}.
38668
38669@kindex maint cplus namespace
38670@item maint cplus namespace
38671Print the list of possible C@t{++} namespaces.
38672
09d4efe1
EZ
38673@kindex maint deprecate
38674@kindex maint undeprecate
38675@cindex deprecated commands
38676@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38677@itemx maint undeprecate @var{command}
38678Deprecate or undeprecate the named @var{command}. Deprecated commands
38679cause @value{GDBN} to issue a warning when you use them. The optional
38680argument @var{replacement} says which newer command should be used in
38681favor of the deprecated one; if it is given, @value{GDBN} will mention
38682the replacement as part of the warning.
38683
38684@kindex maint dump-me
38685@item maint dump-me
721c2651 38686@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38687Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38688This is supported only on systems which support aborting a program
38689with the @code{SIGQUIT} signal.
09d4efe1 38690
8d30a00d
AC
38691@kindex maint internal-error
38692@kindex maint internal-warning
57fcfb1b
GB
38693@kindex maint demangler-warning
38694@cindex demangler crashes
09d4efe1
EZ
38695@item maint internal-error @r{[}@var{message-text}@r{]}
38696@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38697@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38698
38699Cause @value{GDBN} to call the internal function @code{internal_error},
38700@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38701as though an internal problem has been detected. In addition to
57fcfb1b
GB
38702reporting the internal problem, these functions give the user the
38703opportunity to either quit @value{GDBN} or (for @code{internal_error}
38704and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38705@value{GDBN} session.
38706
09d4efe1
EZ
38707These commands take an optional parameter @var{message-text} that is
38708used as the text of the error or warning message.
38709
d3e8051b 38710Here's an example of using @code{internal-error}:
09d4efe1 38711
8d30a00d 38712@smallexample
f7dc1244 38713(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38714@dots{}/maint.c:121: internal-error: testing, 1, 2
38715A problem internal to GDB has been detected. Further
38716debugging may prove unreliable.
38717Quit this debugging session? (y or n) @kbd{n}
38718Create a core file? (y or n) @kbd{n}
f7dc1244 38719(@value{GDBP})
8d30a00d
AC
38720@end smallexample
38721
3c16cced
PA
38722@cindex @value{GDBN} internal error
38723@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38724@cindex demangler crashes
3c16cced
PA
38725
38726@kindex maint set internal-error
38727@kindex maint show internal-error
38728@kindex maint set internal-warning
38729@kindex maint show internal-warning
57fcfb1b
GB
38730@kindex maint set demangler-warning
38731@kindex maint show demangler-warning
3c16cced
PA
38732@item maint set internal-error @var{action} [ask|yes|no]
38733@itemx maint show internal-error @var{action}
38734@itemx maint set internal-warning @var{action} [ask|yes|no]
38735@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38736@itemx maint set demangler-warning @var{action} [ask|yes|no]
38737@itemx maint show demangler-warning @var{action}
3c16cced
PA
38738When @value{GDBN} reports an internal problem (error or warning) it
38739gives the user the opportunity to both quit @value{GDBN} and create a
38740core file of the current @value{GDBN} session. These commands let you
38741override the default behaviour for each particular @var{action},
38742described in the table below.
38743
38744@table @samp
38745@item quit
38746You can specify that @value{GDBN} should always (yes) or never (no)
38747quit. The default is to ask the user what to do.
38748
38749@item corefile
38750You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38751create a core file. The default is to ask the user what to do. Note
38752that there is no @code{corefile} option for @code{demangler-warning}:
38753demangler warnings always create a core file and this cannot be
38754disabled.
3c16cced
PA
38755@end table
38756
09d4efe1
EZ
38757@kindex maint packet
38758@item maint packet @var{text}
38759If @value{GDBN} is talking to an inferior via the serial protocol,
38760then this command sends the string @var{text} to the inferior, and
38761displays the response packet. @value{GDBN} supplies the initial
38762@samp{$} character, the terminating @samp{#} character, and the
38763checksum.
38764
38765@kindex maint print architecture
38766@item maint print architecture @r{[}@var{file}@r{]}
38767Print the entire architecture configuration. The optional argument
38768@var{file} names the file where the output goes.
8d30a00d 38769
ab33b152
AB
38770@kindex maint print c-tdesc
38771@item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
8e2141c6
YQ
38772Print the target description (@pxref{Target Descriptions}) as
38773a C source file. By default, the target description is for the current
38774target, but if the optional argument @var{file} is provided, that file
38775is used to produce the description. The @var{file} should be an XML
38776document, of the form described in @ref{Target Description Format}.
38777The created source file is built into @value{GDBN} when @value{GDBN} is
38778built again. This command is used by developers after they add or
38779modify XML target descriptions.
81adfced 38780
ab33b152
AB
38781When the optional flag @samp{-single-feature} is provided then the
38782target description being processed (either the default, or from
38783@var{file}) must only contain a single feature. The source file
38784produced is different in this case.
38785
caa7fd04
AB
38786@kindex maint print xml-tdesc
38787@item maint print xml-tdesc @r{[}@var{file}@r{]}
38788Print the target description (@pxref{Target Descriptions}) as an XML
38789file. By default print the target description for the current target,
38790but if the optional argument @var{file} is provided, then that file is
38791read in by GDB and then used to produce the description. The
38792@var{file} should be an XML document, of the form described in
38793@ref{Target Description Format}.
38794
27d41eac
YQ
38795@kindex maint check xml-descriptions
38796@item maint check xml-descriptions @var{dir}
38797Check that the target descriptions dynamically created by @value{GDBN}
38798equal the descriptions created from XML files found in @var{dir}.
38799
41fc26a2 38800@anchor{maint check libthread-db}
5045b3d7
GB
38801@kindex maint check libthread-db
38802@item maint check libthread-db
38803Run integrity checks on the current inferior's thread debugging
38804library. This exercises all @code{libthread_db} functionality used by
38805@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38806@code{proc_service} functions provided by @value{GDBN} that
38807@code{libthread_db} uses. Note that parts of the test may be skipped
38808on some platforms when debugging core files.
38809
b089853a
KB
38810@kindex maint print core-file-backed-mappings
38811@cindex memory address space mappings
38812@item maint print core-file-backed-mappings
38813Print the file-backed mappings which were loaded from a core file note.
38814This output represents state internal to @value{GDBN} and should be
38815similar to the mappings displayed by the @code{info proc mappings}
38816command.
38817
00905d52
AC
38818@kindex maint print dummy-frames
38819@item maint print dummy-frames
00905d52
AC
38820Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38821
38822@smallexample
f7dc1244 38823(@value{GDBP}) @kbd{b add}
00905d52 38824@dots{}
f7dc1244 38825(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38826Breakpoint 2, add (a=2, b=3) at @dots{}
3882758 return (a + b);
38828The program being debugged stopped while in a function called from GDB.
38829@dots{}
f7dc1244 38830(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 388310xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38832(@value{GDBP})
00905d52
AC
38833@end smallexample
38834
38835Takes an optional file parameter.
38836
0680b120
AC
38837@kindex maint print registers
38838@kindex maint print raw-registers
38839@kindex maint print cooked-registers
617073a9 38840@kindex maint print register-groups
c21236dc 38841@kindex maint print remote-registers
09d4efe1
EZ
38842@item maint print registers @r{[}@var{file}@r{]}
38843@itemx maint print raw-registers @r{[}@var{file}@r{]}
38844@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38845@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38846@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38847Print @value{GDBN}'s internal register data structures.
38848
617073a9 38849The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38850the raw register cache; the command @code{maint print
38851cooked-registers} includes the (cooked) value of all registers,
38852including registers which aren't available on the target nor visible
38853to user; the command @code{maint print register-groups} includes the
38854groups that each register is a member of; and the command @code{maint
38855print remote-registers} includes the remote target's register numbers
0a7cfe2c 38856and offsets in the `G' packets.
0680b120 38857
09d4efe1
EZ
38858These commands take an optional parameter, a file name to which to
38859write the information.
0680b120 38860
617073a9 38861@kindex maint print reggroups
09d4efe1
EZ
38862@item maint print reggroups @r{[}@var{file}@r{]}
38863Print @value{GDBN}'s internal register group data structures. The
38864optional argument @var{file} tells to what file to write the
38865information.
617073a9 38866
09d4efe1 38867The register groups info looks like this:
617073a9
AC
38868
38869@smallexample
f7dc1244 38870(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38871 Group Type
38872 general user
38873 float user
38874 all user
38875 vector user
38876 system user
38877 save internal
38878 restore internal
617073a9
AC
38879@end smallexample
38880
50a5f187 38881@kindex maint flush register-cache
09d4efe1 38882@kindex flushregs
50a5f187
AB
38883@cindex register cache, flushing
38884@item maint flush register-cache
38885@itemx flushregs
38886Flush the contents of the register cache and as a consequence the
38887frame cache. This command is useful when debugging issues related to
38888register fetching, or frame unwinding. The command @code{flushregs}
38889is deprecated in favor of @code{maint flush register-cache}.
09d4efe1
EZ
38890
38891@kindex maint print objfiles
38892@cindex info for known object files
52e260a3
DE
38893@item maint print objfiles @r{[}@var{regexp}@r{]}
38894Print a dump of all known object files.
38895If @var{regexp} is specified, only print object files whose names
38896match @var{regexp}. For each object file, this command prints its name,
38897address in memory, and all of its psymtabs and symtabs.
09d4efe1 38898
f5b95c01
AA
38899@kindex maint print user-registers
38900@cindex user registers
38901@item maint print user-registers
38902List all currently available @dfn{user registers}. User registers
38903typically provide alternate names for actual hardware registers. They
38904include the four ``standard'' registers @code{$fp}, @code{$pc},
38905@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38906registers can be used in expressions in the same way as the canonical
38907register names, but only the latter are listed by the @code{info
38908registers} and @code{maint print registers} commands.
38909
8a1ea21f
DE
38910@kindex maint print section-scripts
38911@cindex info for known .debug_gdb_scripts-loaded scripts
38912@item maint print section-scripts [@var{regexp}]
38913Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38914If @var{regexp} is specified, only print scripts loaded by object files
38915matching @var{regexp}.
38916For each script, this command prints its name as specified in the objfile,
38917and the full path if known.
8e0583c8 38918@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38919
09d4efe1
EZ
38920@kindex maint print statistics
38921@cindex bcache statistics
38922@item maint print statistics
38923This command prints, for each object file in the program, various data
38924about that object file followed by the byte cache (@dfn{bcache})
38925statistics for the object file. The objfile data includes the number
d3e8051b 38926of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38927defined by the objfile, the number of as yet unexpanded psym tables,
38928the number of line tables and string tables, and the amount of memory
38929used by the various tables. The bcache statistics include the counts,
38930sizes, and counts of duplicates of all and unique objects, max,
38931average, and median entry size, total memory used and its overhead and
38932savings, and various measures of the hash table size and chain
38933lengths.
38934
c7ba131e
JB
38935@kindex maint print target-stack
38936@cindex target stack description
38937@item maint print target-stack
38938A @dfn{target} is an interface between the debugger and a particular
38939kind of file or process. Targets can be stacked in @dfn{strata},
38940so that more than one target can potentially respond to a request.
38941In particular, memory accesses will walk down the stack of targets
38942until they find a target that is interested in handling that particular
38943address.
38944
38945This command prints a short description of each layer that was pushed on
38946the @dfn{target stack}, starting from the top layer down to the bottom one.
38947
09d4efe1
EZ
38948@kindex maint print type
38949@cindex type chain of a data type
38950@item maint print type @var{expr}
38951Print the type chain for a type specified by @var{expr}. The argument
38952can be either a type name or a symbol. If it is a symbol, the type of
38953that symbol is described. The type chain produced by this command is
38954a recursive definition of the data type as stored in @value{GDBN}'s
38955data structures, including its flags and contained types.
38956
dcd1f979
TT
38957@kindex maint selftest
38958@cindex self tests
1526853e 38959@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
38960Run any self tests that were compiled in to @value{GDBN}. This will
38961print a message showing how many tests were run, and how many failed.
1526853e
SM
38962If a @var{filter} is passed, only the tests with @var{filter} in their
38963name will by ran.
38964
3c2fcaf9 38965@kindex maint info selftests
1526853e
SM
38966@cindex self tests
38967@item maint info selftests
38968List the selftests compiled in to @value{GDBN}.
dcd1f979 38969
b4f54984
DE
38970@kindex maint set dwarf always-disassemble
38971@kindex maint show dwarf always-disassemble
38972@item maint set dwarf always-disassemble
38973@item maint show dwarf always-disassemble
9eae7c52
TT
38974Control the behavior of @code{info address} when using DWARF debugging
38975information.
38976
38977The default is @code{off}, which means that @value{GDBN} should try to
38978describe a variable's location in an easily readable format. When
38979@code{on}, @value{GDBN} will instead display the DWARF location
38980expression in an assembly-like format. Note that some locations are
38981too complex for @value{GDBN} to describe simply; in this case you will
38982always see the disassembly form.
38983
38984Here is an example of the resulting disassembly:
38985
38986@smallexample
38987(gdb) info addr argc
38988Symbol "argc" is a complex DWARF expression:
38989 1: DW_OP_fbreg 0
38990@end smallexample
38991
38992For more information on these expressions, see
38993@uref{http://www.dwarfstd.org/, the DWARF standard}.
38994
b4f54984
DE
38995@kindex maint set dwarf max-cache-age
38996@kindex maint show dwarf max-cache-age
38997@item maint set dwarf max-cache-age
38998@itemx maint show dwarf max-cache-age
38999Control the DWARF compilation unit cache.
09d4efe1 39000
b4f54984 39001@cindex DWARF compilation units cache
09d4efe1 39002In object files with inter-compilation-unit references, such as those
b4f54984 39003produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
39004reader needs to frequently refer to previously read compilation units.
39005This setting controls how long a compilation unit will remain in the
39006cache if it is not referenced. A higher limit means that cached
39007compilation units will be stored in memory longer, and more total
39008memory will be used. Setting it to zero disables caching, which will
39009slow down @value{GDBN} startup, but reduce memory consumption.
39010
3c3bb058
AB
39011@kindex maint set dwarf unwinders
39012@kindex maint show dwarf unwinders
39013@item maint set dwarf unwinders
39014@itemx maint show dwarf unwinders
39015Control use of the DWARF frame unwinders.
39016
39017@cindex DWARF frame unwinders
39018Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39019frame unwinders to build the backtrace. Many of these targets will
39020also have a second mechanism for building the backtrace for use in
39021cases where DWARF information is not available, this second mechanism
39022is often an analysis of a function's prologue.
39023
39024In order to extend testing coverage of the second level stack
39025unwinding mechanisms it is helpful to be able to disable the DWARF
39026stack unwinders, this can be done with this switch.
39027
39028In normal use of @value{GDBN} disabling the DWARF unwinders is not
39029advisable, there are cases that are better handled through DWARF than
39030prologue analysis, and the debug experience is likely to be better
39031with the DWARF frame unwinders enabled.
39032
39033If DWARF frame unwinders are not supported for a particular target
39034architecture, then enabling this flag does not cause them to be used.
22138db6
TT
39035
39036@kindex maint set worker-threads
39037@kindex maint show worker-threads
39038@item maint set worker-threads
39039@item maint show worker-threads
39040Control the number of worker threads that may be used by @value{GDBN}.
39041On capable hosts, @value{GDBN} may use multiple threads to speed up
39042certain CPU-intensive operations, such as demangling symbol names.
39043While the number of threads used by @value{GDBN} may vary, this
39044command can be used to set an upper bound on this number. The default
39045is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39046number. Note that this only controls worker threads started by
39047@value{GDBN} itself; libraries used by @value{GDBN} may start threads
39048of their own.
39049
e7ba9c65
DJ
39050@kindex maint set profile
39051@kindex maint show profile
39052@cindex profiling GDB
39053@item maint set profile
39054@itemx maint show profile
39055Control profiling of @value{GDBN}.
39056
39057Profiling will be disabled until you use the @samp{maint set profile}
39058command to enable it. When you enable profiling, the system will begin
39059collecting timing and execution count data; when you disable profiling or
39060exit @value{GDBN}, the results will be written to a log file. Remember that
39061if you use profiling, @value{GDBN} will overwrite the profiling log file
39062(often called @file{gmon.out}). If you have a record of important profiling
39063data in a @file{gmon.out} file, be sure to move it to a safe location.
39064
39065Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 39066compiled with the @samp{-pg} compiler option.
e7ba9c65 39067
cbe54154
PA
39068@kindex maint set show-debug-regs
39069@kindex maint show show-debug-regs
eac35c4e 39070@cindex hardware debug registers
cbe54154
PA
39071@item maint set show-debug-regs
39072@itemx maint show show-debug-regs
eac35c4e 39073Control whether to show variables that mirror the hardware debug
6dd315ba 39074registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 39075enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
39076removes a hardware breakpoint or watchpoint, and when the inferior
39077triggers a hardware-assisted breakpoint or watchpoint.
39078
711e434b
PM
39079@kindex maint set show-all-tib
39080@kindex maint show show-all-tib
39081@item maint set show-all-tib
39082@itemx maint show show-all-tib
39083Control whether to show all non zero areas within a 1k block starting
39084at thread local base, when using the @samp{info w32 thread-information-block}
39085command.
39086
329ea579
PA
39087@kindex maint set target-async
39088@kindex maint show target-async
39089@item maint set target-async
39090@itemx maint show target-async
39091This controls whether @value{GDBN} targets operate in synchronous or
39092asynchronous mode (@pxref{Background Execution}). Normally the
39093default is asynchronous, if it is available; but this can be changed
39094to more easily debug problems occurring only in synchronous mode.
39095
fbea99ea
PA
39096@kindex maint set target-non-stop @var{mode} [on|off|auto]
39097@kindex maint show target-non-stop
39098@item maint set target-non-stop
39099@itemx maint show target-non-stop
39100
39101This controls whether @value{GDBN} targets always operate in non-stop
39102mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39103Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39104if supported by the target.
39105
39106@table @code
39107@item maint set target-non-stop auto
39108This is the default mode. @value{GDBN} controls the target in
39109non-stop mode if the target supports it.
39110
39111@item maint set target-non-stop on
39112@value{GDBN} controls the target in non-stop mode even if the target
39113does not indicate support.
39114
39115@item maint set target-non-stop off
39116@value{GDBN} does not control the target in non-stop mode even if the
39117target supports it.
39118@end table
39119
45e42163
TT
39120@kindex maint set tui-resize-message
39121@kindex maint show tui-resize-message
39122@item maint set tui-resize-message
39123@item maint show tui-resize-message
39124Control whether @value{GDBN} displays a message each time the terminal
39125is resized when in TUI mode. The default is @code{off}, which means
39126that @value{GDBN} is silent during resizes. When @code{on},
39127@value{GDBN} will display a message after a resize is completed; the
39128message will include a number indicating how many times the terminal
39129has been resized. This setting is intended for use by the test suite,
39130where it would otherwise be difficult to determine when a resize and
39131refresh has been completed.
39132
bd712aed
DE
39133@kindex maint set per-command
39134@kindex maint show per-command
39135@item maint set per-command
39136@itemx maint show per-command
39137@cindex resources used by commands
09d4efe1 39138
bd712aed
DE
39139@value{GDBN} can display the resources used by each command.
39140This is useful in debugging performance problems.
39141
39142@table @code
39143@item maint set per-command space [on|off]
39144@itemx maint show per-command space
39145Enable or disable the printing of the memory used by GDB for each command.
39146If enabled, @value{GDBN} will display how much memory each command
39147took, following the command's own output.
39148This can also be requested by invoking @value{GDBN} with the
39149@option{--statistics} command-line switch (@pxref{Mode Options}).
39150
39151@item maint set per-command time [on|off]
39152@itemx maint show per-command time
39153Enable or disable the printing of the execution time of @value{GDBN}
39154for each command.
39155If enabled, @value{GDBN} will display how much time it
09d4efe1 39156took to execute each command, following the command's own output.
0a1c4d10
DE
39157Both CPU time and wallclock time are printed.
39158Printing both is useful when trying to determine whether the cost is
bd712aed 39159CPU or, e.g., disk/network latency.
0a1c4d10
DE
39160Note that the CPU time printed is for @value{GDBN} only, it does not include
39161the execution time of the inferior because there's no mechanism currently
39162to compute how much time was spent by @value{GDBN} and how much time was
39163spent by the program been debugged.
09d4efe1
EZ
39164This can also be requested by invoking @value{GDBN} with the
39165@option{--statistics} command-line switch (@pxref{Mode Options}).
39166
bd712aed
DE
39167@item maint set per-command symtab [on|off]
39168@itemx maint show per-command symtab
39169Enable or disable the printing of basic symbol table statistics
39170for each command.
39171If enabled, @value{GDBN} will display the following information:
39172
215b9f98
EZ
39173@enumerate a
39174@item
39175number of symbol tables
39176@item
39177number of primary symbol tables
39178@item
39179number of blocks in the blockvector
39180@end enumerate
bd712aed
DE
39181@end table
39182
5045b3d7
GB
39183@kindex maint set check-libthread-db
39184@kindex maint show check-libthread-db
39185@item maint set check-libthread-db [on|off]
39186@itemx maint show check-libthread-db
39187Control whether @value{GDBN} should run integrity checks on inferior
39188specific thread debugging libraries as they are loaded. The default
39189is not to perform such checks. If any check fails @value{GDBN} will
39190unload the library and continue searching for a suitable candidate as
39191described in @ref{set libthread-db-search-path}. For more information
39192about the tests, see @ref{maint check libthread-db}.
39193
bd712aed
DE
39194@kindex maint space
39195@cindex memory used by commands
39196@item maint space @var{value}
39197An alias for @code{maint set per-command space}.
39198A non-zero value enables it, zero disables it.
39199
39200@kindex maint time
39201@cindex time of command execution
39202@item maint time @var{value}
39203An alias for @code{maint set per-command time}.
39204A non-zero value enables it, zero disables it.
39205
09d4efe1
EZ
39206@kindex maint translate-address
39207@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39208Find the symbol stored at the location specified by the address
39209@var{addr} and an optional section name @var{section}. If found,
39210@value{GDBN} prints the name of the closest symbol and an offset from
39211the symbol's location to the specified address. This is similar to
39212the @code{info address} command (@pxref{Symbols}), except that this
39213command also allows to find symbols in other sections.
ae038cb0 39214
c14c28ba
PP
39215If section was not specified, the section in which the symbol was found
39216is also printed. For dynamically linked executables, the name of
39217executable or shared library containing the symbol is printed as well.
39218
3345721a
PA
39219@kindex maint test-options
39220@item maint test-options require-delimiter
39221@itemx maint test-options unknown-is-error
39222@itemx maint test-options unknown-is-operand
39223These commands are used by the testsuite to validate the command
39224options framework. The @code{require-delimiter} variant requires a
39225double-dash delimiter to indicate end of options. The
39226@code{unknown-is-error} and @code{unknown-is-operand} do not. The
39227@code{unknown-is-error} variant throws an error on unknown option,
39228while @code{unknown-is-operand} treats unknown options as the start of
39229the command's operands. When run, the commands output the result of
39230the processed options. When completed, the commands store the
39231internal result of completion in a variable exposed by the @code{maint
39232show test-options-completion-result} command.
39233
39234@kindex maint show test-options-completion-result
39235@item maint show test-options-completion-result
39236Shows the result of completing the @code{maint test-options}
39237subcommands. This is used by the testsuite to validate completion
39238support in the command options framework.
39239
c6ac8931
PA
39240@kindex maint set test-settings
39241@kindex maint show test-settings
39242@item maint set test-settings @var{kind}
39243@itemx maint show test-settings @var{kind}
dca0f6c0
PA
39244These are representative commands for each @var{kind} of setting type
39245@value{GDBN} supports. They are used by the testsuite for exercising
39246the settings infrastructure.
fdbc9870
PA
39247
39248@kindex maint with
39249@item maint with @var{setting} [@var{value}] [-- @var{command}]
39250Like the @code{with} command, but works with @code{maintenance set}
39251variables. This is used by the testsuite to exercise the @code{with}
39252command's infrastructure.
39253
8e04817f 39254@end table
c906108c 39255
9c16f35a
EZ
39256The following command is useful for non-interactive invocations of
39257@value{GDBN}, such as in the test suite.
39258
39259@table @code
39260@item set watchdog @var{nsec}
39261@kindex set watchdog
39262@cindex watchdog timer
39263@cindex timeout for commands
39264Set the maximum number of seconds @value{GDBN} will wait for the
39265target operation to finish. If this time expires, @value{GDBN}
39266reports and error and the command is aborted.
39267
39268@item show watchdog
39269Show the current setting of the target wait timeout.
39270@end table
c906108c 39271
e0ce93ac 39272@node Remote Protocol
8e04817f 39273@appendix @value{GDBN} Remote Serial Protocol
c906108c 39274
ee2d5c50
AC
39275@menu
39276* Overview::
39277* Packets::
39278* Stop Reply Packets::
39279* General Query Packets::
a1dcb23a 39280* Architecture-Specific Protocol Details::
9d29849a 39281* Tracepoint Packets::
a6b151f1 39282* Host I/O Packets::
9a6253be 39283* Interrupts::
8b23ecc4
SL
39284* Notification Packets::
39285* Remote Non-Stop::
a6f3e723 39286* Packet Acknowledgment::
ee2d5c50 39287* Examples::
79a6e687 39288* File-I/O Remote Protocol Extension::
cfa9d6d9 39289* Library List Format::
2268b414 39290* Library List Format for SVR4 Targets::
79a6e687 39291* Memory Map Format::
dc146f7c 39292* Thread List Format::
b3b9301e 39293* Traceframe Info Format::
2ae8c8e7 39294* Branch Trace Format::
f4abbc16 39295* Branch Trace Configuration Format::
ee2d5c50
AC
39296@end menu
39297
39298@node Overview
39299@section Overview
39300
8e04817f
AC
39301There may be occasions when you need to know something about the
39302protocol---for example, if there is only one serial port to your target
39303machine, you might want your program to do something special if it
39304recognizes a packet meant for @value{GDBN}.
c906108c 39305
d2c6833e 39306In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 39307transmitted and received data, respectively.
c906108c 39308
8e04817f
AC
39309@cindex protocol, @value{GDBN} remote serial
39310@cindex serial protocol, @value{GDBN} remote
39311@cindex remote serial protocol
8b23ecc4
SL
39312All @value{GDBN} commands and responses (other than acknowledgments
39313and notifications, see @ref{Notification Packets}) are sent as a
39314@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
39315@samp{$}, the actual @var{packet-data}, and the terminating character
39316@samp{#} followed by a two-digit @var{checksum}:
c906108c 39317
474c8240 39318@smallexample
8e04817f 39319@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 39320@end smallexample
8e04817f 39321@noindent
c906108c 39322
8e04817f
AC
39323@cindex checksum, for @value{GDBN} remote
39324@noindent
39325The two-digit @var{checksum} is computed as the modulo 256 sum of all
39326characters between the leading @samp{$} and the trailing @samp{#} (an
39327eight bit unsigned checksum).
c906108c 39328
8e04817f
AC
39329Implementors should note that prior to @value{GDBN} 5.0 the protocol
39330specification also included an optional two-digit @var{sequence-id}:
c906108c 39331
474c8240 39332@smallexample
8e04817f 39333@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 39334@end smallexample
c906108c 39335
8e04817f
AC
39336@cindex sequence-id, for @value{GDBN} remote
39337@noindent
39338That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39339has never output @var{sequence-id}s. Stubs that handle packets added
39340since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 39341
8e04817f
AC
39342When either the host or the target machine receives a packet, the first
39343response expected is an acknowledgment: either @samp{+} (to indicate
39344the package was received correctly) or @samp{-} (to request
39345retransmission):
c906108c 39346
474c8240 39347@smallexample
d2c6833e
AC
39348-> @code{$}@var{packet-data}@code{#}@var{checksum}
39349<- @code{+}
474c8240 39350@end smallexample
8e04817f 39351@noindent
53a5351d 39352
a6f3e723
SL
39353The @samp{+}/@samp{-} acknowledgments can be disabled
39354once a connection is established.
39355@xref{Packet Acknowledgment}, for details.
39356
8e04817f
AC
39357The host (@value{GDBN}) sends @var{command}s, and the target (the
39358debugging stub incorporated in your program) sends a @var{response}. In
39359the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
39360when the operation has completed, and the target has again stopped all
39361threads in all attached processes. This is the default all-stop mode
39362behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39363execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 39364
8e04817f
AC
39365@var{packet-data} consists of a sequence of characters with the
39366exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39367exceptions).
c906108c 39368
ee2d5c50 39369@cindex remote protocol, field separator
0876f84a 39370Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 39371@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 39372@sc{hex} with leading zeros suppressed.
c906108c 39373
8e04817f
AC
39374Implementors should note that prior to @value{GDBN} 5.0, the character
39375@samp{:} could not appear as the third character in a packet (as it
39376would potentially conflict with the @var{sequence-id}).
c906108c 39377
0876f84a
DJ
39378@cindex remote protocol, binary data
39379@anchor{Binary Data}
39380Binary data in most packets is encoded either as two hexadecimal
39381digits per byte of binary data. This allowed the traditional remote
39382protocol to work over connections which were only seven-bit clean.
39383Some packets designed more recently assume an eight-bit clean
39384connection, and use a more efficient encoding to send and receive
39385binary data.
39386
39387The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39388as an escape character. Any escaped byte is transmitted as the escape
39389character followed by the original character XORed with @code{0x20}.
39390For example, the byte @code{0x7d} would be transmitted as the two
39391bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39392@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39393@samp{@}}) must always be escaped. Responses sent by the stub
39394must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39395is not interpreted as the start of a run-length encoded sequence
39396(described next).
39397
1d3811f6
DJ
39398Response @var{data} can be run-length encoded to save space.
39399Run-length encoding replaces runs of identical characters with one
39400instance of the repeated character, followed by a @samp{*} and a
39401repeat count. The repeat count is itself sent encoded, to avoid
39402binary characters in @var{data}: a value of @var{n} is sent as
39403@code{@var{n}+29}. For a repeat count greater or equal to 3, this
39404produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39405code 32) for a repeat count of 3. (This is because run-length
39406encoding starts to win for counts 3 or more.) Thus, for example,
39407@samp{0* } is a run-length encoding of ``0000'': the space character
39408after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
394093}} more times.
39410
39411The printable characters @samp{#} and @samp{$} or with a numeric value
39412greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39413seven repeats (@samp{$}) can be expanded using a repeat count of only
39414five (@samp{"}). For example, @samp{00000000} can be encoded as
39415@samp{0*"00}.
c906108c 39416
8e04817f
AC
39417The error response returned for some packets includes a two character
39418error number. That number is not well defined.
c906108c 39419
f8da2bff 39420@cindex empty response, for unsupported packets
8e04817f
AC
39421For any @var{command} not supported by the stub, an empty response
39422(@samp{$#00}) should be returned. That way it is possible to extend the
39423protocol. A newer @value{GDBN} can tell if a packet is supported based
39424on that response.
c906108c 39425
c9fe1b58
RT
39426At a minimum, a stub is required to support the @samp{?} command to
39427tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
393eab54
PA
39428commands for register access, and the @samp{m} and @samp{M} commands
39429for memory access. Stubs that only control single-threaded targets
c9fe1b58
RT
39430can implement run control with the @samp{c} (continue) command, and if
39431the target architecture supports hardware-assisted single-stepping,
39432the @samp{s} (step) command. Stubs that support multi-threading
39433targets should support the @samp{vCont} command. All other commands
39434are optional.
c906108c 39435
ee2d5c50
AC
39436@node Packets
39437@section Packets
39438
39439The following table provides a complete list of all currently defined
39440@var{command}s and their corresponding response @var{data}.
79a6e687 39441@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 39442I/O extension of the remote protocol.
ee2d5c50 39443
b8ff78ce
JB
39444Each packet's description has a template showing the packet's overall
39445syntax, followed by an explanation of the packet's meaning. We
39446include spaces in some of the templates for clarity; these are not
39447part of the packet's syntax. No @value{GDBN} packet uses spaces to
39448separate its components. For example, a template like @samp{foo
39449@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39450bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 39451@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
39452@samp{foo} and the @var{bar}, or between the @var{bar} and the
39453@var{baz}.
39454
b90a069a
SL
39455@cindex @var{thread-id}, in remote protocol
39456@anchor{thread-id syntax}
39457Several packets and replies include a @var{thread-id} field to identify
39458a thread. Normally these are positive numbers with a target-specific
39459interpretation, formatted as big-endian hex strings. A @var{thread-id}
39460can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39461pick any thread.
39462
39463In addition, the remote protocol supports a multiprocess feature in
39464which the @var{thread-id} syntax is extended to optionally include both
39465process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39466The @var{pid} (process) and @var{tid} (thread) components each have the
39467format described above: a positive number with target-specific
39468interpretation formatted as a big-endian hex string, literal @samp{-1}
39469to indicate all processes or threads (respectively), or @samp{0} to
39470indicate an arbitrary process or thread. Specifying just a process, as
39471@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39472error to specify all processes but a specific thread, such as
39473@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39474for those packets and replies explicitly documented to include a process
39475ID, rather than a @var{thread-id}.
39476
39477The multiprocess @var{thread-id} syntax extensions are only used if both
39478@value{GDBN} and the stub report support for the @samp{multiprocess}
39479feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39480more information.
39481
8ffe2530
JB
39482Note that all packet forms beginning with an upper- or lower-case
39483letter, other than those described here, are reserved for future use.
39484
b8ff78ce 39485Here are the packet descriptions.
ee2d5c50 39486
b8ff78ce 39487@table @samp
ee2d5c50 39488
b8ff78ce
JB
39489@item !
39490@cindex @samp{!} packet
2d717e4f 39491@anchor{extended mode}
8e04817f
AC
39492Enable extended mode. In extended mode, the remote server is made
39493persistent. The @samp{R} packet is used to restart the program being
39494debugged.
ee2d5c50
AC
39495
39496Reply:
39497@table @samp
39498@item OK
8e04817f 39499The remote target both supports and has enabled extended mode.
ee2d5c50 39500@end table
c906108c 39501
b8ff78ce
JB
39502@item ?
39503@cindex @samp{?} packet
36cb1214 39504@anchor{? packet}
ee2d5c50 39505Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
39506step and continue. This packet has a special interpretation when the
39507target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 39508
ee2d5c50
AC
39509Reply:
39510@xref{Stop Reply Packets}, for the reply specifications.
39511
b8ff78ce
JB
39512@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39513@cindex @samp{A} packet
39514Initialized @code{argv[]} array passed into program. @var{arglen}
39515specifies the number of bytes in the hex encoded byte stream
39516@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
39517
39518Reply:
39519@table @samp
39520@item OK
b8ff78ce
JB
39521The arguments were set.
39522@item E @var{NN}
39523An error occurred.
ee2d5c50
AC
39524@end table
39525
b8ff78ce
JB
39526@item b @var{baud}
39527@cindex @samp{b} packet
39528(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39529Change the serial line speed to @var{baud}.
39530
39531JTC: @emph{When does the transport layer state change? When it's
39532received, or after the ACK is transmitted. In either case, there are
39533problems if the command or the acknowledgment packet is dropped.}
39534
39535Stan: @emph{If people really wanted to add something like this, and get
39536it working for the first time, they ought to modify ser-unix.c to send
39537some kind of out-of-band message to a specially-setup stub and have the
39538switch happen "in between" packets, so that from remote protocol's point
39539of view, nothing actually happened.}
39540
b8ff78ce
JB
39541@item B @var{addr},@var{mode}
39542@cindex @samp{B} packet
8e04817f 39543Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39544breakpoint at @var{addr}.
39545
b8ff78ce 39546Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39547(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39548
bacec72f 39549@cindex @samp{bc} packet
0d772ac9
MS
39550@anchor{bc}
39551@item bc
bacec72f
MS
39552Backward continue. Execute the target system in reverse. No parameter.
39553@xref{Reverse Execution}, for more information.
39554
39555Reply:
39556@xref{Stop Reply Packets}, for the reply specifications.
39557
bacec72f 39558@cindex @samp{bs} packet
0d772ac9
MS
39559@anchor{bs}
39560@item bs
bacec72f
MS
39561Backward single step. Execute one instruction in reverse. No parameter.
39562@xref{Reverse Execution}, for more information.
39563
39564Reply:
39565@xref{Stop Reply Packets}, for the reply specifications.
39566
4f553f88 39567@item c @r{[}@var{addr}@r{]}
b8ff78ce 39568@cindex @samp{c} packet
697aa1b7
EZ
39569Continue at @var{addr}, which is the address to resume. If @var{addr}
39570is omitted, resume at current address.
c906108c 39571
393eab54
PA
39572This packet is deprecated for multi-threading support. @xref{vCont
39573packet}.
39574
ee2d5c50
AC
39575Reply:
39576@xref{Stop Reply Packets}, for the reply specifications.
39577
4f553f88 39578@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39579@cindex @samp{C} packet
8e04817f 39580Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39581@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39582
393eab54
PA
39583This packet is deprecated for multi-threading support. @xref{vCont
39584packet}.
39585
ee2d5c50
AC
39586Reply:
39587@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39588
b8ff78ce
JB
39589@item d
39590@cindex @samp{d} packet
ee2d5c50
AC
39591Toggle debug flag.
39592
b8ff78ce
JB
39593Don't use this packet; instead, define a general set packet
39594(@pxref{General Query Packets}).
ee2d5c50 39595
b8ff78ce 39596@item D
b90a069a 39597@itemx D;@var{pid}
b8ff78ce 39598@cindex @samp{D} packet
b90a069a
SL
39599The first form of the packet is used to detach @value{GDBN} from the
39600remote system. It is sent to the remote target
07f31aa6 39601before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39602
b90a069a
SL
39603The second form, including a process ID, is used when multiprocess
39604protocol extensions are enabled (@pxref{multiprocess extensions}), to
39605detach only a specific process. The @var{pid} is specified as a
39606big-endian hex string.
39607
ee2d5c50
AC
39608Reply:
39609@table @samp
10fac096
NW
39610@item OK
39611for success
b8ff78ce 39612@item E @var{NN}
10fac096 39613for an error
ee2d5c50 39614@end table
c906108c 39615
b8ff78ce
JB
39616@item F @var{RC},@var{EE},@var{CF};@var{XX}
39617@cindex @samp{F} packet
39618A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39619This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39620Remote Protocol Extension}, for the specification.
ee2d5c50 39621
b8ff78ce 39622@item g
ee2d5c50 39623@anchor{read registers packet}
b8ff78ce 39624@cindex @samp{g} packet
ee2d5c50
AC
39625Read general registers.
39626
39627Reply:
39628@table @samp
39629@item @var{XX@dots{}}
8e04817f
AC
39630Each byte of register data is described by two hex digits. The bytes
39631with the register are transmitted in target byte order. The size of
b8ff78ce 39632each register and their position within the @samp{g} packet are
4a9bb1df 39633determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39634@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39635
39636When reading registers from a trace frame (@pxref{Analyze Collected
39637Data,,Using the Collected Data}), the stub may also return a string of
39638literal @samp{x}'s in place of the register data digits, to indicate
39639that the corresponding register has not been collected, thus its value
39640is unavailable. For example, for an architecture with 4 registers of
396414 bytes each, the following reply indicates to @value{GDBN} that
39642registers 0 and 2 have not been collected, while registers 1 and 3
39643have been collected, and both have zero value:
39644
39645@smallexample
39646-> @code{g}
39647<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39648@end smallexample
39649
b8ff78ce 39650@item E @var{NN}
ee2d5c50
AC
39651for an error.
39652@end table
c906108c 39653
b8ff78ce
JB
39654@item G @var{XX@dots{}}
39655@cindex @samp{G} packet
39656Write general registers. @xref{read registers packet}, for a
39657description of the @var{XX@dots{}} data.
ee2d5c50
AC
39658
39659Reply:
39660@table @samp
39661@item OK
39662for success
b8ff78ce 39663@item E @var{NN}
ee2d5c50
AC
39664for an error
39665@end table
39666
393eab54 39667@item H @var{op} @var{thread-id}
b8ff78ce 39668@cindex @samp{H} packet
8e04817f 39669Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39670@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39671should be @samp{c} for step and continue operations (note that this
393eab54 39672is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39673option), and @samp{g} for other operations. The thread designator
393eab54
PA
39674@var{thread-id} has the format and interpretation described in
39675@ref{thread-id syntax}.
ee2d5c50
AC
39676
39677Reply:
39678@table @samp
39679@item OK
39680for success
b8ff78ce 39681@item E @var{NN}
ee2d5c50
AC
39682for an error
39683@end table
c906108c 39684
8e04817f
AC
39685@c FIXME: JTC:
39686@c 'H': How restrictive (or permissive) is the thread model. If a
39687@c thread is selected and stopped, are other threads allowed
39688@c to continue to execute? As I mentioned above, I think the
39689@c semantics of each command when a thread is selected must be
39690@c described. For example:
39691@c
39692@c 'g': If the stub supports threads and a specific thread is
39693@c selected, returns the register block from that thread;
39694@c otherwise returns current registers.
39695@c
39696@c 'G' If the stub supports threads and a specific thread is
39697@c selected, sets the registers of the register block of
39698@c that thread; otherwise sets current registers.
c906108c 39699
b8ff78ce 39700@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39701@anchor{cycle step packet}
b8ff78ce
JB
39702@cindex @samp{i} packet
39703Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39704present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39705step starting at that address.
c906108c 39706
b8ff78ce
JB
39707@item I
39708@cindex @samp{I} packet
39709Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39710step packet}.
ee2d5c50 39711
b8ff78ce
JB
39712@item k
39713@cindex @samp{k} packet
39714Kill request.
c906108c 39715
36cb1214
HZ
39716The exact effect of this packet is not specified.
39717
39718For a bare-metal target, it may power cycle or reset the target
39719system. For that reason, the @samp{k} packet has no reply.
39720
39721For a single-process target, it may kill that process if possible.
39722
39723A multiple-process target may choose to kill just one process, or all
39724that are under @value{GDBN}'s control. For more precise control, use
39725the vKill packet (@pxref{vKill packet}).
39726
39727If the target system immediately closes the connection in response to
39728@samp{k}, @value{GDBN} does not consider the lack of packet
39729acknowledgment to be an error, and assumes the kill was successful.
39730
39731If connected using @kbd{target extended-remote}, and the target does
39732not close the connection in response to a kill request, @value{GDBN}
39733probes the target state as if a new connection was opened
39734(@pxref{? packet}).
c906108c 39735
b8ff78ce
JB
39736@item m @var{addr},@var{length}
39737@cindex @samp{m} packet
a86c90e6
SM
39738Read @var{length} addressable memory units starting at address @var{addr}
39739(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39740any particular boundary.
fb031cdf
JB
39741
39742The stub need not use any particular size or alignment when gathering
39743data from memory for the response; even if @var{addr} is word-aligned
39744and @var{length} is a multiple of the word size, the stub is free to
39745use byte accesses, or not. For this reason, this packet may not be
39746suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39747@cindex alignment of remote memory accesses
39748@cindex size of remote memory accesses
39749@cindex memory, alignment and size of remote accesses
c906108c 39750
ee2d5c50
AC
39751Reply:
39752@table @samp
39753@item @var{XX@dots{}}
a86c90e6
SM
39754Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39755The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39756server was able to read only part of the region of memory.
39757@item E @var{NN}
ee2d5c50
AC
39758@var{NN} is errno
39759@end table
39760
b8ff78ce
JB
39761@item M @var{addr},@var{length}:@var{XX@dots{}}
39762@cindex @samp{M} packet
a86c90e6
SM
39763Write @var{length} addressable memory units starting at address @var{addr}
39764(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39765byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39766
39767Reply:
39768@table @samp
39769@item OK
39770for success
b8ff78ce 39771@item E @var{NN}
8e04817f
AC
39772for an error (this includes the case where only part of the data was
39773written).
ee2d5c50 39774@end table
c906108c 39775
b8ff78ce
JB
39776@item p @var{n}
39777@cindex @samp{p} packet
39778Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39779@xref{read registers packet}, for a description of how the returned
39780register value is encoded.
ee2d5c50
AC
39781
39782Reply:
39783@table @samp
2e868123
AC
39784@item @var{XX@dots{}}
39785the register's value
b8ff78ce 39786@item E @var{NN}
2e868123 39787for an error
d57350ea 39788@item @w{}
2e868123 39789Indicating an unrecognized @var{query}.
ee2d5c50
AC
39790@end table
39791
b8ff78ce 39792@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39793@anchor{write register packet}
b8ff78ce
JB
39794@cindex @samp{P} packet
39795Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39796number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39797digits for each byte in the register (target byte order).
c906108c 39798
ee2d5c50
AC
39799Reply:
39800@table @samp
39801@item OK
39802for success
b8ff78ce 39803@item E @var{NN}
ee2d5c50
AC
39804for an error
39805@end table
39806
5f3bebba
JB
39807@item q @var{name} @var{params}@dots{}
39808@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39809@cindex @samp{q} packet
b8ff78ce 39810@cindex @samp{Q} packet
5f3bebba
JB
39811General query (@samp{q}) and set (@samp{Q}). These packets are
39812described fully in @ref{General Query Packets}.
c906108c 39813
b8ff78ce
JB
39814@item r
39815@cindex @samp{r} packet
8e04817f 39816Reset the entire system.
c906108c 39817
b8ff78ce 39818Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39819
b8ff78ce
JB
39820@item R @var{XX}
39821@cindex @samp{R} packet
697aa1b7 39822Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39823This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39824
8e04817f 39825The @samp{R} packet has no reply.
ee2d5c50 39826
4f553f88 39827@item s @r{[}@var{addr}@r{]}
b8ff78ce 39828@cindex @samp{s} packet
697aa1b7 39829Single step, resuming at @var{addr}. If
b8ff78ce 39830@var{addr} is omitted, resume at same address.
c906108c 39831
393eab54
PA
39832This packet is deprecated for multi-threading support. @xref{vCont
39833packet}.
39834
ee2d5c50
AC
39835Reply:
39836@xref{Stop Reply Packets}, for the reply specifications.
39837
4f553f88 39838@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39839@anchor{step with signal packet}
b8ff78ce
JB
39840@cindex @samp{S} packet
39841Step with signal. This is analogous to the @samp{C} packet, but
39842requests a single-step, rather than a normal resumption of execution.
c906108c 39843
393eab54
PA
39844This packet is deprecated for multi-threading support. @xref{vCont
39845packet}.
39846
ee2d5c50
AC
39847Reply:
39848@xref{Stop Reply Packets}, for the reply specifications.
39849
b8ff78ce
JB
39850@item t @var{addr}:@var{PP},@var{MM}
39851@cindex @samp{t} packet
8e04817f 39852Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39853@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39854There must be at least 3 digits in @var{addr}.
c906108c 39855
b90a069a 39856@item T @var{thread-id}
b8ff78ce 39857@cindex @samp{T} packet
b90a069a 39858Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39859
ee2d5c50
AC
39860Reply:
39861@table @samp
39862@item OK
39863thread is still alive
b8ff78ce 39864@item E @var{NN}
ee2d5c50
AC
39865thread is dead
39866@end table
39867
b8ff78ce
JB
39868@item v
39869Packets starting with @samp{v} are identified by a multi-letter name,
39870up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39871
2d717e4f
DJ
39872@item vAttach;@var{pid}
39873@cindex @samp{vAttach} packet
8b23ecc4
SL
39874Attach to a new process with the specified process ID @var{pid}.
39875The process ID is a
39876hexadecimal integer identifying the process. In all-stop mode, all
39877threads in the attached process are stopped; in non-stop mode, it may be
39878attached without being stopped if that is supported by the target.
39879
39880@c In non-stop mode, on a successful vAttach, the stub should set the
39881@c current thread to a thread of the newly-attached process. After
39882@c attaching, GDB queries for the attached process's thread ID with qC.
39883@c Also note that, from a user perspective, whether or not the
39884@c target is stopped on attach in non-stop mode depends on whether you
39885@c use the foreground or background version of the attach command, not
39886@c on what vAttach does; GDB does the right thing with respect to either
39887@c stopping or restarting threads.
2d717e4f
DJ
39888
39889This packet is only available in extended mode (@pxref{extended mode}).
39890
39891Reply:
39892@table @samp
39893@item E @var{nn}
39894for an error
39895@item @r{Any stop packet}
8b23ecc4
SL
39896for success in all-stop mode (@pxref{Stop Reply Packets})
39897@item OK
39898for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39899@end table
39900
b90a069a 39901@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39902@cindex @samp{vCont} packet
393eab54 39903@anchor{vCont packet}
b8ff78ce 39904Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39905
39906For each inferior thread, the leftmost action with a matching
39907@var{thread-id} is applied. Threads that don't match any action
39908remain in their current state. Thread IDs are specified using the
39909syntax described in @ref{thread-id syntax}. If multiprocess
39910extensions (@pxref{multiprocess extensions}) are supported, actions
39911can be specified to match all threads in a process by using the
39912@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39913@var{thread-id} matches all threads. Specifying no actions is an
39914error.
b90a069a
SL
39915
39916Currently supported actions are:
86d30acc 39917
b8ff78ce 39918@table @samp
86d30acc
DJ
39919@item c
39920Continue.
b8ff78ce 39921@item C @var{sig}
8b23ecc4 39922Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39923@item s
39924Step.
b8ff78ce 39925@item S @var{sig}
8b23ecc4
SL
39926Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39927@item t
39928Stop.
c1e36e3e
PA
39929@item r @var{start},@var{end}
39930Step once, and then keep stepping as long as the thread stops at
39931addresses between @var{start} (inclusive) and @var{end} (exclusive).
39932The remote stub reports a stop reply when either the thread goes out
39933of the range or is stopped due to an unrelated reason, such as hitting
39934a breakpoint. @xref{range stepping}.
39935
39936If the range is empty (@var{start} == @var{end}), then the action
39937becomes equivalent to the @samp{s} action. In other words,
39938single-step once, and report the stop (even if the stepped instruction
39939jumps to @var{start}).
39940
39941(A stop reply may be sent at any point even if the PC is still within
39942the stepping range; for example, it is valid to implement this packet
39943in a degenerate way as a single instruction step operation.)
39944
86d30acc
DJ
39945@end table
39946
8b23ecc4
SL
39947The optional argument @var{addr} normally associated with the
39948@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39949not supported in @samp{vCont}.
86d30acc 39950
08a0efd0
PA
39951The @samp{t} action is only relevant in non-stop mode
39952(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39953A stop reply should be generated for any affected thread not already stopped.
39954When a thread is stopped by means of a @samp{t} action,
39955the corresponding stop reply should indicate that the thread has stopped with
39956signal @samp{0}, regardless of whether the target uses some other signal
39957as an implementation detail.
39958
ca6eff59
PA
39959The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39960@samp{r} actions for threads that are already running. Conversely,
39961the server must ignore @samp{t} actions for threads that are already
39962stopped.
39963
39964@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 39965@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
39966the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39967
4220b2f8 39968The stub must support @samp{vCont} if it reports support for
ca6eff59 39969multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 39970
86d30acc
DJ
39971Reply:
39972@xref{Stop Reply Packets}, for the reply specifications.
39973
b8ff78ce
JB
39974@item vCont?
39975@cindex @samp{vCont?} packet
d3e8051b 39976Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
39977
39978Reply:
39979@table @samp
b8ff78ce
JB
39980@item vCont@r{[};@var{action}@dots{}@r{]}
39981The @samp{vCont} packet is supported. Each @var{action} is a supported
39982command in the @samp{vCont} packet.
d57350ea 39983@item @w{}
b8ff78ce 39984The @samp{vCont} packet is not supported.
86d30acc 39985@end table
ee2d5c50 39986
de979965
PA
39987@anchor{vCtrlC packet}
39988@item vCtrlC
39989@cindex @samp{vCtrlC} packet
39990Interrupt remote target as if a control-C was pressed on the remote
39991terminal. This is the equivalent to reacting to the @code{^C}
39992(@samp{\003}, the control-C character) character in all-stop mode
39993while the target is running, except this works in non-stop mode.
39994@xref{interrupting remote targets}, for more info on the all-stop
39995variant.
39996
39997Reply:
39998@table @samp
39999@item E @var{nn}
40000for an error
40001@item OK
40002for success
40003@end table
40004
a6b151f1
DJ
40005@item vFile:@var{operation}:@var{parameter}@dots{}
40006@cindex @samp{vFile} packet
40007Perform a file operation on the target system. For details,
40008see @ref{Host I/O Packets}.
40009
68437a39
DJ
40010@item vFlashErase:@var{addr},@var{length}
40011@cindex @samp{vFlashErase} packet
40012Direct the stub to erase @var{length} bytes of flash starting at
40013@var{addr}. The region may enclose any number of flash blocks, but
40014its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
40015flash block size appearing in the memory map (@pxref{Memory Map
40016Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
40017together, and sends a @samp{vFlashDone} request after each group; the
40018stub is allowed to delay erase operation until the @samp{vFlashDone}
40019packet is received.
40020
40021Reply:
40022@table @samp
40023@item OK
40024for success
40025@item E @var{NN}
40026for an error
40027@end table
40028
40029@item vFlashWrite:@var{addr}:@var{XX@dots{}}
40030@cindex @samp{vFlashWrite} packet
40031Direct the stub to write data to flash address @var{addr}. The data
40032is passed in binary form using the same encoding as for the @samp{X}
40033packet (@pxref{Binary Data}). The memory ranges specified by
40034@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40035not overlap, and must appear in order of increasing addresses
40036(although @samp{vFlashErase} packets for higher addresses may already
40037have been received; the ordering is guaranteed only between
40038@samp{vFlashWrite} packets). If a packet writes to an address that was
40039neither erased by a preceding @samp{vFlashErase} packet nor by some other
40040target-specific method, the results are unpredictable.
40041
40042
40043Reply:
40044@table @samp
40045@item OK
40046for success
40047@item E.memtype
40048for vFlashWrite addressing non-flash memory
40049@item E @var{NN}
40050for an error
40051@end table
40052
40053@item vFlashDone
40054@cindex @samp{vFlashDone} packet
40055Indicate to the stub that flash programming operation is finished.
40056The stub is permitted to delay or batch the effects of a group of
40057@samp{vFlashErase} and @samp{vFlashWrite} packets until a
40058@samp{vFlashDone} packet is received. The contents of the affected
40059regions of flash memory are unpredictable until the @samp{vFlashDone}
40060request is completed.
40061
b90a069a
SL
40062@item vKill;@var{pid}
40063@cindex @samp{vKill} packet
36cb1214 40064@anchor{vKill packet}
697aa1b7 40065Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
40066hexadecimal integer identifying the process. This packet is used in
40067preference to @samp{k} when multiprocess protocol extensions are
40068supported; see @ref{multiprocess extensions}.
40069
40070Reply:
40071@table @samp
40072@item E @var{nn}
40073for an error
40074@item OK
40075for success
40076@end table
40077
176efed1
AB
40078@item vMustReplyEmpty
40079@cindex @samp{vMustReplyEmpty} packet
40080The correct reply to an unknown @samp{v} packet is to return the empty
40081string, however, some older versions of @command{gdbserver} would
40082incorrectly return @samp{OK} for unknown @samp{v} packets.
40083
40084The @samp{vMustReplyEmpty} is used as a feature test to check how
40085@command{gdbserver} handles unknown packets, it is important that this
40086packet be handled in the same way as other unknown @samp{v} packets.
40087If this packet is handled differently to other unknown @samp{v}
6b92c0d3 40088packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
40089other areas, specifically around use of @samp{vFile:setfs:}.
40090
2d717e4f
DJ
40091@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40092@cindex @samp{vRun} packet
40093Run the program @var{filename}, passing it each @var{argument} on its
40094command line. The file and arguments are hex-encoded strings. If
40095@var{filename} is an empty string, the stub may use a default program
40096(e.g.@: the last program run). The program is created in the stopped
9b562ab8 40097state.
2d717e4f 40098
8b23ecc4
SL
40099@c FIXME: What about non-stop mode?
40100
2d717e4f
DJ
40101This packet is only available in extended mode (@pxref{extended mode}).
40102
40103Reply:
40104@table @samp
40105@item E @var{nn}
40106for an error
40107@item @r{Any stop packet}
40108for success (@pxref{Stop Reply Packets})
40109@end table
40110
8b23ecc4 40111@item vStopped
8b23ecc4 40112@cindex @samp{vStopped} packet
8dbe8ece 40113@xref{Notification Packets}.
8b23ecc4 40114
b8ff78ce 40115@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 40116@anchor{X packet}
b8ff78ce
JB
40117@cindex @samp{X} packet
40118Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
40119Memory is specified by its address @var{addr} and number of addressable memory
40120units @var{length} (@pxref{addressable memory unit});
0876f84a 40121@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 40122
ee2d5c50
AC
40123Reply:
40124@table @samp
40125@item OK
40126for success
b8ff78ce 40127@item E @var{NN}
ee2d5c50
AC
40128for an error
40129@end table
40130
a1dcb23a
DJ
40131@item z @var{type},@var{addr},@var{kind}
40132@itemx Z @var{type},@var{addr},@var{kind}
2f870471 40133@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
40134@cindex @samp{z} packet
40135@cindex @samp{Z} packets
40136Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 40137watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 40138
2f870471
AC
40139Each breakpoint and watchpoint packet @var{type} is documented
40140separately.
40141
512217c7
AC
40142@emph{Implementation notes: A remote target shall return an empty string
40143for an unrecognized breakpoint or watchpoint packet @var{type}. A
40144remote target shall support either both or neither of a given
b8ff78ce 40145@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
40146avoid potential problems with duplicate packets, the operations should
40147be implemented in an idempotent way.}
40148
a1dcb23a 40149@item z0,@var{addr},@var{kind}
d3ce09f5 40150@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
40151@cindex @samp{z0} packet
40152@cindex @samp{Z0} packet
4435e1cc 40153Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 40154@var{addr} of type @var{kind}.
2f870471 40155
4435e1cc 40156A software breakpoint is implemented by replacing the instruction at
2f870471 40157@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
40158@var{kind} is target-specific and typically indicates the size of the
40159breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40160@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40161architectures have additional meanings for @var{kind}
40162(@pxref{Architecture-Specific Protocol Details}); if no
40163architecture-specific value is being used, it should be @samp{0}.
40164@var{kind} is hex-encoded. @var{cond_list} is an optional list of
40165conditional expressions in bytecode form that should be evaluated on
40166the target's side. These are the conditions that should be taken into
40167consideration when deciding if the breakpoint trigger should be
40168reported back to @value{GDBN}.
83364271 40169
f7e6eed5 40170See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 40171for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 40172
83364271
LM
40173The @var{cond_list} parameter is comprised of a series of expressions,
40174concatenated without separators. Each expression has the following form:
40175
40176@table @samp
40177
40178@item X @var{len},@var{expr}
40179@var{len} is the length of the bytecode expression and @var{expr} is the
40180actual conditional expression in bytecode form.
40181
40182@end table
40183
d3ce09f5
SS
40184The optional @var{cmd_list} parameter introduces commands that may be
40185run on the target, rather than being reported back to @value{GDBN}.
40186The parameter starts with a numeric flag @var{persist}; if the flag is
40187nonzero, then the breakpoint may remain active and the commands
40188continue to be run even when @value{GDBN} disconnects from the target.
40189Following this flag is a series of expressions concatenated with no
40190separators. Each expression has the following form:
40191
40192@table @samp
40193
40194@item X @var{len},@var{expr}
40195@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 40196actual commands expression in bytecode form.
d3ce09f5
SS
40197
40198@end table
40199
2f870471 40200@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 40201code that contains software breakpoints (e.g., when implementing
2f870471
AC
40202overlays). The behavior of this packet, in the presence of such a
40203target, is not defined.}
c906108c 40204
ee2d5c50
AC
40205Reply:
40206@table @samp
2f870471
AC
40207@item OK
40208success
d57350ea 40209@item @w{}
2f870471 40210not supported
b8ff78ce 40211@item E @var{NN}
ee2d5c50 40212for an error
2f870471
AC
40213@end table
40214
a1dcb23a 40215@item z1,@var{addr},@var{kind}
4435e1cc 40216@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
40217@cindex @samp{z1} packet
40218@cindex @samp{Z1} packet
40219Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 40220address @var{addr}.
2f870471
AC
40221
40222A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
40223dependent on being able to modify the target's memory. The
40224@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40225same meaning as in @samp{Z0} packets.
2f870471
AC
40226
40227@emph{Implementation note: A hardware breakpoint is not affected by code
40228movement.}
40229
40230Reply:
40231@table @samp
ee2d5c50 40232@item OK
2f870471 40233success
d57350ea 40234@item @w{}
2f870471 40235not supported
b8ff78ce 40236@item E @var{NN}
2f870471
AC
40237for an error
40238@end table
40239
a1dcb23a
DJ
40240@item z2,@var{addr},@var{kind}
40241@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
40242@cindex @samp{z2} packet
40243@cindex @samp{Z2} packet
a1dcb23a 40244Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 40245The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40246
40247Reply:
40248@table @samp
40249@item OK
40250success
d57350ea 40251@item @w{}
2f870471 40252not supported
b8ff78ce 40253@item E @var{NN}
2f870471
AC
40254for an error
40255@end table
40256
a1dcb23a
DJ
40257@item z3,@var{addr},@var{kind}
40258@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
40259@cindex @samp{z3} packet
40260@cindex @samp{Z3} packet
a1dcb23a 40261Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 40262The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40263
40264Reply:
40265@table @samp
40266@item OK
40267success
d57350ea 40268@item @w{}
2f870471 40269not supported
b8ff78ce 40270@item E @var{NN}
2f870471
AC
40271for an error
40272@end table
40273
a1dcb23a
DJ
40274@item z4,@var{addr},@var{kind}
40275@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
40276@cindex @samp{z4} packet
40277@cindex @samp{Z4} packet
a1dcb23a 40278Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 40279The number of bytes to watch is specified by @var{kind}.
2f870471
AC
40280
40281Reply:
40282@table @samp
40283@item OK
40284success
d57350ea 40285@item @w{}
2f870471 40286not supported
b8ff78ce 40287@item E @var{NN}
2f870471 40288for an error
ee2d5c50
AC
40289@end table
40290
40291@end table
c906108c 40292
ee2d5c50
AC
40293@node Stop Reply Packets
40294@section Stop Reply Packets
40295@cindex stop reply packets
c906108c 40296
8b23ecc4
SL
40297The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40298@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40299receive any of the below as a reply. Except for @samp{?}
40300and @samp{vStopped}, that reply is only returned
b8ff78ce 40301when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
40302number} is defined by the header @file{include/gdb/signals.h} in the
40303@value{GDBN} source code.
c906108c 40304
4435e1cc
TT
40305In non-stop mode, the server will simply reply @samp{OK} to commands
40306such as @samp{vCont}; any stop will be the subject of a future
40307notification. @xref{Remote Non-Stop}.
40308
b8ff78ce
JB
40309As in the description of request packets, we include spaces in the
40310reply templates for clarity; these are not part of the reply packet's
40311syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40312components.
c906108c 40313
b8ff78ce 40314@table @samp
ee2d5c50 40315
b8ff78ce 40316@item S @var{AA}
599b237a 40317The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40318number). This is equivalent to a @samp{T} response with no
40319@var{n}:@var{r} pairs.
c906108c 40320
b8ff78ce
JB
40321@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40322@cindex @samp{T} packet reply
599b237a 40323The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40324number). This is equivalent to an @samp{S} response, except that the
40325@samp{@var{n}:@var{r}} pairs can carry values of important registers
40326and other information directly in the stop reply packet, reducing
40327round-trip latency. Single-step and breakpoint traps are reported
40328this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
40329
40330@itemize @bullet
b8ff78ce 40331@item
599b237a 40332If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 40333corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
40334series of bytes in target byte order, with each byte given by a
40335two-digit hex number.
cfa9d6d9 40336
b8ff78ce 40337@item
b90a069a
SL
40338If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40339the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 40340
dc146f7c
VP
40341@item
40342If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40343the core on which the stop event was detected.
40344
b8ff78ce 40345@item
cfa9d6d9
DJ
40346If @var{n} is a recognized @dfn{stop reason}, it describes a more
40347specific event that stopped the target. The currently defined stop
697aa1b7 40348reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
40349signal. At most one stop reason should be present.
40350
b8ff78ce
JB
40351@item
40352Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40353and go on to the next; this allows us to extend the protocol in the
40354future.
cfa9d6d9
DJ
40355@end itemize
40356
40357The currently defined stop reasons are:
40358
40359@table @samp
40360@item watch
40361@itemx rwatch
40362@itemx awatch
40363The packet indicates a watchpoint hit, and @var{r} is the data address, in
40364hex.
40365
82075af2
JS
40366@item syscall_entry
40367@itemx syscall_return
40368The packet indicates a syscall entry or return, and @var{r} is the
40369syscall number, in hex.
40370
cfa9d6d9
DJ
40371@cindex shared library events, remote reply
40372@item library
40373The packet indicates that the loaded libraries have changed.
40374@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 40375list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
40376
40377@cindex replay log events, remote reply
40378@item replaylog
40379The packet indicates that the target cannot continue replaying
40380logged execution events, because it has reached the end (or the
40381beginning when executing backward) of the log. The value of @var{r}
40382will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40383for more information.
f7e6eed5
PA
40384
40385@item swbreak
40386@anchor{swbreak stop reason}
4435e1cc 40387The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
40388irrespective of whether it was @value{GDBN} that planted the
40389breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40390part must be left empty.
40391
40392On some architectures, such as x86, at the architecture level, when a
40393breakpoint instruction executes the program counter points at the
40394breakpoint address plus an offset. On such targets, the stub is
40395responsible for adjusting the PC to point back at the breakpoint
40396address.
40397
40398This packet should not be sent by default; older @value{GDBN} versions
40399did not support it. @value{GDBN} requests it, by supplying an
40400appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40401remote stub must also supply the appropriate @samp{qSupported} feature
40402indicating support.
40403
40404This packet is required for correct non-stop mode operation.
40405
40406@item hwbreak
40407The packet indicates the target stopped for a hardware breakpoint.
40408The @var{r} part must be left empty.
40409
40410The same remarks about @samp{qSupported} and non-stop mode above
40411apply.
0d71eef5
DB
40412
40413@cindex fork events, remote reply
40414@item fork
40415The packet indicates that @code{fork} was called, and @var{r}
40416is the thread ID of the new child process. Refer to
40417@ref{thread-id syntax} for the format of the @var{thread-id}
40418field. This packet is only applicable to targets that support
40419fork events.
40420
40421This packet should not be sent by default; older @value{GDBN} versions
40422did not support it. @value{GDBN} requests it, by supplying an
40423appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40424remote stub must also supply the appropriate @samp{qSupported} feature
40425indicating support.
40426
40427@cindex vfork events, remote reply
40428@item vfork
40429The packet indicates that @code{vfork} was called, and @var{r}
40430is the thread ID of the new child process. Refer to
40431@ref{thread-id syntax} for the format of the @var{thread-id}
40432field. This packet is only applicable to targets that support
40433vfork events.
40434
40435This packet should not be sent by default; older @value{GDBN} versions
40436did not support it. @value{GDBN} requests it, by supplying an
40437appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40438remote stub must also supply the appropriate @samp{qSupported} feature
40439indicating support.
40440
40441@cindex vforkdone events, remote reply
40442@item vforkdone
e68fa6f0
PA
40443The packet indicates that a child process created by a vfork
40444has either called @code{exec} or terminated, so that the
40445address spaces of the parent and child process are no longer
40446shared. The @var{r} part is ignored. This packet is only
40447applicable to targets that support vforkdone events.
0d71eef5
DB
40448
40449This packet should not be sent by default; older @value{GDBN} versions
40450did not support it. @value{GDBN} requests it, by supplying an
40451appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40452remote stub must also supply the appropriate @samp{qSupported} feature
40453indicating support.
40454
b459a59b
DB
40455@cindex exec events, remote reply
40456@item exec
40457The packet indicates that @code{execve} was called, and @var{r}
40458is the absolute pathname of the file that was executed, in hex.
40459This packet is only applicable to targets that support exec events.
40460
40461This packet should not be sent by default; older @value{GDBN} versions
40462did not support it. @value{GDBN} requests it, by supplying an
40463appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40464remote stub must also supply the appropriate @samp{qSupported} feature
40465indicating support.
40466
65706a29
PA
40467@cindex thread create event, remote reply
40468@anchor{thread create event}
40469@item create
40470The packet indicates that the thread was just created. The new thread
40471is stopped until @value{GDBN} sets it running with a resumption packet
40472(@pxref{vCont packet}). This packet should not be sent by default;
40473@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
40474also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40475@var{r} part is ignored.
65706a29 40476
cfa9d6d9 40477@end table
ee2d5c50 40478
b8ff78ce 40479@item W @var{AA}
b90a069a 40480@itemx W @var{AA} ; process:@var{pid}
8e04817f 40481The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
40482applicable to certain targets.
40483
4435e1cc
TT
40484The second form of the response, including the process ID of the
40485exited process, can be used only when @value{GDBN} has reported
40486support for multiprocess protocol extensions; see @ref{multiprocess
40487extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40488hex strings.
b90a069a 40489
b8ff78ce 40490@item X @var{AA}
b90a069a 40491@itemx X @var{AA} ; process:@var{pid}
8e04817f 40492The process terminated with signal @var{AA}.
c906108c 40493
b90a069a
SL
40494The second form of the response, including the process ID of the
40495terminated process, can be used only when @value{GDBN} has reported
40496support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
40497extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40498hex strings.
b90a069a 40499
65706a29
PA
40500@anchor{thread exit event}
40501@cindex thread exit event, remote reply
40502@item w @var{AA} ; @var{tid}
40503
40504The thread exited, and @var{AA} is the exit status. This response
40505should not be sent by default; @value{GDBN} requests it with the
40506@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 40507@var{AA} is formatted as a big-endian hex string.
65706a29 40508
f2faf941
PA
40509@item N
40510There are no resumed threads left in the target. In other words, even
40511though the process is alive, the last resumed thread has exited. For
40512example, say the target process has two threads: thread 1 and thread
405132. The client leaves thread 1 stopped, and resumes thread 2, which
40514subsequently exits. At this point, even though the process is still
40515alive, and thus no @samp{W} stop reply is sent, no thread is actually
40516executing either. The @samp{N} stop reply thus informs the client
40517that it can stop waiting for stop replies. This packet should not be
40518sent by default; older @value{GDBN} versions did not support it.
40519@value{GDBN} requests it, by supplying an appropriate
40520@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40521also supply the appropriate @samp{qSupported} feature indicating
40522support.
40523
b8ff78ce
JB
40524@item O @var{XX}@dots{}
40525@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40526written as the program's console output. This can happen at any time
40527while the program is running and the debugger should continue to wait
8b23ecc4 40528for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40529
b8ff78ce 40530@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40531@var{call-id} is the identifier which says which host system call should
40532be called. This is just the name of the function. Translation into the
40533correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40534@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40535system calls.
40536
b8ff78ce
JB
40537@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40538this very system call.
0ce1b118 40539
b8ff78ce
JB
40540The target replies with this packet when it expects @value{GDBN} to
40541call a host system call on behalf of the target. @value{GDBN} replies
40542with an appropriate @samp{F} packet and keeps up waiting for the next
40543reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40544or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40545Protocol Extension}, for more details.
0ce1b118 40546
ee2d5c50
AC
40547@end table
40548
40549@node General Query Packets
40550@section General Query Packets
9c16f35a 40551@cindex remote query requests
c906108c 40552
5f3bebba
JB
40553Packets starting with @samp{q} are @dfn{general query packets};
40554packets starting with @samp{Q} are @dfn{general set packets}. General
40555query and set packets are a semi-unified form for retrieving and
40556sending information to and from the stub.
40557
40558The initial letter of a query or set packet is followed by a name
40559indicating what sort of thing the packet applies to. For example,
40560@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40561definitions with the stub. These packet names follow some
40562conventions:
40563
40564@itemize @bullet
40565@item
40566The name must not contain commas, colons or semicolons.
40567@item
40568Most @value{GDBN} query and set packets have a leading upper case
40569letter.
40570@item
40571The names of custom vendor packets should use a company prefix, in
40572lower case, followed by a period. For example, packets designed at
40573the Acme Corporation might begin with @samp{qacme.foo} (for querying
40574foos) or @samp{Qacme.bar} (for setting bars).
40575@end itemize
40576
aa56d27a
JB
40577The name of a query or set packet should be separated from any
40578parameters by a @samp{:}; the parameters themselves should be
40579separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40580full packet name, and check for a separator or the end of the packet,
40581in case two packet names share a common prefix. New packets should not begin
40582with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40583packets predate these conventions, and have arguments without any terminator
40584for the packet name; we suspect they are in widespread use in places that
40585are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40586existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40587packet.}.
c906108c 40588
b8ff78ce
JB
40589Like the descriptions of the other packets, each description here
40590has a template showing the packet's overall syntax, followed by an
40591explanation of the packet's meaning. We include spaces in some of the
40592templates for clarity; these are not part of the packet's syntax. No
40593@value{GDBN} packet uses spaces to separate its components.
40594
5f3bebba
JB
40595Here are the currently defined query and set packets:
40596
b8ff78ce 40597@table @samp
c906108c 40598
d1feda86 40599@item QAgent:1
af4238e5 40600@itemx QAgent:0
d1feda86
YQ
40601Turn on or off the agent as a helper to perform some debugging operations
40602delegated from @value{GDBN} (@pxref{Control Agent}).
40603
d914c394
SS
40604@item QAllow:@var{op}:@var{val}@dots{}
40605@cindex @samp{QAllow} packet
40606Specify which operations @value{GDBN} expects to request of the
40607target, as a semicolon-separated list of operation name and value
40608pairs. Possible values for @var{op} include @samp{WriteReg},
40609@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40610@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40611indicating that @value{GDBN} will not request the operation, or 1,
40612indicating that it may. (The target can then use this to set up its
40613own internals optimally, for instance if the debugger never expects to
40614insert breakpoints, it may not need to install its own trap handler.)
40615
b8ff78ce 40616@item qC
9c16f35a 40617@cindex current thread, remote request
b8ff78ce 40618@cindex @samp{qC} packet
b90a069a 40619Return the current thread ID.
ee2d5c50
AC
40620
40621Reply:
40622@table @samp
b90a069a
SL
40623@item QC @var{thread-id}
40624Where @var{thread-id} is a thread ID as documented in
40625@ref{thread-id syntax}.
b8ff78ce 40626@item @r{(anything else)}
b90a069a 40627Any other reply implies the old thread ID.
ee2d5c50
AC
40628@end table
40629
b8ff78ce 40630@item qCRC:@var{addr},@var{length}
ff2587ec 40631@cindex CRC of memory block, remote request
b8ff78ce 40632@cindex @samp{qCRC} packet
936d2992 40633@anchor{qCRC packet}
99e008fe
EZ
40634Compute the CRC checksum of a block of memory using CRC-32 defined in
40635IEEE 802.3. The CRC is computed byte at a time, taking the most
40636significant bit of each byte first. The initial pattern code
40637@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40638
40639@emph{Note:} This is the same CRC used in validating separate debug
40640files (@pxref{Separate Debug Files, , Debugging Information in Separate
40641Files}). However the algorithm is slightly different. When validating
40642separate debug files, the CRC is computed taking the @emph{least}
40643significant bit of each byte first, and the final result is inverted to
40644detect trailing zeros.
40645
ff2587ec
WZ
40646Reply:
40647@table @samp
b8ff78ce 40648@item E @var{NN}
ff2587ec 40649An error (such as memory fault)
b8ff78ce
JB
40650@item C @var{crc32}
40651The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40652@end table
40653
03583c20
UW
40654@item QDisableRandomization:@var{value}
40655@cindex disable address space randomization, remote request
40656@cindex @samp{QDisableRandomization} packet
40657Some target operating systems will randomize the virtual address space
40658of the inferior process as a security feature, but provide a feature
40659to disable such randomization, e.g.@: to allow for a more deterministic
40660debugging experience. On such systems, this packet with a @var{value}
40661of 1 directs the target to disable address space randomization for
40662processes subsequently started via @samp{vRun} packets, while a packet
40663with a @var{value} of 0 tells the target to enable address space
40664randomization.
40665
40666This packet is only available in extended mode (@pxref{extended mode}).
40667
40668Reply:
40669@table @samp
40670@item OK
40671The request succeeded.
40672
40673@item E @var{nn}
697aa1b7 40674An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40675
d57350ea 40676@item @w{}
03583c20
UW
40677An empty reply indicates that @samp{QDisableRandomization} is not supported
40678by the stub.
40679@end table
40680
40681This packet is not probed by default; the remote stub must request it,
40682by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40683This should only be done on targets that actually support disabling
40684address space randomization.
40685
aefd8b33
SDJ
40686@item QStartupWithShell:@var{value}
40687@cindex startup with shell, remote request
40688@cindex @samp{QStartupWithShell} packet
40689On UNIX-like targets, it is possible to start the inferior using a
40690shell program. This is the default behavior on both @value{GDBN} and
40691@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40692used to inform @command{gdbserver} whether it should start the
40693inferior using a shell or not.
40694
40695If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40696to start the inferior. If @var{value} is @samp{1},
40697@command{gdbserver} will use a shell to start the inferior. All other
40698values are considered an error.
40699
40700This packet is only available in extended mode (@pxref{extended
40701mode}).
40702
40703Reply:
40704@table @samp
40705@item OK
40706The request succeeded.
40707
40708@item E @var{nn}
40709An error occurred. The error number @var{nn} is given as hex digits.
40710@end table
40711
40712This packet is not probed by default; the remote stub must request it,
40713by supplying an appropriate @samp{qSupported} response
40714(@pxref{qSupported}). This should only be done on targets that
40715actually support starting the inferior using a shell.
40716
40717Use of this packet is controlled by the @code{set startup-with-shell}
40718command; @pxref{set startup-with-shell}.
40719
0a2dde4a
SDJ
40720@item QEnvironmentHexEncoded:@var{hex-value}
40721@anchor{QEnvironmentHexEncoded}
40722@cindex set environment variable, remote request
40723@cindex @samp{QEnvironmentHexEncoded} packet
40724On UNIX-like targets, it is possible to set environment variables that
40725will be passed to the inferior during the startup process. This
40726packet is used to inform @command{gdbserver} of an environment
40727variable that has been defined by the user on @value{GDBN} (@pxref{set
40728environment}).
40729
40730The packet is composed by @var{hex-value}, an hex encoded
40731representation of the @var{name=value} format representing an
40732environment variable. The name of the environment variable is
40733represented by @var{name}, and the value to be assigned to the
40734environment variable is represented by @var{value}. If the variable
40735has no value (i.e., the value is @code{null}), then @var{value} will
40736not be present.
40737
40738This packet is only available in extended mode (@pxref{extended
40739mode}).
40740
40741Reply:
40742@table @samp
40743@item OK
40744The request succeeded.
40745@end table
40746
40747This packet is not probed by default; the remote stub must request it,
40748by supplying an appropriate @samp{qSupported} response
40749(@pxref{qSupported}). This should only be done on targets that
40750actually support passing environment variables to the starting
40751inferior.
40752
40753This packet is related to the @code{set environment} command;
40754@pxref{set environment}.
40755
40756@item QEnvironmentUnset:@var{hex-value}
40757@anchor{QEnvironmentUnset}
40758@cindex unset environment variable, remote request
40759@cindex @samp{QEnvironmentUnset} packet
40760On UNIX-like targets, it is possible to unset environment variables
40761before starting the inferior in the remote target. This packet is
40762used to inform @command{gdbserver} of an environment variable that has
40763been unset by the user on @value{GDBN} (@pxref{unset environment}).
40764
40765The packet is composed by @var{hex-value}, an hex encoded
40766representation of the name of the environment variable to be unset.
40767
40768This packet is only available in extended mode (@pxref{extended
40769mode}).
40770
40771Reply:
40772@table @samp
40773@item OK
40774The request succeeded.
40775@end table
40776
40777This packet is not probed by default; the remote stub must request it,
40778by supplying an appropriate @samp{qSupported} response
40779(@pxref{qSupported}). This should only be done on targets that
40780actually support passing environment variables to the starting
40781inferior.
40782
40783This packet is related to the @code{unset environment} command;
40784@pxref{unset environment}.
40785
40786@item QEnvironmentReset
40787@anchor{QEnvironmentReset}
40788@cindex reset environment, remote request
40789@cindex @samp{QEnvironmentReset} packet
40790On UNIX-like targets, this packet is used to reset the state of
40791environment variables in the remote target before starting the
40792inferior. In this context, reset means unsetting all environment
40793variables that were previously set by the user (i.e., were not
40794initially present in the environment). It is sent to
40795@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40796(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40797(@pxref{QEnvironmentUnset}) packets.
40798
40799This packet is only available in extended mode (@pxref{extended
40800mode}).
40801
40802Reply:
40803@table @samp
40804@item OK
40805The request succeeded.
40806@end table
40807
40808This packet is not probed by default; the remote stub must request it,
40809by supplying an appropriate @samp{qSupported} response
40810(@pxref{qSupported}). This should only be done on targets that
40811actually support passing environment variables to the starting
40812inferior.
40813
bc3b087d
SDJ
40814@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40815@anchor{QSetWorkingDir packet}
40816@cindex set working directory, remote request
40817@cindex @samp{QSetWorkingDir} packet
40818This packet is used to inform the remote server of the intended
40819current working directory for programs that are going to be executed.
40820
40821The packet is composed by @var{directory}, an hex encoded
40822representation of the directory that the remote inferior will use as
40823its current working directory. If @var{directory} is an empty string,
40824the remote server should reset the inferior's current working
40825directory to its original, empty value.
40826
40827This packet is only available in extended mode (@pxref{extended
40828mode}).
40829
40830Reply:
40831@table @samp
40832@item OK
40833The request succeeded.
40834@end table
40835
b8ff78ce
JB
40836@item qfThreadInfo
40837@itemx qsThreadInfo
9c16f35a 40838@cindex list active threads, remote request
b8ff78ce
JB
40839@cindex @samp{qfThreadInfo} packet
40840@cindex @samp{qsThreadInfo} packet
b90a069a 40841Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40842may be too many active threads to fit into one reply packet, this query
40843works iteratively: it may require more than one query/reply sequence to
40844obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40845be the @samp{qfThreadInfo} query; subsequent queries in the
40846sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40847
b8ff78ce 40848NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40849
40850Reply:
40851@table @samp
b90a069a
SL
40852@item m @var{thread-id}
40853A single thread ID
40854@item m @var{thread-id},@var{thread-id}@dots{}
40855a comma-separated list of thread IDs
b8ff78ce
JB
40856@item l
40857(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40858@end table
40859
40860In response to each query, the target will reply with a list of one or
b90a069a 40861more thread IDs, separated by commas.
e1aac25b 40862@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40863ids (using the @samp{qs} form of the query), until the target responds
501994c0 40864with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40865Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40866fields.
c906108c 40867
8dfcab11
DT
40868@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40869initial connection with the remote target, and the very first thread ID
40870mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40871message. Therefore, the stub should ensure that the first thread ID in
40872the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40873
b8ff78ce 40874@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40875@cindex get thread-local storage address, remote request
b8ff78ce 40876@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40877Fetch the address associated with thread local storage specified
40878by @var{thread-id}, @var{offset}, and @var{lm}.
40879
b90a069a
SL
40880@var{thread-id} is the thread ID associated with the
40881thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40882
40883@var{offset} is the (big endian, hex encoded) offset associated with the
40884thread local variable. (This offset is obtained from the debug
40885information associated with the variable.)
40886
db2e3e2e 40887@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40888load module associated with the thread local storage. For example,
ff2587ec
WZ
40889a @sc{gnu}/Linux system will pass the link map address of the shared
40890object associated with the thread local storage under consideration.
40891Other operating environments may choose to represent the load module
40892differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40893
40894Reply:
b8ff78ce
JB
40895@table @samp
40896@item @var{XX}@dots{}
ff2587ec
WZ
40897Hex encoded (big endian) bytes representing the address of the thread
40898local storage requested.
40899
b8ff78ce 40900@item E @var{nn}
697aa1b7 40901An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40902
d57350ea 40903@item @w{}
b8ff78ce 40904An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40905@end table
40906
711e434b
PM
40907@item qGetTIBAddr:@var{thread-id}
40908@cindex get thread information block address
40909@cindex @samp{qGetTIBAddr} packet
40910Fetch address of the Windows OS specific Thread Information Block.
40911
40912@var{thread-id} is the thread ID associated with the thread.
40913
40914Reply:
40915@table @samp
40916@item @var{XX}@dots{}
40917Hex encoded (big endian) bytes representing the linear address of the
40918thread information block.
40919
40920@item E @var{nn}
40921An error occured. This means that either the thread was not found, or the
40922address could not be retrieved.
40923
d57350ea 40924@item @w{}
711e434b
PM
40925An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40926@end table
40927
b8ff78ce 40928@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40929Obtain thread information from RTOS. Where: @var{startflag} (one hex
40930digit) is one to indicate the first query and zero to indicate a
40931subsequent query; @var{threadcount} (two hex digits) is the maximum
40932number of threads the response packet can contain; and @var{nextthread}
40933(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40934returned in the response as @var{argthread}.
ee2d5c50 40935
b8ff78ce 40936Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40937
40938Reply:
40939@table @samp
b8ff78ce 40940@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40941Where: @var{count} (two hex digits) is the number of threads being
40942returned; @var{done} (one hex digit) is zero to indicate more threads
40943and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40944digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40945is a sequence of thread IDs, @var{threadid} (eight hex
40946digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40947@end table
c906108c 40948
b8ff78ce 40949@item qOffsets
9c16f35a 40950@cindex section offsets, remote request
b8ff78ce 40951@cindex @samp{qOffsets} packet
31d99776
DJ
40952Get section offsets that the target used when relocating the downloaded
40953image.
c906108c 40954
ee2d5c50
AC
40955Reply:
40956@table @samp
31d99776
DJ
40957@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40958Relocate the @code{Text} section by @var{xxx} from its original address.
40959Relocate the @code{Data} section by @var{yyy} from its original address.
40960If the object file format provides segment information (e.g.@: @sc{elf}
40961@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40962segments by the supplied offsets.
40963
40964@emph{Note: while a @code{Bss} offset may be included in the response,
40965@value{GDBN} ignores this and instead applies the @code{Data} offset
40966to the @code{Bss} section.}
40967
40968@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40969Relocate the first segment of the object file, which conventionally
40970contains program code, to a starting address of @var{xxx}. If
40971@samp{DataSeg} is specified, relocate the second segment, which
40972conventionally contains modifiable data, to a starting address of
40973@var{yyy}. @value{GDBN} will report an error if the object file
40974does not contain segment information, or does not contain at least
40975as many segments as mentioned in the reply. Extra segments are
40976kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
40977@end table
40978
b90a069a 40979@item qP @var{mode} @var{thread-id}
9c16f35a 40980@cindex thread information, remote request
b8ff78ce 40981@cindex @samp{qP} packet
b90a069a
SL
40982Returns information on @var{thread-id}. Where: @var{mode} is a hex
40983encoded 32 bit mode; @var{thread-id} is a thread ID
40984(@pxref{thread-id syntax}).
ee2d5c50 40985
aa56d27a
JB
40986Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40987(see below).
40988
b8ff78ce 40989Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 40990
8b23ecc4 40991@item QNonStop:1
687e43a4 40992@itemx QNonStop:0
8b23ecc4
SL
40993@cindex non-stop mode, remote request
40994@cindex @samp{QNonStop} packet
40995@anchor{QNonStop}
40996Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40997@xref{Remote Non-Stop}, for more information.
40998
40999Reply:
41000@table @samp
41001@item OK
41002The request succeeded.
41003
41004@item E @var{nn}
697aa1b7 41005An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 41006
d57350ea 41007@item @w{}
8b23ecc4
SL
41008An empty reply indicates that @samp{QNonStop} is not supported by
41009the stub.
41010@end table
41011
41012This packet is not probed by default; the remote stub must request it,
41013by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41014Use of this packet is controlled by the @code{set non-stop} command;
41015@pxref{Non-Stop Mode}.
41016
82075af2
JS
41017@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41018@itemx QCatchSyscalls:0
41019@cindex catch syscalls from inferior, remote request
41020@cindex @samp{QCatchSyscalls} packet
41021@anchor{QCatchSyscalls}
41022Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41023catching syscalls from the inferior process.
41024
41025For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41026in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41027is listed, every system call should be reported.
41028
41029Note that if a syscall not in the list is reported, @value{GDBN} will
41030still filter the event according to its own list from all corresponding
41031@code{catch syscall} commands. However, it is more efficient to only
41032report the requested syscalls.
41033
41034Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41035@samp{QCatchSyscalls:1} list is completely replaced by the new list.
41036
41037If the inferior process execs, the state of @samp{QCatchSyscalls} is
41038kept for the new process too. On targets where exec may affect syscall
41039numbers, for example with exec between 32 and 64-bit processes, the
41040client should send a new packet with the new syscall list.
41041
41042Reply:
41043@table @samp
41044@item OK
41045The request succeeded.
41046
41047@item E @var{nn}
41048An error occurred. @var{nn} are hex digits.
41049
41050@item @w{}
41051An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41052the stub.
41053@end table
41054
41055Use of this packet is controlled by the @code{set remote catch-syscalls}
41056command (@pxref{Remote Configuration, set remote catch-syscalls}).
41057This packet is not probed by default; the remote stub must request it,
41058by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41059
89be2091
DJ
41060@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41061@cindex pass signals to inferior, remote request
41062@cindex @samp{QPassSignals} packet
23181151 41063@anchor{QPassSignals}
89be2091
DJ
41064Each listed @var{signal} should be passed directly to the inferior process.
41065Signals are numbered identically to continue packets and stop replies
41066(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41067strictly greater than the previous item. These signals do not need to stop
41068the inferior, or be reported to @value{GDBN}. All other signals should be
41069reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41070combine; any earlier @samp{QPassSignals} list is completely replaced by the
41071new list. This packet improves performance when using @samp{handle
41072@var{signal} nostop noprint pass}.
41073
41074Reply:
41075@table @samp
41076@item OK
41077The request succeeded.
41078
41079@item E @var{nn}
697aa1b7 41080An error occurred. The error number @var{nn} is given as hex digits.
89be2091 41081
d57350ea 41082@item @w{}
89be2091
DJ
41083An empty reply indicates that @samp{QPassSignals} is not supported by
41084the stub.
41085@end table
41086
41087Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 41088command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
41089This packet is not probed by default; the remote stub must request it,
41090by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41091
9b224c5e
PA
41092@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41093@cindex signals the inferior may see, remote request
41094@cindex @samp{QProgramSignals} packet
41095@anchor{QProgramSignals}
41096Each listed @var{signal} may be delivered to the inferior process.
41097Others should be silently discarded.
41098
41099In some cases, the remote stub may need to decide whether to deliver a
41100signal to the program or not without @value{GDBN} involvement. One
41101example of that is while detaching --- the program's threads may have
41102stopped for signals that haven't yet had a chance of being reported to
41103@value{GDBN}, and so the remote stub can use the signal list specified
41104by this packet to know whether to deliver or ignore those pending
41105signals.
41106
41107This does not influence whether to deliver a signal as requested by a
41108resumption packet (@pxref{vCont packet}).
41109
41110Signals are numbered identically to continue packets and stop replies
41111(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41112strictly greater than the previous item. Multiple
41113@samp{QProgramSignals} packets do not combine; any earlier
41114@samp{QProgramSignals} list is completely replaced by the new list.
41115
41116Reply:
41117@table @samp
41118@item OK
41119The request succeeded.
41120
41121@item E @var{nn}
697aa1b7 41122An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 41123
d57350ea 41124@item @w{}
9b224c5e
PA
41125An empty reply indicates that @samp{QProgramSignals} is not supported
41126by the stub.
41127@end table
41128
41129Use of this packet is controlled by the @code{set remote program-signals}
41130command (@pxref{Remote Configuration, set remote program-signals}).
41131This packet is not probed by default; the remote stub must request it,
41132by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41133
65706a29
PA
41134@anchor{QThreadEvents}
41135@item QThreadEvents:1
41136@itemx QThreadEvents:0
41137@cindex thread create/exit events, remote request
41138@cindex @samp{QThreadEvents} packet
41139
41140Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41141reporting of thread create and exit events. @xref{thread create
41142event}, for the reply specifications. For example, this is used in
41143non-stop mode when @value{GDBN} stops a set of threads and
41144synchronously waits for the their corresponding stop replies. Without
41145exit events, if one of the threads exits, @value{GDBN} would hang
41146forever not knowing that it should no longer expect a stop for that
41147same thread. @value{GDBN} does not enable this feature unless the
41148stub reports that it supports it by including @samp{QThreadEvents+} in
41149its @samp{qSupported} reply.
41150
41151Reply:
41152@table @samp
41153@item OK
41154The request succeeded.
41155
41156@item E @var{nn}
41157An error occurred. The error number @var{nn} is given as hex digits.
41158
41159@item @w{}
41160An empty reply indicates that @samp{QThreadEvents} is not supported by
41161the stub.
41162@end table
41163
41164Use of this packet is controlled by the @code{set remote thread-events}
41165command (@pxref{Remote Configuration, set remote thread-events}).
41166
b8ff78ce 41167@item qRcmd,@var{command}
ff2587ec 41168@cindex execute remote command, remote request
b8ff78ce 41169@cindex @samp{qRcmd} packet
ff2587ec 41170@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
41171execution. Invalid commands should be reported using the output
41172string. Before the final result packet, the target may also respond
41173with a number of intermediate @samp{O@var{output}} console output
41174packets. @emph{Implementors should note that providing access to a
41175stubs's interpreter may have security implications}.
fa93a9d8 41176
ff2587ec
WZ
41177Reply:
41178@table @samp
41179@item OK
41180A command response with no output.
41181@item @var{OUTPUT}
41182A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 41183@item E @var{NN}
ff2587ec 41184Indicate a badly formed request.
d57350ea 41185@item @w{}
b8ff78ce 41186An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 41187@end table
fa93a9d8 41188
aa56d27a
JB
41189(Note that the @code{qRcmd} packet's name is separated from the
41190command by a @samp{,}, not a @samp{:}, contrary to the naming
41191conventions above. Please don't use this packet as a model for new
41192packets.)
41193
08388c79
DE
41194@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
41195@cindex searching memory, in remote debugging
5c4808ca 41196@ifnotinfo
08388c79 41197@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
41198@end ifnotinfo
41199@cindex @samp{qSearch memory} packet
08388c79
DE
41200@anchor{qSearch memory}
41201Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
41202Both @var{address} and @var{length} are encoded in hex;
41203@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
41204
41205Reply:
41206@table @samp
41207@item 0
41208The pattern was not found.
41209@item 1,address
41210The pattern was found at @var{address}.
41211@item E @var{NN}
41212A badly formed request or an error was encountered while searching memory.
d57350ea 41213@item @w{}
08388c79
DE
41214An empty reply indicates that @samp{qSearch:memory} is not recognized.
41215@end table
41216
a6f3e723
SL
41217@item QStartNoAckMode
41218@cindex @samp{QStartNoAckMode} packet
41219@anchor{QStartNoAckMode}
41220Request that the remote stub disable the normal @samp{+}/@samp{-}
41221protocol acknowledgments (@pxref{Packet Acknowledgment}).
41222
41223Reply:
41224@table @samp
41225@item OK
41226The stub has switched to no-acknowledgment mode.
6b92c0d3 41227@value{GDBN} acknowledges this response,
a6f3e723
SL
41228but neither the stub nor @value{GDBN} shall send or expect further
41229@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 41230@item @w{}
a6f3e723
SL
41231An empty reply indicates that the stub does not support no-acknowledgment mode.
41232@end table
41233
be2a5f71
DJ
41234@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41235@cindex supported packets, remote query
41236@cindex features of the remote protocol
41237@cindex @samp{qSupported} packet
0876f84a 41238@anchor{qSupported}
be2a5f71
DJ
41239Tell the remote stub about features supported by @value{GDBN}, and
41240query the stub for features it supports. This packet allows
41241@value{GDBN} and the remote stub to take advantage of each others'
41242features. @samp{qSupported} also consolidates multiple feature probes
41243at startup, to improve @value{GDBN} performance---a single larger
41244packet performs better than multiple smaller probe packets on
41245high-latency links. Some features may enable behavior which must not
41246be on by default, e.g.@: because it would confuse older clients or
41247stubs. Other features may describe packets which could be
41248automatically probed for, but are not. These features must be
41249reported before @value{GDBN} will use them. This ``default
41250unsupported'' behavior is not appropriate for all packets, but it
41251helps to keep the initial connection time under control with new
41252versions of @value{GDBN} which support increasing numbers of packets.
41253
41254Reply:
41255@table @samp
41256@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41257The stub supports or does not support each returned @var{stubfeature},
41258depending on the form of each @var{stubfeature} (see below for the
41259possible forms).
d57350ea 41260@item @w{}
be2a5f71
DJ
41261An empty reply indicates that @samp{qSupported} is not recognized,
41262or that no features needed to be reported to @value{GDBN}.
41263@end table
41264
41265The allowed forms for each feature (either a @var{gdbfeature} in the
41266@samp{qSupported} packet, or a @var{stubfeature} in the response)
41267are:
41268
41269@table @samp
41270@item @var{name}=@var{value}
41271The remote protocol feature @var{name} is supported, and associated
41272with the specified @var{value}. The format of @var{value} depends
41273on the feature, but it must not include a semicolon.
41274@item @var{name}+
41275The remote protocol feature @var{name} is supported, and does not
41276need an associated value.
41277@item @var{name}-
41278The remote protocol feature @var{name} is not supported.
41279@item @var{name}?
41280The remote protocol feature @var{name} may be supported, and
41281@value{GDBN} should auto-detect support in some other way when it is
41282needed. This form will not be used for @var{gdbfeature} notifications,
41283but may be used for @var{stubfeature} responses.
41284@end table
41285
41286Whenever the stub receives a @samp{qSupported} request, the
41287supplied set of @value{GDBN} features should override any previous
41288request. This allows @value{GDBN} to put the stub in a known
41289state, even if the stub had previously been communicating with
41290a different version of @value{GDBN}.
41291
b90a069a
SL
41292The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41293are defined:
41294
41295@table @samp
41296@item multiprocess
41297This feature indicates whether @value{GDBN} supports multiprocess
41298extensions to the remote protocol. @value{GDBN} does not use such
41299extensions unless the stub also reports that it supports them by
41300including @samp{multiprocess+} in its @samp{qSupported} reply.
41301@xref{multiprocess extensions}, for details.
c8d5aac9
L
41302
41303@item xmlRegisters
41304This feature indicates that @value{GDBN} supports the XML target
41305description. If the stub sees @samp{xmlRegisters=} with target
41306specific strings separated by a comma, it will report register
41307description.
dde08ee1
PA
41308
41309@item qRelocInsn
41310This feature indicates whether @value{GDBN} supports the
41311@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41312instruction reply packet}).
f7e6eed5
PA
41313
41314@item swbreak
41315This feature indicates whether @value{GDBN} supports the swbreak stop
41316reason in stop replies. @xref{swbreak stop reason}, for details.
41317
41318@item hwbreak
41319This feature indicates whether @value{GDBN} supports the hwbreak stop
41320reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
41321
41322@item fork-events
41323This feature indicates whether @value{GDBN} supports fork event
41324extensions to the remote protocol. @value{GDBN} does not use such
41325extensions unless the stub also reports that it supports them by
41326including @samp{fork-events+} in its @samp{qSupported} reply.
41327
41328@item vfork-events
41329This feature indicates whether @value{GDBN} supports vfork event
41330extensions to the remote protocol. @value{GDBN} does not use such
41331extensions unless the stub also reports that it supports them by
41332including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
41333
41334@item exec-events
41335This feature indicates whether @value{GDBN} supports exec event
41336extensions to the remote protocol. @value{GDBN} does not use such
41337extensions unless the stub also reports that it supports them by
41338including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
41339
41340@item vContSupported
41341This feature indicates whether @value{GDBN} wants to know the
41342supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
41343@end table
41344
41345Stubs should ignore any unknown values for
be2a5f71
DJ
41346@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41347packet supports receiving packets of unlimited length (earlier
b90a069a 41348versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
41349for @var{gdbfeature} may be defined in the future to let the stub take
41350advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
41351improvements in the remote protocol---the @samp{multiprocess} feature is
41352an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
41353of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41354describes all the features it supports, and then the stub replies with
41355all the features it supports.
41356
41357Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41358responses, as long as each response uses one of the standard forms.
41359
41360Some features are flags. A stub which supports a flag feature
41361should respond with a @samp{+} form response. Other features
41362require values, and the stub should respond with an @samp{=}
41363form response.
41364
41365Each feature has a default value, which @value{GDBN} will use if
41366@samp{qSupported} is not available or if the feature is not mentioned
41367in the @samp{qSupported} response. The default values are fixed; a
41368stub is free to omit any feature responses that match the defaults.
41369
41370Not all features can be probed, but for those which can, the probing
41371mechanism is useful: in some cases, a stub's internal
41372architecture may not allow the protocol layer to know some information
41373about the underlying target in advance. This is especially common in
41374stubs which may be configured for multiple targets.
41375
41376These are the currently defined stub features and their properties:
41377
cfa9d6d9 41378@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
41379@c NOTE: The first row should be @headitem, but we do not yet require
41380@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 41381@item Feature Name
be2a5f71
DJ
41382@tab Value Required
41383@tab Default
41384@tab Probe Allowed
41385
41386@item @samp{PacketSize}
41387@tab Yes
41388@tab @samp{-}
41389@tab No
41390
0876f84a
DJ
41391@item @samp{qXfer:auxv:read}
41392@tab No
41393@tab @samp{-}
41394@tab Yes
41395
2ae8c8e7
MM
41396@item @samp{qXfer:btrace:read}
41397@tab No
41398@tab @samp{-}
41399@tab Yes
41400
f4abbc16
MM
41401@item @samp{qXfer:btrace-conf:read}
41402@tab No
41403@tab @samp{-}
41404@tab Yes
41405
c78fa86a
GB
41406@item @samp{qXfer:exec-file:read}
41407@tab No
41408@tab @samp{-}
41409@tab Yes
41410
23181151
DJ
41411@item @samp{qXfer:features:read}
41412@tab No
41413@tab @samp{-}
41414@tab Yes
41415
cfa9d6d9
DJ
41416@item @samp{qXfer:libraries:read}
41417@tab No
41418@tab @samp{-}
41419@tab Yes
41420
85dc5a12
GB
41421@item @samp{qXfer:libraries-svr4:read}
41422@tab No
41423@tab @samp{-}
41424@tab Yes
41425
41426@item @samp{augmented-libraries-svr4-read}
41427@tab No
41428@tab @samp{-}
41429@tab No
41430
68437a39
DJ
41431@item @samp{qXfer:memory-map:read}
41432@tab No
41433@tab @samp{-}
41434@tab Yes
41435
0fb4aa4b
PA
41436@item @samp{qXfer:sdata:read}
41437@tab No
41438@tab @samp{-}
41439@tab Yes
41440
4aa995e1
PA
41441@item @samp{qXfer:siginfo:read}
41442@tab No
41443@tab @samp{-}
41444@tab Yes
41445
41446@item @samp{qXfer:siginfo:write}
41447@tab No
41448@tab @samp{-}
41449@tab Yes
41450
dc146f7c
VP
41451@item @samp{qXfer:threads:read}
41452@tab No
41453@tab @samp{-}
41454@tab Yes
41455
b3b9301e
PA
41456@item @samp{qXfer:traceframe-info:read}
41457@tab No
41458@tab @samp{-}
41459@tab Yes
41460
169081d0
TG
41461@item @samp{qXfer:uib:read}
41462@tab No
41463@tab @samp{-}
41464@tab Yes
41465
78d85199
YQ
41466@item @samp{qXfer:fdpic:read}
41467@tab No
41468@tab @samp{-}
41469@tab Yes
dc146f7c 41470
2ae8c8e7
MM
41471@item @samp{Qbtrace:off}
41472@tab Yes
41473@tab @samp{-}
41474@tab Yes
41475
41476@item @samp{Qbtrace:bts}
41477@tab Yes
41478@tab @samp{-}
41479@tab Yes
41480
b20a6524
MM
41481@item @samp{Qbtrace:pt}
41482@tab Yes
41483@tab @samp{-}
41484@tab Yes
41485
d33501a5
MM
41486@item @samp{Qbtrace-conf:bts:size}
41487@tab Yes
41488@tab @samp{-}
41489@tab Yes
41490
b20a6524
MM
41491@item @samp{Qbtrace-conf:pt:size}
41492@tab Yes
41493@tab @samp{-}
41494@tab Yes
41495
8b23ecc4
SL
41496@item @samp{QNonStop}
41497@tab No
41498@tab @samp{-}
41499@tab Yes
41500
82075af2
JS
41501@item @samp{QCatchSyscalls}
41502@tab No
41503@tab @samp{-}
41504@tab Yes
41505
89be2091
DJ
41506@item @samp{QPassSignals}
41507@tab No
41508@tab @samp{-}
41509@tab Yes
41510
a6f3e723
SL
41511@item @samp{QStartNoAckMode}
41512@tab No
41513@tab @samp{-}
41514@tab Yes
41515
b90a069a
SL
41516@item @samp{multiprocess}
41517@tab No
41518@tab @samp{-}
41519@tab No
41520
83364271
LM
41521@item @samp{ConditionalBreakpoints}
41522@tab No
41523@tab @samp{-}
41524@tab No
41525
782b2b07
SS
41526@item @samp{ConditionalTracepoints}
41527@tab No
41528@tab @samp{-}
41529@tab No
41530
0d772ac9
MS
41531@item @samp{ReverseContinue}
41532@tab No
2f8132f3 41533@tab @samp{-}
0d772ac9
MS
41534@tab No
41535
41536@item @samp{ReverseStep}
41537@tab No
2f8132f3 41538@tab @samp{-}
0d772ac9
MS
41539@tab No
41540
409873ef
SS
41541@item @samp{TracepointSource}
41542@tab No
41543@tab @samp{-}
41544@tab No
41545
d1feda86
YQ
41546@item @samp{QAgent}
41547@tab No
41548@tab @samp{-}
41549@tab No
41550
d914c394
SS
41551@item @samp{QAllow}
41552@tab No
41553@tab @samp{-}
41554@tab No
41555
03583c20
UW
41556@item @samp{QDisableRandomization}
41557@tab No
41558@tab @samp{-}
41559@tab No
41560
d248b706
KY
41561@item @samp{EnableDisableTracepoints}
41562@tab No
41563@tab @samp{-}
41564@tab No
41565
f6f899bf
HAQ
41566@item @samp{QTBuffer:size}
41567@tab No
41568@tab @samp{-}
41569@tab No
41570
3065dfb6
SS
41571@item @samp{tracenz}
41572@tab No
41573@tab @samp{-}
41574@tab No
41575
d3ce09f5
SS
41576@item @samp{BreakpointCommands}
41577@tab No
41578@tab @samp{-}
41579@tab No
41580
f7e6eed5
PA
41581@item @samp{swbreak}
41582@tab No
41583@tab @samp{-}
41584@tab No
41585
41586@item @samp{hwbreak}
41587@tab No
41588@tab @samp{-}
41589@tab No
41590
0d71eef5
DB
41591@item @samp{fork-events}
41592@tab No
41593@tab @samp{-}
41594@tab No
41595
41596@item @samp{vfork-events}
41597@tab No
41598@tab @samp{-}
41599@tab No
41600
b459a59b
DB
41601@item @samp{exec-events}
41602@tab No
41603@tab @samp{-}
41604@tab No
41605
65706a29
PA
41606@item @samp{QThreadEvents}
41607@tab No
41608@tab @samp{-}
41609@tab No
41610
f2faf941
PA
41611@item @samp{no-resumed}
41612@tab No
41613@tab @samp{-}
41614@tab No
41615
be2a5f71
DJ
41616@end multitable
41617
41618These are the currently defined stub features, in more detail:
41619
41620@table @samp
41621@cindex packet size, remote protocol
41622@item PacketSize=@var{bytes}
41623The remote stub can accept packets up to at least @var{bytes} in
41624length. @value{GDBN} will send packets up to this size for bulk
41625transfers, and will never send larger packets. This is a limit on the
41626data characters in the packet, including the frame and checksum.
41627There is no trailing NUL byte in a remote protocol packet; if the stub
41628stores packets in a NUL-terminated format, it should allow an extra
41629byte in its buffer for the NUL. If this stub feature is not supported,
41630@value{GDBN} guesses based on the size of the @samp{g} packet response.
41631
0876f84a
DJ
41632@item qXfer:auxv:read
41633The remote stub understands the @samp{qXfer:auxv:read} packet
41634(@pxref{qXfer auxiliary vector read}).
41635
2ae8c8e7
MM
41636@item qXfer:btrace:read
41637The remote stub understands the @samp{qXfer:btrace:read}
41638packet (@pxref{qXfer btrace read}).
41639
f4abbc16
MM
41640@item qXfer:btrace-conf:read
41641The remote stub understands the @samp{qXfer:btrace-conf:read}
41642packet (@pxref{qXfer btrace-conf read}).
41643
c78fa86a
GB
41644@item qXfer:exec-file:read
41645The remote stub understands the @samp{qXfer:exec-file:read} packet
41646(@pxref{qXfer executable filename read}).
41647
23181151
DJ
41648@item qXfer:features:read
41649The remote stub understands the @samp{qXfer:features:read} packet
41650(@pxref{qXfer target description read}).
41651
cfa9d6d9
DJ
41652@item qXfer:libraries:read
41653The remote stub understands the @samp{qXfer:libraries:read} packet
41654(@pxref{qXfer library list read}).
41655
2268b414
JK
41656@item qXfer:libraries-svr4:read
41657The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41658(@pxref{qXfer svr4 library list read}).
41659
85dc5a12
GB
41660@item augmented-libraries-svr4-read
41661The remote stub understands the augmented form of the
41662@samp{qXfer:libraries-svr4:read} packet
41663(@pxref{qXfer svr4 library list read}).
41664
23181151
DJ
41665@item qXfer:memory-map:read
41666The remote stub understands the @samp{qXfer:memory-map:read} packet
41667(@pxref{qXfer memory map read}).
41668
0fb4aa4b
PA
41669@item qXfer:sdata:read
41670The remote stub understands the @samp{qXfer:sdata:read} packet
41671(@pxref{qXfer sdata read}).
41672
4aa995e1
PA
41673@item qXfer:siginfo:read
41674The remote stub understands the @samp{qXfer:siginfo:read} packet
41675(@pxref{qXfer siginfo read}).
41676
41677@item qXfer:siginfo:write
41678The remote stub understands the @samp{qXfer:siginfo:write} packet
41679(@pxref{qXfer siginfo write}).
41680
dc146f7c
VP
41681@item qXfer:threads:read
41682The remote stub understands the @samp{qXfer:threads:read} packet
41683(@pxref{qXfer threads read}).
41684
b3b9301e
PA
41685@item qXfer:traceframe-info:read
41686The remote stub understands the @samp{qXfer:traceframe-info:read}
41687packet (@pxref{qXfer traceframe info read}).
41688
169081d0
TG
41689@item qXfer:uib:read
41690The remote stub understands the @samp{qXfer:uib:read}
41691packet (@pxref{qXfer unwind info block}).
41692
78d85199
YQ
41693@item qXfer:fdpic:read
41694The remote stub understands the @samp{qXfer:fdpic:read}
41695packet (@pxref{qXfer fdpic loadmap read}).
41696
8b23ecc4
SL
41697@item QNonStop
41698The remote stub understands the @samp{QNonStop} packet
41699(@pxref{QNonStop}).
41700
82075af2
JS
41701@item QCatchSyscalls
41702The remote stub understands the @samp{QCatchSyscalls} packet
41703(@pxref{QCatchSyscalls}).
41704
23181151
DJ
41705@item QPassSignals
41706The remote stub understands the @samp{QPassSignals} packet
41707(@pxref{QPassSignals}).
41708
a6f3e723
SL
41709@item QStartNoAckMode
41710The remote stub understands the @samp{QStartNoAckMode} packet and
41711prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41712
b90a069a
SL
41713@item multiprocess
41714@anchor{multiprocess extensions}
41715@cindex multiprocess extensions, in remote protocol
41716The remote stub understands the multiprocess extensions to the remote
41717protocol syntax. The multiprocess extensions affect the syntax of
41718thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41719add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41720replies. Note that reporting this feature indicates support for the
41721syntactic extensions only, not that the stub necessarily supports
41722debugging of more than one process at a time. The stub must not use
41723multiprocess extensions in packet replies unless @value{GDBN} has also
41724indicated it supports them in its @samp{qSupported} request.
41725
07e059b5
VP
41726@item qXfer:osdata:read
41727The remote stub understands the @samp{qXfer:osdata:read} packet
41728((@pxref{qXfer osdata read}).
41729
83364271
LM
41730@item ConditionalBreakpoints
41731The target accepts and implements evaluation of conditional expressions
41732defined for breakpoints. The target will only report breakpoint triggers
41733when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41734
782b2b07
SS
41735@item ConditionalTracepoints
41736The remote stub accepts and implements conditional expressions defined
41737for tracepoints (@pxref{Tracepoint Conditions}).
41738
0d772ac9
MS
41739@item ReverseContinue
41740The remote stub accepts and implements the reverse continue packet
41741(@pxref{bc}).
41742
41743@item ReverseStep
41744The remote stub accepts and implements the reverse step packet
41745(@pxref{bs}).
41746
409873ef
SS
41747@item TracepointSource
41748The remote stub understands the @samp{QTDPsrc} packet that supplies
41749the source form of tracepoint definitions.
41750
d1feda86
YQ
41751@item QAgent
41752The remote stub understands the @samp{QAgent} packet.
41753
d914c394
SS
41754@item QAllow
41755The remote stub understands the @samp{QAllow} packet.
41756
03583c20
UW
41757@item QDisableRandomization
41758The remote stub understands the @samp{QDisableRandomization} packet.
41759
0fb4aa4b
PA
41760@item StaticTracepoint
41761@cindex static tracepoints, in remote protocol
41762The remote stub supports static tracepoints.
41763
1e4d1764
YQ
41764@item InstallInTrace
41765@anchor{install tracepoint in tracing}
41766The remote stub supports installing tracepoint in tracing.
41767
d248b706
KY
41768@item EnableDisableTracepoints
41769The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41770@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41771to be enabled and disabled while a trace experiment is running.
41772
f6f899bf 41773@item QTBuffer:size
28abe188 41774The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41775packet that allows to change the size of the trace buffer.
41776
3065dfb6
SS
41777@item tracenz
41778@cindex string tracing, in remote protocol
41779The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41780See @ref{Bytecode Descriptions} for details about the bytecode.
41781
d3ce09f5
SS
41782@item BreakpointCommands
41783@cindex breakpoint commands, in remote protocol
41784The remote stub supports running a breakpoint's command list itself,
41785rather than reporting the hit to @value{GDBN}.
41786
2ae8c8e7
MM
41787@item Qbtrace:off
41788The remote stub understands the @samp{Qbtrace:off} packet.
41789
41790@item Qbtrace:bts
41791The remote stub understands the @samp{Qbtrace:bts} packet.
41792
b20a6524
MM
41793@item Qbtrace:pt
41794The remote stub understands the @samp{Qbtrace:pt} packet.
41795
d33501a5
MM
41796@item Qbtrace-conf:bts:size
41797The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41798
b20a6524
MM
41799@item Qbtrace-conf:pt:size
41800The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41801
f7e6eed5
PA
41802@item swbreak
41803The remote stub reports the @samp{swbreak} stop reason for memory
41804breakpoints.
41805
41806@item hwbreak
41807The remote stub reports the @samp{hwbreak} stop reason for hardware
41808breakpoints.
41809
0d71eef5
DB
41810@item fork-events
41811The remote stub reports the @samp{fork} stop reason for fork events.
41812
41813@item vfork-events
41814The remote stub reports the @samp{vfork} stop reason for vfork events
41815and vforkdone events.
41816
b459a59b
DB
41817@item exec-events
41818The remote stub reports the @samp{exec} stop reason for exec events.
41819
750ce8d1
YQ
41820@item vContSupported
41821The remote stub reports the supported actions in the reply to
41822@samp{vCont?} packet.
41823
65706a29
PA
41824@item QThreadEvents
41825The remote stub understands the @samp{QThreadEvents} packet.
41826
f2faf941
PA
41827@item no-resumed
41828The remote stub reports the @samp{N} stop reply.
41829
be2a5f71
DJ
41830@end table
41831
b8ff78ce 41832@item qSymbol::
ff2587ec 41833@cindex symbol lookup, remote request
b8ff78ce 41834@cindex @samp{qSymbol} packet
ff2587ec
WZ
41835Notify the target that @value{GDBN} is prepared to serve symbol lookup
41836requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41837
41838Reply:
ff2587ec 41839@table @samp
b8ff78ce 41840@item OK
ff2587ec 41841The target does not need to look up any (more) symbols.
b8ff78ce 41842@item qSymbol:@var{sym_name}
ff2587ec
WZ
41843The target requests the value of symbol @var{sym_name} (hex encoded).
41844@value{GDBN} may provide the value by using the
b8ff78ce
JB
41845@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41846below.
ff2587ec 41847@end table
83761cbd 41848
b8ff78ce 41849@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41850Set the value of @var{sym_name} to @var{sym_value}.
41851
41852@var{sym_name} (hex encoded) is the name of a symbol whose value the
41853target has previously requested.
41854
41855@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41856@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41857will be empty.
41858
41859Reply:
41860@table @samp
b8ff78ce 41861@item OK
ff2587ec 41862The target does not need to look up any (more) symbols.
b8ff78ce 41863@item qSymbol:@var{sym_name}
ff2587ec
WZ
41864The target requests the value of a new symbol @var{sym_name} (hex
41865encoded). @value{GDBN} will continue to supply the values of symbols
41866(if available), until the target ceases to request them.
fa93a9d8 41867@end table
0abb7bc7 41868
00bf0b85 41869@item qTBuffer
687e43a4
TT
41870@itemx QTBuffer
41871@itemx QTDisconnected
d5551862 41872@itemx QTDP
409873ef 41873@itemx QTDPsrc
d5551862 41874@itemx QTDV
00bf0b85
SS
41875@itemx qTfP
41876@itemx qTfV
9d29849a 41877@itemx QTFrame
405f8e94
SS
41878@itemx qTMinFTPILen
41879
9d29849a
JB
41880@xref{Tracepoint Packets}.
41881
b90a069a 41882@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41883@cindex thread attributes info, remote request
b8ff78ce 41884@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41885Obtain from the target OS a printable string description of thread
41886attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41887for the forms of @var{thread-id}. This
b8ff78ce
JB
41888string may contain anything that the target OS thinks is interesting
41889for @value{GDBN} to tell the user about the thread. The string is
41890displayed in @value{GDBN}'s @code{info threads} display. Some
41891examples of possible thread extra info strings are @samp{Runnable}, or
41892@samp{Blocked on Mutex}.
ff2587ec
WZ
41893
41894Reply:
41895@table @samp
b8ff78ce
JB
41896@item @var{XX}@dots{}
41897Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41898comprising the printable string containing the extra information about
41899the thread's attributes.
ff2587ec 41900@end table
814e32d7 41901
aa56d27a
JB
41902(Note that the @code{qThreadExtraInfo} packet's name is separated from
41903the command by a @samp{,}, not a @samp{:}, contrary to the naming
41904conventions above. Please don't use this packet as a model for new
41905packets.)
41906
f196051f 41907@item QTNotes
687e43a4
TT
41908@itemx qTP
41909@itemx QTSave
41910@itemx qTsP
41911@itemx qTsV
d5551862 41912@itemx QTStart
9d29849a 41913@itemx QTStop
d248b706
KY
41914@itemx QTEnable
41915@itemx QTDisable
9d29849a
JB
41916@itemx QTinit
41917@itemx QTro
41918@itemx qTStatus
d5551862 41919@itemx qTV
0fb4aa4b
PA
41920@itemx qTfSTM
41921@itemx qTsSTM
41922@itemx qTSTMat
9d29849a
JB
41923@xref{Tracepoint Packets}.
41924
0876f84a
DJ
41925@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41926@cindex read special object, remote request
41927@cindex @samp{qXfer} packet
68437a39 41928@anchor{qXfer read}
0876f84a
DJ
41929Read uninterpreted bytes from the target's special data area
41930identified by the keyword @var{object}. Request @var{length} bytes
41931starting at @var{offset} bytes into the data. The content and
0e7f50da 41932encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41933additional details about what data to access.
41934
c185ba27
EZ
41935Reply:
41936@table @samp
41937@item m @var{data}
41938Data @var{data} (@pxref{Binary Data}) has been read from the
41939target. There may be more data at a higher address (although
41940it is permitted to return @samp{m} even for the last valid
41941block of data, as long as at least one byte of data was read).
41942It is possible for @var{data} to have fewer bytes than the @var{length} in the
41943request.
41944
41945@item l @var{data}
41946Data @var{data} (@pxref{Binary Data}) has been read from the target.
41947There is no more data to be read. It is possible for @var{data} to
41948have fewer bytes than the @var{length} in the request.
41949
41950@item l
41951The @var{offset} in the request is at the end of the data.
41952There is no more data to be read.
41953
41954@item E00
41955The request was malformed, or @var{annex} was invalid.
41956
41957@item E @var{nn}
41958The offset was invalid, or there was an error encountered reading the data.
41959The @var{nn} part is a hex-encoded @code{errno} value.
41960
41961@item @w{}
41962An empty reply indicates the @var{object} string was not recognized by
41963the stub, or that the object does not support reading.
41964@end table
41965
41966Here are the specific requests of this form defined so far. All the
0876f84a 41967@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 41968formats, listed above.
0876f84a
DJ
41969
41970@table @samp
41971@item qXfer:auxv:read::@var{offset},@var{length}
41972@anchor{qXfer auxiliary vector read}
41973Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 41974auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
41975
41976This packet is not probed by default; the remote stub must request it,
89be2091 41977by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 41978
2ae8c8e7
MM
41979@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41980@anchor{qXfer btrace read}
41981
41982Return a description of the current branch trace.
41983@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41984packet may have one of the following values:
41985
41986@table @code
41987@item all
41988Returns all available branch trace.
41989
41990@item new
41991Returns all available branch trace if the branch trace changed since
41992the last read request.
969c39fb
MM
41993
41994@item delta
41995Returns the new branch trace since the last read request. Adds a new
41996block to the end of the trace that begins at zero and ends at the source
41997location of the first branch in the trace buffer. This extra block is
41998used to stitch traces together.
41999
42000If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
42001@end table
42002
42003This packet is not probed by default; the remote stub must request it
42004by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42005
f4abbc16
MM
42006@item qXfer:btrace-conf:read::@var{offset},@var{length}
42007@anchor{qXfer btrace-conf read}
42008
42009Return a description of the current branch trace configuration.
42010@xref{Branch Trace Configuration Format}.
42011
42012This packet is not probed by default; the remote stub must request it
42013by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
42014
42015@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42016@anchor{qXfer executable filename read}
42017Return the full absolute name of the file that was executed to create
42018a process running on the remote system. The annex specifies the
42019numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
42020number. If the annex part is empty the remote stub should return the
42021filename corresponding to the currently executing process.
c78fa86a
GB
42022
42023This packet is not probed by default; the remote stub must request it,
42024by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 42025
23181151
DJ
42026@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42027@anchor{qXfer target description read}
42028Access the @dfn{target description}. @xref{Target Descriptions}. The
42029annex specifies which XML document to access. The main description is
42030always loaded from the @samp{target.xml} annex.
42031
42032This packet is not probed by default; the remote stub must request it,
42033by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42034
cfa9d6d9
DJ
42035@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42036@anchor{qXfer library list read}
42037Access the target's list of loaded libraries. @xref{Library List Format}.
42038The annex part of the generic @samp{qXfer} packet must be empty
42039(@pxref{qXfer read}).
42040
42041Targets which maintain a list of libraries in the program's memory do
42042not need to implement this packet; it is designed for platforms where
42043the operating system manages the list of loaded libraries.
42044
42045This packet is not probed by default; the remote stub must request it,
42046by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42047
2268b414
JK
42048@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42049@anchor{qXfer svr4 library list read}
42050Access the target's list of loaded libraries when the target is an SVR4
42051platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
42052of the generic @samp{qXfer} packet must be empty unless the remote
42053stub indicated it supports the augmented form of this packet
42054by supplying an appropriate @samp{qSupported} response
42055(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
42056
42057This packet is optional for better performance on SVR4 targets.
42058@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42059
42060This packet is not probed by default; the remote stub must request it,
42061by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42062
85dc5a12
GB
42063If the remote stub indicates it supports the augmented form of this
42064packet then the annex part of the generic @samp{qXfer} packet may
42065contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42066arguments. The currently supported arguments are:
42067
42068@table @code
42069@item start=@var{address}
42070A hexadecimal number specifying the address of the @samp{struct
42071link_map} to start reading the library list from. If unset or zero
42072then the first @samp{struct link_map} in the library list will be
42073chosen as the starting point.
42074
42075@item prev=@var{address}
42076A hexadecimal number specifying the address of the @samp{struct
42077link_map} immediately preceding the @samp{struct link_map}
42078specified by the @samp{start} argument. If unset or zero then
42079the remote stub will expect that no @samp{struct link_map}
42080exists prior to the starting point.
42081
42082@end table
42083
42084Arguments that are not understood by the remote stub will be silently
42085ignored.
42086
68437a39
DJ
42087@item qXfer:memory-map:read::@var{offset},@var{length}
42088@anchor{qXfer memory map read}
79a6e687 42089Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
42090annex part of the generic @samp{qXfer} packet must be empty
42091(@pxref{qXfer read}).
42092
0e7f50da
UW
42093This packet is not probed by default; the remote stub must request it,
42094by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42095
0fb4aa4b
PA
42096@item qXfer:sdata:read::@var{offset},@var{length}
42097@anchor{qXfer sdata read}
42098
42099Read contents of the extra collected static tracepoint marker
42100information. The annex part of the generic @samp{qXfer} packet must
42101be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42102Action Lists}.
42103
42104This packet is not probed by default; the remote stub must request it,
42105by supplying an appropriate @samp{qSupported} response
42106(@pxref{qSupported}).
42107
4aa995e1
PA
42108@item qXfer:siginfo:read::@var{offset},@var{length}
42109@anchor{qXfer siginfo read}
42110Read contents of the extra signal information on the target
42111system. The annex part of the generic @samp{qXfer} packet must be
42112empty (@pxref{qXfer read}).
42113
42114This packet is not probed by default; the remote stub must request it,
42115by supplying an appropriate @samp{qSupported} response
42116(@pxref{qSupported}).
42117
dc146f7c
VP
42118@item qXfer:threads:read::@var{offset},@var{length}
42119@anchor{qXfer threads read}
42120Access the list of threads on target. @xref{Thread List Format}. The
42121annex part of the generic @samp{qXfer} packet must be empty
42122(@pxref{qXfer read}).
42123
42124This packet is not probed by default; the remote stub must request it,
42125by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42126
b3b9301e
PA
42127@item qXfer:traceframe-info:read::@var{offset},@var{length}
42128@anchor{qXfer traceframe info read}
42129
42130Return a description of the current traceframe's contents.
42131@xref{Traceframe Info Format}. The annex part of the generic
42132@samp{qXfer} packet must be empty (@pxref{qXfer read}).
42133
42134This packet is not probed by default; the remote stub must request it,
42135by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42136
169081d0
TG
42137@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
42138@anchor{qXfer unwind info block}
42139
42140Return the unwind information block for @var{pc}. This packet is used
42141on OpenVMS/ia64 to ask the kernel unwind information.
42142
42143This packet is not probed by default.
42144
78d85199
YQ
42145@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
42146@anchor{qXfer fdpic loadmap read}
42147Read contents of @code{loadmap}s on the target system. The
42148annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
42149executable @code{loadmap} or interpreter @code{loadmap} to read.
42150
42151This packet is not probed by default; the remote stub must request it,
42152by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42153
07e059b5
VP
42154@item qXfer:osdata:read::@var{offset},@var{length}
42155@anchor{qXfer osdata read}
697aa1b7 42156Access the target's @dfn{operating system information}.
07e059b5
VP
42157@xref{Operating System Information}.
42158
68437a39
DJ
42159@end table
42160
c185ba27
EZ
42161@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
42162@cindex write data into object, remote request
42163@anchor{qXfer write}
42164Write uninterpreted bytes into the target's special data area
42165identified by the keyword @var{object}, starting at @var{offset} bytes
42166into the data. The binary-encoded data (@pxref{Binary Data}) to be
42167written is given by @var{data}@dots{}. The content and encoding of @var{annex}
42168is specific to @var{object}; it can supply additional details about what data
42169to access.
42170
0876f84a
DJ
42171Reply:
42172@table @samp
c185ba27
EZ
42173@item @var{nn}
42174@var{nn} (hex encoded) is the number of bytes written.
42175This may be fewer bytes than supplied in the request.
0876f84a
DJ
42176
42177@item E00
42178The request was malformed, or @var{annex} was invalid.
42179
42180@item E @var{nn}
c185ba27 42181The offset was invalid, or there was an error encountered writing the data.
697aa1b7 42182The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 42183
d57350ea 42184@item @w{}
c185ba27
EZ
42185An empty reply indicates the @var{object} string was not
42186recognized by the stub, or that the object does not support writing.
0876f84a
DJ
42187@end table
42188
c185ba27 42189Here are the specific requests of this form defined so far. All the
0e7f50da 42190@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 42191formats, listed above.
0e7f50da
UW
42192
42193@table @samp
4aa995e1
PA
42194@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
42195@anchor{qXfer siginfo write}
42196Write @var{data} to the extra signal information on the target system.
42197The annex part of the generic @samp{qXfer} packet must be
42198empty (@pxref{qXfer write}).
42199
42200This packet is not probed by default; the remote stub must request it,
42201by supplying an appropriate @samp{qSupported} response
42202(@pxref{qSupported}).
0e7f50da 42203@end table
0876f84a 42204
0876f84a
DJ
42205@item qXfer:@var{object}:@var{operation}:@dots{}
42206Requests of this form may be added in the future. When a stub does
42207not recognize the @var{object} keyword, or its support for
42208@var{object} does not recognize the @var{operation} keyword, the stub
42209must respond with an empty packet.
42210
0b16c5cf
PA
42211@item qAttached:@var{pid}
42212@cindex query attached, remote request
42213@cindex @samp{qAttached} packet
42214Return an indication of whether the remote server attached to an
42215existing process or created a new process. When the multiprocess
42216protocol extensions are supported (@pxref{multiprocess extensions}),
42217@var{pid} is an integer in hexadecimal format identifying the target
42218process. Otherwise, @value{GDBN} will omit the @var{pid} field and
42219the query packet will be simplified as @samp{qAttached}.
42220
42221This query is used, for example, to know whether the remote process
42222should be detached or killed when a @value{GDBN} session is ended with
42223the @code{quit} command.
42224
42225Reply:
42226@table @samp
42227@item 1
42228The remote server attached to an existing process.
42229@item 0
42230The remote server created a new process.
42231@item E @var{NN}
42232A badly formed request or an error was encountered.
42233@end table
42234
2ae8c8e7 42235@item Qbtrace:bts
b20a6524
MM
42236Enable branch tracing for the current thread using Branch Trace Store.
42237
42238Reply:
42239@table @samp
42240@item OK
42241Branch tracing has been enabled.
42242@item E.errtext
42243A badly formed request or an error was encountered.
42244@end table
42245
42246@item Qbtrace:pt
bc504a31 42247Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
42248
42249Reply:
42250@table @samp
42251@item OK
42252Branch tracing has been enabled.
42253@item E.errtext
42254A badly formed request or an error was encountered.
42255@end table
42256
42257@item Qbtrace:off
42258Disable branch tracing for the current thread.
42259
42260Reply:
42261@table @samp
42262@item OK
42263Branch tracing has been disabled.
42264@item E.errtext
42265A badly formed request or an error was encountered.
42266@end table
42267
d33501a5
MM
42268@item Qbtrace-conf:bts:size=@var{value}
42269Set the requested ring buffer size for new threads that use the
42270btrace recording method in bts format.
42271
42272Reply:
42273@table @samp
42274@item OK
42275The ring buffer size has been set.
42276@item E.errtext
42277A badly formed request or an error was encountered.
42278@end table
42279
b20a6524
MM
42280@item Qbtrace-conf:pt:size=@var{value}
42281Set the requested ring buffer size for new threads that use the
42282btrace recording method in pt format.
42283
42284Reply:
42285@table @samp
42286@item OK
42287The ring buffer size has been set.
42288@item E.errtext
42289A badly formed request or an error was encountered.
42290@end table
42291
ee2d5c50
AC
42292@end table
42293
a1dcb23a
DJ
42294@node Architecture-Specific Protocol Details
42295@section Architecture-Specific Protocol Details
42296
42297This section describes how the remote protocol is applied to specific
42298target architectures. Also see @ref{Standard Target Features}, for
42299details of XML target descriptions for each architecture.
42300
02b67415
MR
42301@menu
42302* ARM-Specific Protocol Details::
42303* MIPS-Specific Protocol Details::
42304@end menu
42305
42306@node ARM-Specific Protocol Details
42307@subsection @acronym{ARM}-specific Protocol Details
42308
42309@menu
42310* ARM Breakpoint Kinds::
42311@end menu
a1dcb23a 42312
02b67415
MR
42313@node ARM Breakpoint Kinds
42314@subsubsection @acronym{ARM} Breakpoint Kinds
42315@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
42316
42317These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42318
42319@table @r
42320
42321@item 2
4232216-bit Thumb mode breakpoint.
42323
42324@item 3
4232532-bit Thumb mode (Thumb-2) breakpoint.
42326
42327@item 4
02b67415 4232832-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
42329
42330@end table
42331
02b67415
MR
42332@node MIPS-Specific Protocol Details
42333@subsection @acronym{MIPS}-specific Protocol Details
42334
42335@menu
42336* MIPS Register packet Format::
4cc0665f 42337* MIPS Breakpoint Kinds::
02b67415 42338@end menu
a1dcb23a 42339
02b67415
MR
42340@node MIPS Register packet Format
42341@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 42342@cindex register packet format, @acronym{MIPS}
eb12ee30 42343
b8ff78ce 42344The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
42345In the below, some thirty-two bit registers are transferred as
42346sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
42347to fill the space allocated. Register bytes are transferred in target
42348byte order. The two nibbles within a register byte are transferred
02b67415 42349most-significant -- least-significant.
eb12ee30 42350
ee2d5c50 42351@table @r
eb12ee30 42352
8e04817f 42353@item MIPS32
599b237a 42354All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4235532 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42356registers; fsr; fir; fp.
eb12ee30 42357
8e04817f 42358@item MIPS64
599b237a 42359All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
42360thirty-two bit registers such as @code{sr}). The ordering is the same
42361as @code{MIPS32}.
eb12ee30 42362
ee2d5c50
AC
42363@end table
42364
4cc0665f
MR
42365@node MIPS Breakpoint Kinds
42366@subsubsection @acronym{MIPS} Breakpoint Kinds
42367@cindex breakpoint kinds, @acronym{MIPS}
42368
42369These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42370
42371@table @r
42372
42373@item 2
4237416-bit @acronym{MIPS16} mode breakpoint.
42375
42376@item 3
4237716-bit @acronym{microMIPS} mode breakpoint.
42378
42379@item 4
4238032-bit standard @acronym{MIPS} mode breakpoint.
42381
42382@item 5
4238332-bit @acronym{microMIPS} mode breakpoint.
42384
42385@end table
42386
9d29849a
JB
42387@node Tracepoint Packets
42388@section Tracepoint Packets
42389@cindex tracepoint packets
42390@cindex packets, tracepoint
42391
42392Here we describe the packets @value{GDBN} uses to implement
42393tracepoints (@pxref{Tracepoints}).
42394
42395@table @samp
42396
7a697b8d 42397@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 42398@cindex @samp{QTDP} packet
9d29849a
JB
42399Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42400is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
42401the tracepoint is disabled. The @var{step} gives the tracepoint's step
42402count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
42403then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42404the number of bytes that the target should copy elsewhere to make room
42405for the tracepoint. If an @samp{X} is present, it introduces a
42406tracepoint condition, which consists of a hexadecimal length, followed
42407by a comma and hex-encoded bytes, in a manner similar to action
42408encodings as described below. If the trailing @samp{-} is present,
42409further @samp{QTDP} packets will follow to specify this tracepoint's
42410actions.
9d29849a
JB
42411
42412Replies:
42413@table @samp
42414@item OK
42415The packet was understood and carried out.
dde08ee1
PA
42416@item qRelocInsn
42417@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42418@item @w{}
9d29849a
JB
42419The packet was not recognized.
42420@end table
42421
42422@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 42423Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
42424@var{addr} must be the same as in the initial @samp{QTDP} packet for
42425this tracepoint. This packet may only be sent immediately after
42426another @samp{QTDP} packet that ended with a @samp{-}. If the
42427trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42428specifying more actions for this tracepoint.
42429
42430In the series of action packets for a given tracepoint, at most one
42431can have an @samp{S} before its first @var{action}. If such a packet
42432is sent, it and the following packets define ``while-stepping''
42433actions. Any prior packets define ordinary actions --- that is, those
42434taken when the tracepoint is first hit. If no action packet has an
42435@samp{S}, then all the packets in the series specify ordinary
42436tracepoint actions.
42437
42438The @samp{@var{action}@dots{}} portion of the packet is a series of
42439actions, concatenated without separators. Each action has one of the
42440following forms:
42441
42442@table @samp
42443
42444@item R @var{mask}
697aa1b7 42445Collect the registers whose bits are set in @var{mask},
599b237a 42446a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
42447@var{i} should be collected. (The least significant bit is numbered
42448zero.) Note that @var{mask} may be any number of digits long; it may
42449not fit in a 32-bit word.
42450
42451@item M @var{basereg},@var{offset},@var{len}
42452Collect @var{len} bytes of memory starting at the address in register
42453number @var{basereg}, plus @var{offset}. If @var{basereg} is
42454@samp{-1}, then the range has a fixed address: @var{offset} is the
42455address of the lowest byte to collect. The @var{basereg},
599b237a 42456@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
42457values (the @samp{-1} value for @var{basereg} is a special case).
42458
42459@item X @var{len},@var{expr}
42460Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 42461it directs. The agent expression @var{expr} is as described in
9d29849a
JB
42462@ref{Agent Expressions}. Each byte of the expression is encoded as a
42463two-digit hex number in the packet; @var{len} is the number of bytes
42464in the expression (and thus one-half the number of hex digits in the
42465packet).
42466
42467@end table
42468
42469Any number of actions may be packed together in a single @samp{QTDP}
42470packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
42471length (400 bytes, for many stubs). There may be only one @samp{R}
42472action per tracepoint, and it must precede any @samp{M} or @samp{X}
42473actions. Any registers referred to by @samp{M} and @samp{X} actions
42474must be collected by a preceding @samp{R} action. (The
42475``while-stepping'' actions are treated as if they were attached to a
42476separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
42477
42478Replies:
42479@table @samp
42480@item OK
42481The packet was understood and carried out.
dde08ee1
PA
42482@item qRelocInsn
42483@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42484@item @w{}
9d29849a
JB
42485The packet was not recognized.
42486@end table
42487
409873ef
SS
42488@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42489@cindex @samp{QTDPsrc} packet
42490Specify a source string of tracepoint @var{n} at address @var{addr}.
42491This is useful to get accurate reproduction of the tracepoints
697aa1b7 42492originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
42493is the name of the tracepoint part, such as @samp{cond} for the
42494tracepoint's conditional expression (see below for a list of types), while
42495@var{bytes} is the string, encoded in hexadecimal.
42496
42497@var{start} is the offset of the @var{bytes} within the overall source
42498string, while @var{slen} is the total length of the source string.
42499This is intended for handling source strings that are longer than will
42500fit in a single packet.
42501@c Add detailed example when this info is moved into a dedicated
42502@c tracepoint descriptions section.
42503
42504The available string types are @samp{at} for the location,
42505@samp{cond} for the conditional, and @samp{cmd} for an action command.
42506@value{GDBN} sends a separate packet for each command in the action
42507list, in the same order in which the commands are stored in the list.
42508
42509The target does not need to do anything with source strings except
42510report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42511query packets.
42512
42513Although this packet is optional, and @value{GDBN} will only send it
42514if the target replies with @samp{TracepointSource} @xref{General
42515Query Packets}, it makes both disconnected tracing and trace files
42516much easier to use. Otherwise the user must be careful that the
42517tracepoints in effect while looking at trace frames are identical to
42518the ones in effect during the trace run; even a small discrepancy
42519could cause @samp{tdump} not to work, or a particular trace frame not
42520be found.
42521
fa3f8d5a 42522@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
42523@cindex define trace state variable, remote request
42524@cindex @samp{QTDV} packet
42525Create a new trace state variable, number @var{n}, with an initial
42526value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42527and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42528the option of not using this packet for initial values of zero; the
42529target should simply create the trace state variables as they are
fa3f8d5a
DT
42530mentioned in expressions. The value @var{builtin} should be 1 (one)
42531if the trace state variable is builtin and 0 (zero) if it is not builtin.
42532@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42533@samp{qTsV} packet had it set. The contents of @var{name} is the
42534hex-encoded name (without the leading @samp{$}) of the trace state
42535variable.
f61e138d 42536
9d29849a 42537@item QTFrame:@var{n}
c614397c 42538@cindex @samp{QTFrame} packet
9d29849a
JB
42539Select the @var{n}'th tracepoint frame from the buffer, and use the
42540register and memory contents recorded there to answer subsequent
42541request packets from @value{GDBN}.
42542
42543A successful reply from the stub indicates that the stub has found the
42544requested frame. The response is a series of parts, concatenated
42545without separators, describing the frame we selected. Each part has
42546one of the following forms:
42547
42548@table @samp
42549@item F @var{f}
42550The selected frame is number @var{n} in the trace frame buffer;
599b237a 42551@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42552was no frame matching the criteria in the request packet.
42553
42554@item T @var{t}
42555The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42556@var{t} is a hexadecimal number.
9d29849a
JB
42557
42558@end table
42559
42560@item QTFrame:pc:@var{addr}
42561Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42562currently selected frame whose PC is @var{addr};
599b237a 42563@var{addr} is a hexadecimal number.
9d29849a
JB
42564
42565@item QTFrame:tdp:@var{t}
42566Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42567currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42568is a hexadecimal number.
9d29849a
JB
42569
42570@item QTFrame:range:@var{start}:@var{end}
42571Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42572currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42573and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42574numbers.
42575
42576@item QTFrame:outside:@var{start}:@var{end}
42577Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42578frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42579
405f8e94 42580@item qTMinFTPILen
c614397c 42581@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42582This packet requests the minimum length of instruction at which a fast
42583tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42584the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42585it depends on the target system being able to create trampolines in
42586the first 64K of memory, which might or might not be possible for that
42587system. So the reply to this packet will be 4 if it is able to
42588arrange for that.
42589
42590Replies:
42591
42592@table @samp
42593@item 0
42594The minimum instruction length is currently unknown.
42595@item @var{length}
697aa1b7
EZ
42596The minimum instruction length is @var{length}, where @var{length}
42597is a hexadecimal number greater or equal to 1. A reply
42598of 1 means that a fast tracepoint may be placed on any instruction
42599regardless of size.
405f8e94
SS
42600@item E
42601An error has occurred.
d57350ea 42602@item @w{}
405f8e94
SS
42603An empty reply indicates that the request is not supported by the stub.
42604@end table
42605
9d29849a 42606@item QTStart
c614397c 42607@cindex @samp{QTStart} packet
dde08ee1
PA
42608Begin the tracepoint experiment. Begin collecting data from
42609tracepoint hits in the trace frame buffer. This packet supports the
42610@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42611instruction reply packet}).
9d29849a
JB
42612
42613@item QTStop
c614397c 42614@cindex @samp{QTStop} packet
9d29849a
JB
42615End the tracepoint experiment. Stop collecting trace frames.
42616
d248b706
KY
42617@item QTEnable:@var{n}:@var{addr}
42618@anchor{QTEnable}
c614397c 42619@cindex @samp{QTEnable} packet
d248b706
KY
42620Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42621experiment. If the tracepoint was previously disabled, then collection
42622of data from it will resume.
42623
42624@item QTDisable:@var{n}:@var{addr}
42625@anchor{QTDisable}
c614397c 42626@cindex @samp{QTDisable} packet
d248b706
KY
42627Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42628experiment. No more data will be collected from the tracepoint unless
42629@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42630
9d29849a 42631@item QTinit
c614397c 42632@cindex @samp{QTinit} packet
9d29849a
JB
42633Clear the table of tracepoints, and empty the trace frame buffer.
42634
42635@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42636@cindex @samp{QTro} packet
9d29849a
JB
42637Establish the given ranges of memory as ``transparent''. The stub
42638will answer requests for these ranges from memory's current contents,
42639if they were not collected as part of the tracepoint hit.
42640
42641@value{GDBN} uses this to mark read-only regions of memory, like those
42642containing program code. Since these areas never change, they should
42643still have the same contents they did when the tracepoint was hit, so
42644there's no reason for the stub to refuse to provide their contents.
42645
d5551862 42646@item QTDisconnected:@var{value}
c614397c 42647@cindex @samp{QTDisconnected} packet
d5551862
SS
42648Set the choice to what to do with the tracing run when @value{GDBN}
42649disconnects from the target. A @var{value} of 1 directs the target to
42650continue the tracing run, while 0 tells the target to stop tracing if
42651@value{GDBN} is no longer in the picture.
42652
9d29849a 42653@item qTStatus
c614397c 42654@cindex @samp{qTStatus} packet
9d29849a
JB
42655Ask the stub if there is a trace experiment running right now.
42656
4daf5ac0
SS
42657The reply has the form:
42658
42659@table @samp
42660
42661@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42662@var{running} is a single digit @code{1} if the trace is presently
42663running, or @code{0} if not. It is followed by semicolon-separated
42664optional fields that an agent may use to report additional status.
42665
42666@end table
42667
42668If the trace is not running, the agent may report any of several
42669explanations as one of the optional fields:
42670
42671@table @samp
42672
42673@item tnotrun:0
42674No trace has been run yet.
42675
f196051f
SS
42676@item tstop[:@var{text}]:0
42677The trace was stopped by a user-originated stop command. The optional
42678@var{text} field is a user-supplied string supplied as part of the
42679stop command (for instance, an explanation of why the trace was
42680stopped manually). It is hex-encoded.
4daf5ac0
SS
42681
42682@item tfull:0
42683The trace stopped because the trace buffer filled up.
42684
42685@item tdisconnected:0
42686The trace stopped because @value{GDBN} disconnected from the target.
42687
42688@item tpasscount:@var{tpnum}
42689The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42690
6c28cbf2
SS
42691@item terror:@var{text}:@var{tpnum}
42692The trace stopped because tracepoint @var{tpnum} had an error. The
42693string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42694(for instance, a divide by zero in the condition expression); it
42695is hex encoded.
6c28cbf2 42696
4daf5ac0
SS
42697@item tunknown:0
42698The trace stopped for some other reason.
42699
42700@end table
42701
33da3f1c
SS
42702Additional optional fields supply statistical and other information.
42703Although not required, they are extremely useful for users monitoring
42704the progress of a trace run. If a trace has stopped, and these
42705numbers are reported, they must reflect the state of the just-stopped
42706trace.
4daf5ac0 42707
9d29849a 42708@table @samp
4daf5ac0
SS
42709
42710@item tframes:@var{n}
42711The number of trace frames in the buffer.
42712
42713@item tcreated:@var{n}
42714The total number of trace frames created during the run. This may
42715be larger than the trace frame count, if the buffer is circular.
42716
42717@item tsize:@var{n}
42718The total size of the trace buffer, in bytes.
42719
42720@item tfree:@var{n}
42721The number of bytes still unused in the buffer.
42722
33da3f1c
SS
42723@item circular:@var{n}
42724The value of the circular trace buffer flag. @code{1} means that the
42725trace buffer is circular and old trace frames will be discarded if
42726necessary to make room, @code{0} means that the trace buffer is linear
42727and may fill up.
42728
42729@item disconn:@var{n}
42730The value of the disconnected tracing flag. @code{1} means that
42731tracing will continue after @value{GDBN} disconnects, @code{0} means
42732that the trace run will stop.
42733
9d29849a
JB
42734@end table
42735
f196051f
SS
42736@item qTP:@var{tp}:@var{addr}
42737@cindex tracepoint status, remote request
42738@cindex @samp{qTP} packet
42739Ask the stub for the current state of tracepoint number @var{tp} at
42740address @var{addr}.
42741
42742Replies:
42743@table @samp
42744@item V@var{hits}:@var{usage}
42745The tracepoint has been hit @var{hits} times so far during the trace
42746run, and accounts for @var{usage} in the trace buffer. Note that
42747@code{while-stepping} steps are not counted as separate hits, but the
42748steps' space consumption is added into the usage number.
42749
42750@end table
42751
f61e138d
SS
42752@item qTV:@var{var}
42753@cindex trace state variable value, remote request
42754@cindex @samp{qTV} packet
42755Ask the stub for the value of the trace state variable number @var{var}.
42756
42757Replies:
42758@table @samp
42759@item V@var{value}
42760The value of the variable is @var{value}. This will be the current
42761value of the variable if the user is examining a running target, or a
42762saved value if the variable was collected in the trace frame that the
42763user is looking at. Note that multiple requests may result in
42764different reply values, such as when requesting values while the
42765program is running.
42766
42767@item U
42768The value of the variable is unknown. This would occur, for example,
42769if the user is examining a trace frame in which the requested variable
42770was not collected.
9d29849a
JB
42771@end table
42772
d5551862 42773@item qTfP
c614397c 42774@cindex @samp{qTfP} packet
d5551862 42775@itemx qTsP
c614397c 42776@cindex @samp{qTsP} packet
d5551862
SS
42777These packets request data about tracepoints that are being used by
42778the target. @value{GDBN} sends @code{qTfP} to get the first piece
42779of data, and multiple @code{qTsP} to get additional pieces. Replies
42780to these packets generally take the form of the @code{QTDP} packets
42781that define tracepoints. (FIXME add detailed syntax)
42782
00bf0b85 42783@item qTfV
c614397c 42784@cindex @samp{qTfV} packet
00bf0b85 42785@itemx qTsV
c614397c 42786@cindex @samp{qTsV} packet
00bf0b85
SS
42787These packets request data about trace state variables that are on the
42788target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42789and multiple @code{qTsV} to get additional variables. Replies to
42790these packets follow the syntax of the @code{QTDV} packets that define
42791trace state variables.
42792
0fb4aa4b
PA
42793@item qTfSTM
42794@itemx qTsSTM
16bdd41f
YQ
42795@anchor{qTfSTM}
42796@anchor{qTsSTM}
c614397c
YQ
42797@cindex @samp{qTfSTM} packet
42798@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42799These packets request data about static tracepoint markers that exist
42800in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42801first piece of data, and multiple @code{qTsSTM} to get additional
42802pieces. Replies to these packets take the following form:
42803
42804Reply:
42805@table @samp
42806@item m @var{address}:@var{id}:@var{extra}
42807A single marker
42808@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42809a comma-separated list of markers
42810@item l
42811(lower case letter @samp{L}) denotes end of list.
42812@item E @var{nn}
697aa1b7 42813An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42814@item @w{}
0fb4aa4b
PA
42815An empty reply indicates that the request is not supported by the
42816stub.
42817@end table
42818
697aa1b7 42819The @var{address} is encoded in hex;
0fb4aa4b
PA
42820@var{id} and @var{extra} are strings encoded in hex.
42821
42822In response to each query, the target will reply with a list of one or
42823more markers, separated by commas. @value{GDBN} will respond to each
42824reply with a request for more markers (using the @samp{qs} form of the
42825query), until the target responds with @samp{l} (lower-case ell, for
42826@dfn{last}).
42827
42828@item qTSTMat:@var{address}
16bdd41f 42829@anchor{qTSTMat}
c614397c 42830@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42831This packets requests data about static tracepoint markers in the
42832target program at @var{address}. Replies to this packet follow the
42833syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42834tracepoint markers.
42835
00bf0b85 42836@item QTSave:@var{filename}
c614397c 42837@cindex @samp{QTSave} packet
00bf0b85 42838This packet directs the target to save trace data to the file name
697aa1b7 42839@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42840as a hex string; the interpretation of the file name (relative vs
42841absolute, wild cards, etc) is up to the target.
42842
42843@item qTBuffer:@var{offset},@var{len}
c614397c 42844@cindex @samp{qTBuffer} packet
00bf0b85
SS
42845Return up to @var{len} bytes of the current contents of trace buffer,
42846starting at @var{offset}. The trace buffer is treated as if it were
42847a contiguous collection of traceframes, as per the trace file format.
42848The reply consists as many hex-encoded bytes as the target can deliver
42849in a packet; it is not an error to return fewer than were asked for.
42850A reply consisting of just @code{l} indicates that no bytes are
42851available.
42852
4daf5ac0
SS
42853@item QTBuffer:circular:@var{value}
42854This packet directs the target to use a circular trace buffer if
42855@var{value} is 1, or a linear buffer if the value is 0.
42856
f6f899bf 42857@item QTBuffer:size:@var{size}
28abe188
EZ
42858@anchor{QTBuffer-size}
42859@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42860This packet directs the target to make the trace buffer be of size
42861@var{size} if possible. A value of @code{-1} tells the target to
42862use whatever size it prefers.
42863
f196051f 42864@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42865@cindex @samp{QTNotes} packet
f196051f
SS
42866This packet adds optional textual notes to the trace run. Allowable
42867types include @code{user}, @code{notes}, and @code{tstop}, the
42868@var{text} fields are arbitrary strings, hex-encoded.
42869
f61e138d 42870@end table
9d29849a 42871
dde08ee1
PA
42872@subsection Relocate instruction reply packet
42873When installing fast tracepoints in memory, the target may need to
42874relocate the instruction currently at the tracepoint address to a
42875different address in memory. For most instructions, a simple copy is
42876enough, but, for example, call instructions that implicitly push the
42877return address on the stack, and relative branches or other
42878PC-relative instructions require offset adjustment, so that the effect
42879of executing the instruction at a different address is the same as if
42880it had executed in the original location.
42881
42882In response to several of the tracepoint packets, the target may also
42883respond with a number of intermediate @samp{qRelocInsn} request
42884packets before the final result packet, to have @value{GDBN} handle
42885this relocation operation. If a packet supports this mechanism, its
42886documentation will explicitly say so. See for example the above
42887descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42888format of the request is:
42889
42890@table @samp
42891@item qRelocInsn:@var{from};@var{to}
42892
42893This requests @value{GDBN} to copy instruction at address @var{from}
42894to address @var{to}, possibly adjusted so that executing the
42895instruction at @var{to} has the same effect as executing it at
42896@var{from}. @value{GDBN} writes the adjusted instruction to target
42897memory starting at @var{to}.
42898@end table
42899
42900Replies:
42901@table @samp
42902@item qRelocInsn:@var{adjusted_size}
697aa1b7 42903Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42904the length in bytes of resulting relocated instruction sequence.
42905@item E @var{NN}
42906A badly formed request was detected, or an error was encountered while
42907relocating the instruction.
42908@end table
42909
a6b151f1
DJ
42910@node Host I/O Packets
42911@section Host I/O Packets
42912@cindex Host I/O, remote protocol
42913@cindex file transfer, remote protocol
42914
42915The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42916operations on the far side of a remote link. For example, Host I/O is
42917used to upload and download files to a remote target with its own
42918filesystem. Host I/O uses the same constant values and data structure
42919layout as the target-initiated File-I/O protocol. However, the
42920Host I/O packets are structured differently. The target-initiated
42921protocol relies on target memory to store parameters and buffers.
42922Host I/O requests are initiated by @value{GDBN}, and the
42923target's memory is not involved. @xref{File-I/O Remote Protocol
42924Extension}, for more details on the target-initiated protocol.
42925
42926The Host I/O request packets all encode a single operation along with
42927its arguments. They have this format:
42928
42929@table @samp
42930
42931@item vFile:@var{operation}: @var{parameter}@dots{}
42932@var{operation} is the name of the particular request; the target
42933should compare the entire packet name up to the second colon when checking
42934for a supported operation. The format of @var{parameter} depends on
42935the operation. Numbers are always passed in hexadecimal. Negative
42936numbers have an explicit minus sign (i.e.@: two's complement is not
42937used). Strings (e.g.@: filenames) are encoded as a series of
42938hexadecimal bytes. The last argument to a system call may be a
42939buffer of escaped binary data (@pxref{Binary Data}).
42940
42941@end table
42942
42943The valid responses to Host I/O packets are:
42944
42945@table @samp
42946
42947@item F @var{result} [, @var{errno}] [; @var{attachment}]
42948@var{result} is the integer value returned by this operation, usually
42949non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42950@var{errno} will be included in the result specifying a
a6b151f1
DJ
42951value defined by the File-I/O protocol (@pxref{Errno Values}). For
42952operations which return data, @var{attachment} supplies the data as a
42953binary buffer. Binary buffers in response packets are escaped in the
42954normal way (@pxref{Binary Data}). See the individual packet
42955documentation for the interpretation of @var{result} and
42956@var{attachment}.
42957
d57350ea 42958@item @w{}
a6b151f1
DJ
42959An empty response indicates that this operation is not recognized.
42960
42961@end table
42962
42963These are the supported Host I/O operations:
42964
42965@table @samp
697aa1b7
EZ
42966@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42967Open a file at @var{filename} and return a file descriptor for it, or
42968return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
42969@var{flags} is an integer indicating a mask of open flags
42970(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42971of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 42972@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
42973
42974@item vFile:close: @var{fd}
42975Close the open file corresponding to @var{fd} and return 0, or
42976-1 if an error occurs.
42977
42978@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42979Read data from the open file corresponding to @var{fd}. Up to
42980@var{count} bytes will be read from the file, starting at @var{offset}
42981relative to the start of the file. The target may read fewer bytes;
42982common reasons include packet size limits and an end-of-file
42983condition. The number of bytes read is returned. Zero should only be
42984returned for a successful read at the end of the file, or if
42985@var{count} was zero.
42986
42987The data read should be returned as a binary attachment on success.
42988If zero bytes were read, the response should include an empty binary
42989attachment (i.e.@: a trailing semicolon). The return value is the
42990number of target bytes read; the binary attachment may be longer if
42991some characters were escaped.
42992
42993@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42994Write @var{data} (a binary buffer) to the open file corresponding
42995to @var{fd}. Start the write at @var{offset} from the start of the
42996file. Unlike many @code{write} system calls, there is no
42997separate @var{count} argument; the length of @var{data} in the
fb092e09 42998packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
42999which may be shorter than the length of @var{data}, or -1 if an
43000error occurred.
43001
0a93529c
GB
43002@item vFile:fstat: @var{fd}
43003Get information about the open file corresponding to @var{fd}.
43004On success the information is returned as a binary attachment
43005and the return value is the size of this attachment in bytes.
43006If an error occurs the return value is -1. The format of the
43007returned binary attachment is as described in @ref{struct stat}.
43008
697aa1b7
EZ
43009@item vFile:unlink: @var{filename}
43010Delete the file at @var{filename} on the target. Return 0,
43011or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 43012
b9e7b9c3
UW
43013@item vFile:readlink: @var{filename}
43014Read value of symbolic link @var{filename} on the target. Return
43015the number of bytes read, or -1 if an error occurs.
43016
43017The data read should be returned as a binary attachment on success.
43018If zero bytes were read, the response should include an empty binary
43019attachment (i.e.@: a trailing semicolon). The return value is the
43020number of target bytes read; the binary attachment may be longer if
43021some characters were escaped.
43022
15a201c8
GB
43023@item vFile:setfs: @var{pid}
43024Select the filesystem on which @code{vFile} operations with
43025@var{filename} arguments will operate. This is required for
43026@value{GDBN} to be able to access files on remote targets where
43027the remote stub does not share a common filesystem with the
43028inferior(s).
43029
43030If @var{pid} is nonzero, select the filesystem as seen by process
43031@var{pid}. If @var{pid} is zero, select the filesystem as seen by
43032the remote stub. Return 0 on success, or -1 if an error occurs.
43033If @code{vFile:setfs:} indicates success, the selected filesystem
43034remains selected until the next successful @code{vFile:setfs:}
43035operation.
43036
a6b151f1
DJ
43037@end table
43038
9a6253be
KB
43039@node Interrupts
43040@section Interrupts
43041@cindex interrupts (remote protocol)
de979965 43042@anchor{interrupting remote targets}
9a6253be 43043
de979965
PA
43044In all-stop mode, when a program on the remote target is running,
43045@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43046@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43047is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
43048
43049The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
43050mechanism and may, in fact, be undefined. @value{GDBN} does not
43051currently define a @code{BREAK} mechanism for any of the network
43052interfaces except for TCP, in which case @value{GDBN} sends the
43053@code{telnet} BREAK sequence.
9a6253be
KB
43054
43055@samp{Ctrl-C}, on the other hand, is defined and implemented for all
43056transport mechanisms. It is represented by sending the single byte
43057@code{0x03} without any of the usual packet overhead described in
43058the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43059transmitted as part of a packet, it is considered to be packet data
43060and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 43061(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
43062@code{0x03} as part of its packet.
43063
9a7071a8
JB
43064@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43065When Linux kernel receives this sequence from serial port,
43066it stops execution and connects to gdb.
43067
de979965
PA
43068In non-stop mode, because packet resumptions are asynchronous
43069(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43070command to the remote stub, even when the target is running. For that
43071reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43072packet}) with the usual packet framing instead of the single byte
43073@code{0x03}.
43074
9a6253be
KB
43075Stubs are not required to recognize these interrupt mechanisms and the
43076precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
43077implementation defined. If the target supports debugging of multiple
43078threads and/or processes, it should attempt to interrupt all
43079currently-executing threads and processes.
43080If the stub is successful at interrupting the
43081running program, it should send one of the stop
43082reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43083of successfully stopping the program in all-stop mode, and a stop reply
43084for each stopped thread in non-stop mode.
43085Interrupts received while the
cde67b27
YQ
43086program is stopped are queued and the program will be interrupted when
43087it is resumed next time.
8b23ecc4
SL
43088
43089@node Notification Packets
43090@section Notification Packets
43091@cindex notification packets
43092@cindex packets, notification
43093
43094The @value{GDBN} remote serial protocol includes @dfn{notifications},
43095packets that require no acknowledgment. Both the GDB and the stub
43096may send notifications (although the only notifications defined at
43097present are sent by the stub). Notifications carry information
43098without incurring the round-trip latency of an acknowledgment, and so
43099are useful for low-impact communications where occasional packet loss
43100is not a problem.
43101
43102A notification packet has the form @samp{% @var{data} #
43103@var{checksum}}, where @var{data} is the content of the notification,
43104and @var{checksum} is a checksum of @var{data}, computed and formatted
43105as for ordinary @value{GDBN} packets. A notification's @var{data}
43106never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43107receiving a notification, the recipient sends no @samp{+} or @samp{-}
43108to acknowledge the notification's receipt or to report its corruption.
43109
43110Every notification's @var{data} begins with a name, which contains no
43111colon characters, followed by a colon character.
43112
43113Recipients should silently ignore corrupted notifications and
43114notifications they do not understand. Recipients should restart
43115timeout periods on receipt of a well-formed notification, whether or
43116not they understand it.
43117
43118Senders should only send the notifications described here when this
43119protocol description specifies that they are permitted. In the
43120future, we may extend the protocol to permit existing notifications in
43121new contexts; this rule helps older senders avoid confusing newer
43122recipients.
43123
43124(Older versions of @value{GDBN} ignore bytes received until they see
43125the @samp{$} byte that begins an ordinary packet, so new stubs may
43126transmit notifications without fear of confusing older clients. There
43127are no notifications defined for @value{GDBN} to send at the moment, but we
43128assume that most older stubs would ignore them, as well.)
43129
8dbe8ece 43130Each notification is comprised of three parts:
8b23ecc4 43131@table @samp
8dbe8ece
YQ
43132@item @var{name}:@var{event}
43133The notification packet is sent by the side that initiates the
43134exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
43135carrying the specific information about the notification, and
43136@var{name} specifying the name of the notification.
8dbe8ece
YQ
43137@item @var{ack}
43138The acknowledge sent by the other side, usually @value{GDBN}, to
43139acknowledge the exchange and request the event.
43140@end table
43141
43142The purpose of an asynchronous notification mechanism is to report to
43143@value{GDBN} that something interesting happened in the remote stub.
43144
43145The remote stub may send notification @var{name}:@var{event}
43146at any time, but @value{GDBN} acknowledges the notification when
43147appropriate. The notification event is pending before @value{GDBN}
43148acknowledges. Only one notification at a time may be pending; if
43149additional events occur before @value{GDBN} has acknowledged the
43150previous notification, they must be queued by the stub for later
43151synchronous transmission in response to @var{ack} packets from
43152@value{GDBN}. Because the notification mechanism is unreliable,
43153the stub is permitted to resend a notification if it believes
43154@value{GDBN} may not have received it.
43155
43156Specifically, notifications may appear when @value{GDBN} is not
43157otherwise reading input from the stub, or when @value{GDBN} is
43158expecting to read a normal synchronous response or a
43159@samp{+}/@samp{-} acknowledgment to a packet it has sent.
43160Notification packets are distinct from any other communication from
43161the stub so there is no ambiguity.
43162
43163After receiving a notification, @value{GDBN} shall acknowledge it by
43164sending a @var{ack} packet as a regular, synchronous request to the
43165stub. Such acknowledgment is not required to happen immediately, as
43166@value{GDBN} is permitted to send other, unrelated packets to the
43167stub first, which the stub should process normally.
43168
43169Upon receiving a @var{ack} packet, if the stub has other queued
43170events to report to @value{GDBN}, it shall respond by sending a
43171normal @var{event}. @value{GDBN} shall then send another @var{ack}
43172packet to solicit further responses; again, it is permitted to send
43173other, unrelated packets as well which the stub should process
43174normally.
43175
43176If the stub receives a @var{ack} packet and there are no additional
43177@var{event} to report, the stub shall return an @samp{OK} response.
43178At this point, @value{GDBN} has finished processing a notification
43179and the stub has completed sending any queued events. @value{GDBN}
43180won't accept any new notifications until the final @samp{OK} is
43181received . If further notification events occur, the stub shall send
43182a new notification, @value{GDBN} shall accept the notification, and
43183the process shall be repeated.
43184
43185The process of asynchronous notification can be illustrated by the
43186following example:
43187@smallexample
4435e1cc 43188<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
43189@code{...}
43190-> @code{vStopped}
43191<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
43192-> @code{vStopped}
43193<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
43194-> @code{vStopped}
43195<- @code{OK}
43196@end smallexample
43197
43198The following notifications are defined:
43199@multitable @columnfractions 0.12 0.12 0.38 0.38
43200
43201@item Notification
43202@tab Ack
43203@tab Event
43204@tab Description
43205
43206@item Stop
43207@tab vStopped
43208@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
43209described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
43210for information on how these notifications are acknowledged by
43211@value{GDBN}.
8dbe8ece
YQ
43212@tab Report an asynchronous stop event in non-stop mode.
43213
43214@end multitable
8b23ecc4
SL
43215
43216@node Remote Non-Stop
43217@section Remote Protocol Support for Non-Stop Mode
43218
43219@value{GDBN}'s remote protocol supports non-stop debugging of
43220multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
43221supports non-stop mode, it should report that to @value{GDBN} by including
43222@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
43223
43224@value{GDBN} typically sends a @samp{QNonStop} packet only when
43225establishing a new connection with the stub. Entering non-stop mode
43226does not alter the state of any currently-running threads, but targets
43227must stop all threads in any already-attached processes when entering
43228all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
43229probe the target state after a mode change.
43230
43231In non-stop mode, when an attached process encounters an event that
43232would otherwise be reported with a stop reply, it uses the
43233asynchronous notification mechanism (@pxref{Notification Packets}) to
43234inform @value{GDBN}. In contrast to all-stop mode, where all threads
43235in all processes are stopped when a stop reply is sent, in non-stop
43236mode only the thread reporting the stop event is stopped. That is,
43237when reporting a @samp{S} or @samp{T} response to indicate completion
43238of a step operation, hitting a breakpoint, or a fault, only the
43239affected thread is stopped; any other still-running threads continue
43240to run. When reporting a @samp{W} or @samp{X} response, all running
43241threads belonging to other attached processes continue to run.
43242
8b23ecc4
SL
43243In non-stop mode, the target shall respond to the @samp{?} packet as
43244follows. First, any incomplete stop reply notification/@samp{vStopped}
43245sequence in progress is abandoned. The target must begin a new
43246sequence reporting stop events for all stopped threads, whether or not
43247it has previously reported those events to @value{GDBN}. The first
43248stop reply is sent as a synchronous reply to the @samp{?} packet, and
43249subsequent stop replies are sent as responses to @samp{vStopped} packets
43250using the mechanism described above. The target must not send
43251asynchronous stop reply notifications until the sequence is complete.
43252If all threads are running when the target receives the @samp{?} packet,
43253or if the target is not attached to any process, it shall respond
43254@samp{OK}.
9a6253be 43255
f7e6eed5
PA
43256If the stub supports non-stop mode, it should also support the
43257@samp{swbreak} stop reason if software breakpoints are supported, and
43258the @samp{hwbreak} stop reason if hardware breakpoints are supported
43259(@pxref{swbreak stop reason}). This is because given the asynchronous
43260nature of non-stop mode, between the time a thread hits a breakpoint
43261and the time the event is finally processed by @value{GDBN}, the
43262breakpoint may have already been removed from the target. Due to
43263this, @value{GDBN} needs to be able to tell whether a trap stop was
43264caused by a delayed breakpoint event, which should be ignored, as
43265opposed to a random trap signal, which should be reported to the user.
43266Note the @samp{swbreak} feature implies that the target is responsible
43267for adjusting the PC when a software breakpoint triggers, if
43268necessary, such as on the x86 architecture.
43269
a6f3e723
SL
43270@node Packet Acknowledgment
43271@section Packet Acknowledgment
43272
43273@cindex acknowledgment, for @value{GDBN} remote
43274@cindex packet acknowledgment, for @value{GDBN} remote
43275By default, when either the host or the target machine receives a packet,
43276the first response expected is an acknowledgment: either @samp{+} (to indicate
43277the package was received correctly) or @samp{-} (to request retransmission).
43278This mechanism allows the @value{GDBN} remote protocol to operate over
43279unreliable transport mechanisms, such as a serial line.
43280
43281In cases where the transport mechanism is itself reliable (such as a pipe or
43282TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43283It may be desirable to disable them in that case to reduce communication
43284overhead, or for other reasons. This can be accomplished by means of the
43285@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43286
43287When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43288expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43289and response format still includes the normal checksum, as described in
43290@ref{Overview}, but the checksum may be ignored by the receiver.
43291
43292If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43293no-acknowledgment mode, it should report that to @value{GDBN}
43294by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43295@pxref{qSupported}.
43296If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43297disabled via the @code{set remote noack-packet off} command
43298(@pxref{Remote Configuration}),
43299@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43300Only then may the stub actually turn off packet acknowledgments.
43301@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43302response, which can be safely ignored by the stub.
43303
43304Note that @code{set remote noack-packet} command only affects negotiation
43305between @value{GDBN} and the stub when subsequent connections are made;
43306it does not affect the protocol acknowledgment state for any current
43307connection.
43308Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43309new connection is established,
43310there is also no protocol request to re-enable the acknowledgments
43311for the current connection, once disabled.
43312
ee2d5c50
AC
43313@node Examples
43314@section Examples
eb12ee30 43315
8e04817f
AC
43316Example sequence of a target being re-started. Notice how the restart
43317does not get any direct output:
eb12ee30 43318
474c8240 43319@smallexample
d2c6833e
AC
43320-> @code{R00}
43321<- @code{+}
8e04817f 43322@emph{target restarts}
d2c6833e 43323-> @code{?}
8e04817f 43324<- @code{+}
d2c6833e
AC
43325<- @code{T001:1234123412341234}
43326-> @code{+}
474c8240 43327@end smallexample
eb12ee30 43328
8e04817f 43329Example sequence of a target being stepped by a single instruction:
eb12ee30 43330
474c8240 43331@smallexample
d2c6833e 43332-> @code{G1445@dots{}}
8e04817f 43333<- @code{+}
d2c6833e
AC
43334-> @code{s}
43335<- @code{+}
43336@emph{time passes}
43337<- @code{T001:1234123412341234}
8e04817f 43338-> @code{+}
d2c6833e 43339-> @code{g}
8e04817f 43340<- @code{+}
d2c6833e
AC
43341<- @code{1455@dots{}}
43342-> @code{+}
474c8240 43343@end smallexample
eb12ee30 43344
79a6e687
BW
43345@node File-I/O Remote Protocol Extension
43346@section File-I/O Remote Protocol Extension
0ce1b118
CV
43347@cindex File-I/O remote protocol extension
43348
43349@menu
43350* File-I/O Overview::
79a6e687
BW
43351* Protocol Basics::
43352* The F Request Packet::
43353* The F Reply Packet::
43354* The Ctrl-C Message::
0ce1b118 43355* Console I/O::
79a6e687 43356* List of Supported Calls::
db2e3e2e 43357* Protocol-specific Representation of Datatypes::
0ce1b118
CV
43358* Constants::
43359* File-I/O Examples::
43360@end menu
43361
43362@node File-I/O Overview
43363@subsection File-I/O Overview
43364@cindex file-i/o overview
43365
9c16f35a 43366The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 43367target to use the host's file system and console I/O to perform various
0ce1b118 43368system calls. System calls on the target system are translated into a
fc320d37
SL
43369remote protocol packet to the host system, which then performs the needed
43370actions and returns a response packet to the target system.
0ce1b118
CV
43371This simulates file system operations even on targets that lack file systems.
43372
fc320d37
SL
43373The protocol is defined to be independent of both the host and target systems.
43374It uses its own internal representation of datatypes and values. Both
0ce1b118 43375@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
43376translating the system-dependent value representations into the internal
43377protocol representations when data is transmitted.
0ce1b118 43378
fc320d37
SL
43379The communication is synchronous. A system call is possible only when
43380@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43381or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 43382the target is stopped to allow deterministic access to the target's
fc320d37
SL
43383memory. Therefore File-I/O is not interruptible by target signals. On
43384the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 43385(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
43386
43387The target's request to perform a host system call does not finish
43388the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43389after finishing the system call, the target returns to continuing the
43390previous activity (continue, step). No additional continue or step
43391request from @value{GDBN} is required.
43392
43393@smallexample
f7dc1244 43394(@value{GDBP}) continue
0ce1b118
CV
43395 <- target requests 'system call X'
43396 target is stopped, @value{GDBN} executes system call
3f94c067
BW
43397 -> @value{GDBN} returns result
43398 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
43399 <- target hits breakpoint and sends a Txx packet
43400@end smallexample
43401
fc320d37
SL
43402The protocol only supports I/O on the console and to regular files on
43403the host file system. Character or block special devices, pipes,
43404named pipes, sockets or any other communication method on the host
0ce1b118
CV
43405system are not supported by this protocol.
43406
8b23ecc4
SL
43407File I/O is not supported in non-stop mode.
43408
79a6e687
BW
43409@node Protocol Basics
43410@subsection Protocol Basics
0ce1b118
CV
43411@cindex protocol basics, file-i/o
43412
fc320d37
SL
43413The File-I/O protocol uses the @code{F} packet as the request as well
43414as reply packet. Since a File-I/O system call can only occur when
43415@value{GDBN} is waiting for a response from the continuing or stepping target,
43416the File-I/O request is a reply that @value{GDBN} has to expect as a result
43417of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
43418This @code{F} packet contains all information needed to allow @value{GDBN}
43419to call the appropriate host system call:
43420
43421@itemize @bullet
b383017d 43422@item
0ce1b118
CV
43423A unique identifier for the requested system call.
43424
43425@item
43426All parameters to the system call. Pointers are given as addresses
43427in the target memory address space. Pointers to strings are given as
b383017d 43428pointer/length pair. Numerical values are given as they are.
db2e3e2e 43429Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
43430
43431@end itemize
43432
fc320d37 43433At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
43434
43435@itemize @bullet
b383017d 43436@item
fc320d37
SL
43437If the parameters include pointer values to data needed as input to a
43438system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
43439standard @code{m} packet request. This additional communication has to be
43440expected by the target implementation and is handled as any other @code{m}
43441packet.
43442
43443@item
43444@value{GDBN} translates all value from protocol representation to host
43445representation as needed. Datatypes are coerced into the host types.
43446
43447@item
fc320d37 43448@value{GDBN} calls the system call.
0ce1b118
CV
43449
43450@item
43451It then coerces datatypes back to protocol representation.
43452
43453@item
fc320d37
SL
43454If the system call is expected to return data in buffer space specified
43455by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
43456target using a @code{M} or @code{X} packet. This packet has to be expected
43457by the target implementation and is handled as any other @code{M} or @code{X}
43458packet.
43459
43460@end itemize
43461
43462Eventually @value{GDBN} replies with another @code{F} packet which contains all
43463necessary information for the target to continue. This at least contains
43464
43465@itemize @bullet
43466@item
43467Return value.
43468
43469@item
43470@code{errno}, if has been changed by the system call.
43471
43472@item
43473``Ctrl-C'' flag.
43474
43475@end itemize
43476
43477After having done the needed type and value coercion, the target continues
43478the latest continue or step action.
43479
79a6e687
BW
43480@node The F Request Packet
43481@subsection The @code{F} Request Packet
0ce1b118
CV
43482@cindex file-i/o request packet
43483@cindex @code{F} request packet
43484
43485The @code{F} request packet has the following format:
43486
43487@table @samp
fc320d37 43488@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
43489
43490@var{call-id} is the identifier to indicate the host system call to be called.
43491This is just the name of the function.
43492
fc320d37
SL
43493@var{parameter@dots{}} are the parameters to the system call.
43494Parameters are hexadecimal integer values, either the actual values in case
43495of scalar datatypes, pointers to target buffer space in case of compound
43496datatypes and unspecified memory areas, or pointer/length pairs in case
43497of string parameters. These are appended to the @var{call-id} as a
43498comma-delimited list. All values are transmitted in ASCII
43499string representation, pointer/length pairs separated by a slash.
0ce1b118 43500
b383017d 43501@end table
0ce1b118 43502
fc320d37 43503
0ce1b118 43504
79a6e687
BW
43505@node The F Reply Packet
43506@subsection The @code{F} Reply Packet
0ce1b118
CV
43507@cindex file-i/o reply packet
43508@cindex @code{F} reply packet
43509
43510The @code{F} reply packet has the following format:
43511
43512@table @samp
43513
d3bdde98 43514@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
43515
43516@var{retcode} is the return code of the system call as hexadecimal value.
43517
db2e3e2e
BW
43518@var{errno} is the @code{errno} set by the call, in protocol-specific
43519representation.
0ce1b118
CV
43520This parameter can be omitted if the call was successful.
43521
fc320d37
SL
43522@var{Ctrl-C flag} is only sent if the user requested a break. In this
43523case, @var{errno} must be sent as well, even if the call was successful.
43524The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
43525
43526@smallexample
43527F0,0,C
43528@end smallexample
43529
43530@noindent
fc320d37 43531or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43532
43533@smallexample
43534F-1,4,C
43535@end smallexample
43536
43537@noindent
db2e3e2e 43538assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43539
43540@end table
43541
0ce1b118 43542
79a6e687
BW
43543@node The Ctrl-C Message
43544@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43545@cindex ctrl-c message, in file-i/o protocol
43546
c8aa23ab 43547If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43548reply packet (@pxref{The F Reply Packet}),
fc320d37 43549the target should behave as if it had
0ce1b118 43550gotten a break message. The meaning for the target is ``system call
fc320d37 43551interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43552(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43553packet.
fc320d37
SL
43554
43555It's important for the target to know in which
43556state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43557
43558@itemize @bullet
43559@item
43560The system call hasn't been performed on the host yet.
43561
43562@item
43563The system call on the host has been finished.
43564
43565@end itemize
43566
43567These two states can be distinguished by the target by the value of the
43568returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43569call hasn't been performed. This is equivalent to the @code{EINTR} handling
43570on POSIX systems. In any other case, the target may presume that the
fc320d37 43571system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43572as if the break message arrived right after the system call.
43573
fc320d37 43574@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43575yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43576@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43577before the user requests a break, the full action must be finished by
43578@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43579The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43580or the full action has been completed.
43581
43582@node Console I/O
43583@subsection Console I/O
43584@cindex console i/o as part of file-i/o
43585
d3e8051b 43586By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43587descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43588on the @value{GDBN} console is handled as any other file output operation
43589(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43590by @value{GDBN} so that after the target read request from file descriptor
435910 all following typing is buffered until either one of the following
43592conditions is met:
43593
43594@itemize @bullet
43595@item
c8aa23ab 43596The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43597@code{read}
43598system call is treated as finished.
43599
43600@item
7f9087cb 43601The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43602newline.
0ce1b118
CV
43603
43604@item
c8aa23ab
EZ
43605The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43606character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43607
43608@end itemize
43609
fc320d37
SL
43610If the user has typed more characters than fit in the buffer given to
43611the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43612either another @code{read(0, @dots{})} is requested by the target, or debugging
43613is stopped at the user's request.
0ce1b118 43614
0ce1b118 43615
79a6e687
BW
43616@node List of Supported Calls
43617@subsection List of Supported Calls
0ce1b118
CV
43618@cindex list of supported file-i/o calls
43619
43620@menu
43621* open::
43622* close::
43623* read::
43624* write::
43625* lseek::
43626* rename::
43627* unlink::
43628* stat/fstat::
43629* gettimeofday::
43630* isatty::
43631* system::
43632@end menu
43633
43634@node open
43635@unnumberedsubsubsec open
43636@cindex open, file-i/o system call
43637
fc320d37
SL
43638@table @asis
43639@item Synopsis:
0ce1b118 43640@smallexample
0ce1b118
CV
43641int open(const char *pathname, int flags);
43642int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43643@end smallexample
43644
fc320d37
SL
43645@item Request:
43646@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43647
0ce1b118 43648@noindent
fc320d37 43649@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43650
43651@table @code
b383017d 43652@item O_CREAT
0ce1b118
CV
43653If the file does not exist it will be created. The host
43654rules apply as far as file ownership and time stamps
43655are concerned.
43656
b383017d 43657@item O_EXCL
fc320d37 43658When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43659an error and open() fails.
43660
b383017d 43661@item O_TRUNC
0ce1b118 43662If the file already exists and the open mode allows
fc320d37
SL
43663writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43664truncated to zero length.
0ce1b118 43665
b383017d 43666@item O_APPEND
0ce1b118
CV
43667The file is opened in append mode.
43668
b383017d 43669@item O_RDONLY
0ce1b118
CV
43670The file is opened for reading only.
43671
b383017d 43672@item O_WRONLY
0ce1b118
CV
43673The file is opened for writing only.
43674
b383017d 43675@item O_RDWR
0ce1b118 43676The file is opened for reading and writing.
fc320d37 43677@end table
0ce1b118
CV
43678
43679@noindent
fc320d37 43680Other bits are silently ignored.
0ce1b118 43681
0ce1b118
CV
43682
43683@noindent
fc320d37 43684@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43685
43686@table @code
b383017d 43687@item S_IRUSR
0ce1b118
CV
43688User has read permission.
43689
b383017d 43690@item S_IWUSR
0ce1b118
CV
43691User has write permission.
43692
b383017d 43693@item S_IRGRP
0ce1b118
CV
43694Group has read permission.
43695
b383017d 43696@item S_IWGRP
0ce1b118
CV
43697Group has write permission.
43698
b383017d 43699@item S_IROTH
0ce1b118
CV
43700Others have read permission.
43701
b383017d 43702@item S_IWOTH
0ce1b118 43703Others have write permission.
fc320d37 43704@end table
0ce1b118
CV
43705
43706@noindent
fc320d37 43707Other bits are silently ignored.
0ce1b118 43708
0ce1b118 43709
fc320d37
SL
43710@item Return value:
43711@code{open} returns the new file descriptor or -1 if an error
43712occurred.
0ce1b118 43713
fc320d37 43714@item Errors:
0ce1b118
CV
43715
43716@table @code
b383017d 43717@item EEXIST
fc320d37 43718@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43719
b383017d 43720@item EISDIR
fc320d37 43721@var{pathname} refers to a directory.
0ce1b118 43722
b383017d 43723@item EACCES
0ce1b118
CV
43724The requested access is not allowed.
43725
43726@item ENAMETOOLONG
fc320d37 43727@var{pathname} was too long.
0ce1b118 43728
b383017d 43729@item ENOENT
fc320d37 43730A directory component in @var{pathname} does not exist.
0ce1b118 43731
b383017d 43732@item ENODEV
fc320d37 43733@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43734
b383017d 43735@item EROFS
fc320d37 43736@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43737write access was requested.
43738
b383017d 43739@item EFAULT
fc320d37 43740@var{pathname} is an invalid pointer value.
0ce1b118 43741
b383017d 43742@item ENOSPC
0ce1b118
CV
43743No space on device to create the file.
43744
b383017d 43745@item EMFILE
0ce1b118
CV
43746The process already has the maximum number of files open.
43747
b383017d 43748@item ENFILE
0ce1b118
CV
43749The limit on the total number of files open on the system
43750has been reached.
43751
b383017d 43752@item EINTR
0ce1b118
CV
43753The call was interrupted by the user.
43754@end table
43755
fc320d37
SL
43756@end table
43757
0ce1b118
CV
43758@node close
43759@unnumberedsubsubsec close
43760@cindex close, file-i/o system call
43761
fc320d37
SL
43762@table @asis
43763@item Synopsis:
0ce1b118 43764@smallexample
0ce1b118 43765int close(int fd);
fc320d37 43766@end smallexample
0ce1b118 43767
fc320d37
SL
43768@item Request:
43769@samp{Fclose,@var{fd}}
0ce1b118 43770
fc320d37
SL
43771@item Return value:
43772@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43773
fc320d37 43774@item Errors:
0ce1b118
CV
43775
43776@table @code
b383017d 43777@item EBADF
fc320d37 43778@var{fd} isn't a valid open file descriptor.
0ce1b118 43779
b383017d 43780@item EINTR
0ce1b118
CV
43781The call was interrupted by the user.
43782@end table
43783
fc320d37
SL
43784@end table
43785
0ce1b118
CV
43786@node read
43787@unnumberedsubsubsec read
43788@cindex read, file-i/o system call
43789
fc320d37
SL
43790@table @asis
43791@item Synopsis:
0ce1b118 43792@smallexample
0ce1b118 43793int read(int fd, void *buf, unsigned int count);
fc320d37 43794@end smallexample
0ce1b118 43795
fc320d37
SL
43796@item Request:
43797@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43798
fc320d37 43799@item Return value:
0ce1b118
CV
43800On success, the number of bytes read is returned.
43801Zero indicates end of file. If count is zero, read
b383017d 43802returns zero as well. On error, -1 is returned.
0ce1b118 43803
fc320d37 43804@item Errors:
0ce1b118
CV
43805
43806@table @code
b383017d 43807@item EBADF
fc320d37 43808@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43809reading.
43810
b383017d 43811@item EFAULT
fc320d37 43812@var{bufptr} is an invalid pointer value.
0ce1b118 43813
b383017d 43814@item EINTR
0ce1b118
CV
43815The call was interrupted by the user.
43816@end table
43817
fc320d37
SL
43818@end table
43819
0ce1b118
CV
43820@node write
43821@unnumberedsubsubsec write
43822@cindex write, file-i/o system call
43823
fc320d37
SL
43824@table @asis
43825@item Synopsis:
0ce1b118 43826@smallexample
0ce1b118 43827int write(int fd, const void *buf, unsigned int count);
fc320d37 43828@end smallexample
0ce1b118 43829
fc320d37
SL
43830@item Request:
43831@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43832
fc320d37 43833@item Return value:
0ce1b118
CV
43834On success, the number of bytes written are returned.
43835Zero indicates nothing was written. On error, -1
43836is returned.
43837
fc320d37 43838@item Errors:
0ce1b118
CV
43839
43840@table @code
b383017d 43841@item EBADF
fc320d37 43842@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43843writing.
43844
b383017d 43845@item EFAULT
fc320d37 43846@var{bufptr} is an invalid pointer value.
0ce1b118 43847
b383017d 43848@item EFBIG
0ce1b118 43849An attempt was made to write a file that exceeds the
db2e3e2e 43850host-specific maximum file size allowed.
0ce1b118 43851
b383017d 43852@item ENOSPC
0ce1b118
CV
43853No space on device to write the data.
43854
b383017d 43855@item EINTR
0ce1b118
CV
43856The call was interrupted by the user.
43857@end table
43858
fc320d37
SL
43859@end table
43860
0ce1b118
CV
43861@node lseek
43862@unnumberedsubsubsec lseek
43863@cindex lseek, file-i/o system call
43864
fc320d37
SL
43865@table @asis
43866@item Synopsis:
0ce1b118 43867@smallexample
0ce1b118 43868long lseek (int fd, long offset, int flag);
0ce1b118
CV
43869@end smallexample
43870
fc320d37
SL
43871@item Request:
43872@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43873
43874@var{flag} is one of:
0ce1b118
CV
43875
43876@table @code
b383017d 43877@item SEEK_SET
fc320d37 43878The offset is set to @var{offset} bytes.
0ce1b118 43879
b383017d 43880@item SEEK_CUR
fc320d37 43881The offset is set to its current location plus @var{offset}
0ce1b118
CV
43882bytes.
43883
b383017d 43884@item SEEK_END
fc320d37 43885The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43886bytes.
43887@end table
43888
fc320d37 43889@item Return value:
0ce1b118
CV
43890On success, the resulting unsigned offset in bytes from
43891the beginning of the file is returned. Otherwise, a
43892value of -1 is returned.
43893
fc320d37 43894@item Errors:
0ce1b118
CV
43895
43896@table @code
b383017d 43897@item EBADF
fc320d37 43898@var{fd} is not a valid open file descriptor.
0ce1b118 43899
b383017d 43900@item ESPIPE
fc320d37 43901@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43902
b383017d 43903@item EINVAL
fc320d37 43904@var{flag} is not a proper value.
0ce1b118 43905
b383017d 43906@item EINTR
0ce1b118
CV
43907The call was interrupted by the user.
43908@end table
43909
fc320d37
SL
43910@end table
43911
0ce1b118
CV
43912@node rename
43913@unnumberedsubsubsec rename
43914@cindex rename, file-i/o system call
43915
fc320d37
SL
43916@table @asis
43917@item Synopsis:
0ce1b118 43918@smallexample
0ce1b118 43919int rename(const char *oldpath, const char *newpath);
fc320d37 43920@end smallexample
0ce1b118 43921
fc320d37
SL
43922@item Request:
43923@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43924
fc320d37 43925@item Return value:
0ce1b118
CV
43926On success, zero is returned. On error, -1 is returned.
43927
fc320d37 43928@item Errors:
0ce1b118
CV
43929
43930@table @code
b383017d 43931@item EISDIR
fc320d37 43932@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43933directory.
43934
b383017d 43935@item EEXIST
fc320d37 43936@var{newpath} is a non-empty directory.
0ce1b118 43937
b383017d 43938@item EBUSY
fc320d37 43939@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43940process.
43941
b383017d 43942@item EINVAL
0ce1b118
CV
43943An attempt was made to make a directory a subdirectory
43944of itself.
43945
b383017d 43946@item ENOTDIR
fc320d37
SL
43947A component used as a directory in @var{oldpath} or new
43948path is not a directory. Or @var{oldpath} is a directory
43949and @var{newpath} exists but is not a directory.
0ce1b118 43950
b383017d 43951@item EFAULT
fc320d37 43952@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43953
b383017d 43954@item EACCES
0ce1b118
CV
43955No access to the file or the path of the file.
43956
43957@item ENAMETOOLONG
b383017d 43958
fc320d37 43959@var{oldpath} or @var{newpath} was too long.
0ce1b118 43960
b383017d 43961@item ENOENT
fc320d37 43962A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 43963
b383017d 43964@item EROFS
0ce1b118
CV
43965The file is on a read-only filesystem.
43966
b383017d 43967@item ENOSPC
0ce1b118
CV
43968The device containing the file has no room for the new
43969directory entry.
43970
b383017d 43971@item EINTR
0ce1b118
CV
43972The call was interrupted by the user.
43973@end table
43974
fc320d37
SL
43975@end table
43976
0ce1b118
CV
43977@node unlink
43978@unnumberedsubsubsec unlink
43979@cindex unlink, file-i/o system call
43980
fc320d37
SL
43981@table @asis
43982@item Synopsis:
0ce1b118 43983@smallexample
0ce1b118 43984int unlink(const char *pathname);
fc320d37 43985@end smallexample
0ce1b118 43986
fc320d37
SL
43987@item Request:
43988@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 43989
fc320d37 43990@item Return value:
0ce1b118
CV
43991On success, zero is returned. On error, -1 is returned.
43992
fc320d37 43993@item Errors:
0ce1b118
CV
43994
43995@table @code
b383017d 43996@item EACCES
0ce1b118
CV
43997No access to the file or the path of the file.
43998
b383017d 43999@item EPERM
0ce1b118
CV
44000The system does not allow unlinking of directories.
44001
b383017d 44002@item EBUSY
fc320d37 44003The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
44004being used by another process.
44005
b383017d 44006@item EFAULT
fc320d37 44007@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
44008
44009@item ENAMETOOLONG
fc320d37 44010@var{pathname} was too long.
0ce1b118 44011
b383017d 44012@item ENOENT
fc320d37 44013A directory component in @var{pathname} does not exist.
0ce1b118 44014
b383017d 44015@item ENOTDIR
0ce1b118
CV
44016A component of the path is not a directory.
44017
b383017d 44018@item EROFS
0ce1b118
CV
44019The file is on a read-only filesystem.
44020
b383017d 44021@item EINTR
0ce1b118
CV
44022The call was interrupted by the user.
44023@end table
44024
fc320d37
SL
44025@end table
44026
0ce1b118
CV
44027@node stat/fstat
44028@unnumberedsubsubsec stat/fstat
44029@cindex fstat, file-i/o system call
44030@cindex stat, file-i/o system call
44031
fc320d37
SL
44032@table @asis
44033@item Synopsis:
0ce1b118 44034@smallexample
0ce1b118
CV
44035int stat(const char *pathname, struct stat *buf);
44036int fstat(int fd, struct stat *buf);
fc320d37 44037@end smallexample
0ce1b118 44038
fc320d37
SL
44039@item Request:
44040@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44041@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 44042
fc320d37 44043@item Return value:
0ce1b118
CV
44044On success, zero is returned. On error, -1 is returned.
44045
fc320d37 44046@item Errors:
0ce1b118
CV
44047
44048@table @code
b383017d 44049@item EBADF
fc320d37 44050@var{fd} is not a valid open file.
0ce1b118 44051
b383017d 44052@item ENOENT
fc320d37 44053A directory component in @var{pathname} does not exist or the
0ce1b118
CV
44054path is an empty string.
44055
b383017d 44056@item ENOTDIR
0ce1b118
CV
44057A component of the path is not a directory.
44058
b383017d 44059@item EFAULT
fc320d37 44060@var{pathnameptr} is an invalid pointer value.
0ce1b118 44061
b383017d 44062@item EACCES
0ce1b118
CV
44063No access to the file or the path of the file.
44064
44065@item ENAMETOOLONG
fc320d37 44066@var{pathname} was too long.
0ce1b118 44067
b383017d 44068@item EINTR
0ce1b118
CV
44069The call was interrupted by the user.
44070@end table
44071
fc320d37
SL
44072@end table
44073
0ce1b118
CV
44074@node gettimeofday
44075@unnumberedsubsubsec gettimeofday
44076@cindex gettimeofday, file-i/o system call
44077
fc320d37
SL
44078@table @asis
44079@item Synopsis:
0ce1b118 44080@smallexample
0ce1b118 44081int gettimeofday(struct timeval *tv, void *tz);
fc320d37 44082@end smallexample
0ce1b118 44083
fc320d37
SL
44084@item Request:
44085@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 44086
fc320d37 44087@item Return value:
0ce1b118
CV
44088On success, 0 is returned, -1 otherwise.
44089
fc320d37 44090@item Errors:
0ce1b118
CV
44091
44092@table @code
b383017d 44093@item EINVAL
fc320d37 44094@var{tz} is a non-NULL pointer.
0ce1b118 44095
b383017d 44096@item EFAULT
fc320d37
SL
44097@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44098@end table
44099
0ce1b118
CV
44100@end table
44101
44102@node isatty
44103@unnumberedsubsubsec isatty
44104@cindex isatty, file-i/o system call
44105
fc320d37
SL
44106@table @asis
44107@item Synopsis:
0ce1b118 44108@smallexample
0ce1b118 44109int isatty(int fd);
fc320d37 44110@end smallexample
0ce1b118 44111
fc320d37
SL
44112@item Request:
44113@samp{Fisatty,@var{fd}}
0ce1b118 44114
fc320d37
SL
44115@item Return value:
44116Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 44117
fc320d37 44118@item Errors:
0ce1b118
CV
44119
44120@table @code
b383017d 44121@item EINTR
0ce1b118
CV
44122The call was interrupted by the user.
44123@end table
44124
fc320d37
SL
44125@end table
44126
44127Note that the @code{isatty} call is treated as a special case: it returns
441281 to the target if the file descriptor is attached
44129to the @value{GDBN} console, 0 otherwise. Implementing through system calls
44130would require implementing @code{ioctl} and would be more complex than
44131needed.
44132
44133
0ce1b118
CV
44134@node system
44135@unnumberedsubsubsec system
44136@cindex system, file-i/o system call
44137
fc320d37
SL
44138@table @asis
44139@item Synopsis:
0ce1b118 44140@smallexample
0ce1b118 44141int system(const char *command);
fc320d37 44142@end smallexample
0ce1b118 44143
fc320d37
SL
44144@item Request:
44145@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 44146
fc320d37 44147@item Return value:
5600ea19
NS
44148If @var{len} is zero, the return value indicates whether a shell is
44149available. A zero return value indicates a shell is not available.
44150For non-zero @var{len}, the value returned is -1 on error and the
44151return status of the command otherwise. Only the exit status of the
44152command is returned, which is extracted from the host's @code{system}
44153return value by calling @code{WEXITSTATUS(retval)}. In case
44154@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 44155
fc320d37 44156@item Errors:
0ce1b118
CV
44157
44158@table @code
b383017d 44159@item EINTR
0ce1b118
CV
44160The call was interrupted by the user.
44161@end table
44162
fc320d37
SL
44163@end table
44164
44165@value{GDBN} takes over the full task of calling the necessary host calls
44166to perform the @code{system} call. The return value of @code{system} on
44167the host is simplified before it's returned
44168to the target. Any termination signal information from the child process
44169is discarded, and the return value consists
44170entirely of the exit status of the called command.
44171
44172Due to security concerns, the @code{system} call is by default refused
44173by @value{GDBN}. The user has to allow this call explicitly with the
44174@code{set remote system-call-allowed 1} command.
44175
44176@table @code
44177@item set remote system-call-allowed
44178@kindex set remote system-call-allowed
44179Control whether to allow the @code{system} calls in the File I/O
44180protocol for the remote target. The default is zero (disabled).
44181
44182@item show remote system-call-allowed
44183@kindex show remote system-call-allowed
44184Show whether the @code{system} calls are allowed in the File I/O
44185protocol.
44186@end table
44187
db2e3e2e
BW
44188@node Protocol-specific Representation of Datatypes
44189@subsection Protocol-specific Representation of Datatypes
44190@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
44191
44192@menu
79a6e687
BW
44193* Integral Datatypes::
44194* Pointer Values::
44195* Memory Transfer::
0ce1b118
CV
44196* struct stat::
44197* struct timeval::
44198@end menu
44199
79a6e687
BW
44200@node Integral Datatypes
44201@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
44202@cindex integral datatypes, in file-i/o protocol
44203
fc320d37
SL
44204The integral datatypes used in the system calls are @code{int},
44205@code{unsigned int}, @code{long}, @code{unsigned long},
44206@code{mode_t}, and @code{time_t}.
0ce1b118 44207
fc320d37 44208@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
44209implemented as 32 bit values in this protocol.
44210
fc320d37 44211@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 44212
0ce1b118
CV
44213@xref{Limits}, for corresponding MIN and MAX values (similar to those
44214in @file{limits.h}) to allow range checking on host and target.
44215
44216@code{time_t} datatypes are defined as seconds since the Epoch.
44217
44218All integral datatypes transferred as part of a memory read or write of a
44219structured datatype e.g.@: a @code{struct stat} have to be given in big endian
44220byte order.
44221
79a6e687
BW
44222@node Pointer Values
44223@unnumberedsubsubsec Pointer Values
0ce1b118
CV
44224@cindex pointer values, in file-i/o protocol
44225
44226Pointers to target data are transmitted as they are. An exception
44227is made for pointers to buffers for which the length isn't
44228transmitted as part of the function call, namely strings. Strings
44229are transmitted as a pointer/length pair, both as hex values, e.g.@:
44230
44231@smallexample
44232@code{1aaf/12}
44233@end smallexample
44234
44235@noindent
44236which is a pointer to data of length 18 bytes at position 0x1aaf.
44237The length is defined as the full string length in bytes, including
fc320d37
SL
44238the trailing null byte. For example, the string @code{"hello world"}
44239at address 0x123456 is transmitted as
0ce1b118
CV
44240
44241@smallexample
fc320d37 44242@code{123456/d}
0ce1b118
CV
44243@end smallexample
44244
79a6e687
BW
44245@node Memory Transfer
44246@unnumberedsubsubsec Memory Transfer
fc320d37
SL
44247@cindex memory transfer, in file-i/o protocol
44248
44249Structured data which is transferred using a memory read or write (for
db2e3e2e 44250example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
44251with all scalar multibyte datatypes being big endian. Translation to
44252this representation needs to be done both by the target before the @code{F}
44253packet is sent, and by @value{GDBN} before
44254it transfers memory to the target. Transferred pointers to structured
44255data should point to the already-coerced data at any time.
0ce1b118 44256
0ce1b118
CV
44257
44258@node struct stat
44259@unnumberedsubsubsec struct stat
44260@cindex struct stat, in file-i/o protocol
44261
fc320d37
SL
44262The buffer of type @code{struct stat} used by the target and @value{GDBN}
44263is defined as follows:
0ce1b118
CV
44264
44265@smallexample
44266struct stat @{
44267 unsigned int st_dev; /* device */
44268 unsigned int st_ino; /* inode */
44269 mode_t st_mode; /* protection */
44270 unsigned int st_nlink; /* number of hard links */
44271 unsigned int st_uid; /* user ID of owner */
44272 unsigned int st_gid; /* group ID of owner */
44273 unsigned int st_rdev; /* device type (if inode device) */
44274 unsigned long st_size; /* total size, in bytes */
44275 unsigned long st_blksize; /* blocksize for filesystem I/O */
44276 unsigned long st_blocks; /* number of blocks allocated */
44277 time_t st_atime; /* time of last access */
44278 time_t st_mtime; /* time of last modification */
44279 time_t st_ctime; /* time of last change */
44280@};
44281@end smallexample
44282
fc320d37 44283The integral datatypes conform to the definitions given in the
79a6e687 44284appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44285structure is of size 64 bytes.
44286
44287The values of several fields have a restricted meaning and/or
44288range of values.
44289
fc320d37 44290@table @code
0ce1b118 44291
fc320d37
SL
44292@item st_dev
44293A value of 0 represents a file, 1 the console.
0ce1b118 44294
fc320d37
SL
44295@item st_ino
44296No valid meaning for the target. Transmitted unchanged.
0ce1b118 44297
fc320d37
SL
44298@item st_mode
44299Valid mode bits are described in @ref{Constants}. Any other
44300bits have currently no meaning for the target.
0ce1b118 44301
fc320d37
SL
44302@item st_uid
44303@itemx st_gid
44304@itemx st_rdev
44305No valid meaning for the target. Transmitted unchanged.
0ce1b118 44306
fc320d37
SL
44307@item st_atime
44308@itemx st_mtime
44309@itemx st_ctime
44310These values have a host and file system dependent
44311accuracy. Especially on Windows hosts, the file system may not
44312support exact timing values.
44313@end table
0ce1b118 44314
fc320d37
SL
44315The target gets a @code{struct stat} of the above representation and is
44316responsible for coercing it to the target representation before
0ce1b118
CV
44317continuing.
44318
fc320d37
SL
44319Note that due to size differences between the host, target, and protocol
44320representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
44321get truncated on the target.
44322
44323@node struct timeval
44324@unnumberedsubsubsec struct timeval
44325@cindex struct timeval, in file-i/o protocol
44326
fc320d37 44327The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
44328is defined as follows:
44329
44330@smallexample
b383017d 44331struct timeval @{
0ce1b118
CV
44332 time_t tv_sec; /* second */
44333 long tv_usec; /* microsecond */
44334@};
44335@end smallexample
44336
fc320d37 44337The integral datatypes conform to the definitions given in the
79a6e687 44338appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44339structure is of size 8 bytes.
44340
44341@node Constants
44342@subsection Constants
44343@cindex constants, in file-i/o protocol
44344
44345The following values are used for the constants inside of the
fc320d37 44346protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
44347values before and after the call as needed.
44348
44349@menu
79a6e687
BW
44350* Open Flags::
44351* mode_t Values::
44352* Errno Values::
44353* Lseek Flags::
0ce1b118
CV
44354* Limits::
44355@end menu
44356
79a6e687
BW
44357@node Open Flags
44358@unnumberedsubsubsec Open Flags
0ce1b118
CV
44359@cindex open flags, in file-i/o protocol
44360
44361All values are given in hexadecimal representation.
44362
44363@smallexample
44364 O_RDONLY 0x0
44365 O_WRONLY 0x1
44366 O_RDWR 0x2
44367 O_APPEND 0x8
44368 O_CREAT 0x200
44369 O_TRUNC 0x400
44370 O_EXCL 0x800
44371@end smallexample
44372
79a6e687
BW
44373@node mode_t Values
44374@unnumberedsubsubsec mode_t Values
0ce1b118
CV
44375@cindex mode_t values, in file-i/o protocol
44376
44377All values are given in octal representation.
44378
44379@smallexample
44380 S_IFREG 0100000
44381 S_IFDIR 040000
44382 S_IRUSR 0400
44383 S_IWUSR 0200
44384 S_IXUSR 0100
44385 S_IRGRP 040
44386 S_IWGRP 020
44387 S_IXGRP 010
44388 S_IROTH 04
44389 S_IWOTH 02
44390 S_IXOTH 01
44391@end smallexample
44392
79a6e687
BW
44393@node Errno Values
44394@unnumberedsubsubsec Errno Values
0ce1b118
CV
44395@cindex errno values, in file-i/o protocol
44396
44397All values are given in decimal representation.
44398
44399@smallexample
44400 EPERM 1
44401 ENOENT 2
44402 EINTR 4
44403 EBADF 9
44404 EACCES 13
44405 EFAULT 14
44406 EBUSY 16
44407 EEXIST 17
44408 ENODEV 19
44409 ENOTDIR 20
44410 EISDIR 21
44411 EINVAL 22
44412 ENFILE 23
44413 EMFILE 24
44414 EFBIG 27
44415 ENOSPC 28
44416 ESPIPE 29
44417 EROFS 30
44418 ENAMETOOLONG 91
44419 EUNKNOWN 9999
44420@end smallexample
44421
fc320d37 44422 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
44423 any error value not in the list of supported error numbers.
44424
79a6e687
BW
44425@node Lseek Flags
44426@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
44427@cindex lseek flags, in file-i/o protocol
44428
44429@smallexample
44430 SEEK_SET 0
44431 SEEK_CUR 1
44432 SEEK_END 2
44433@end smallexample
44434
44435@node Limits
44436@unnumberedsubsubsec Limits
44437@cindex limits, in file-i/o protocol
44438
44439All values are given in decimal representation.
44440
44441@smallexample
44442 INT_MIN -2147483648
44443 INT_MAX 2147483647
44444 UINT_MAX 4294967295
44445 LONG_MIN -9223372036854775808
44446 LONG_MAX 9223372036854775807
44447 ULONG_MAX 18446744073709551615
44448@end smallexample
44449
44450@node File-I/O Examples
44451@subsection File-I/O Examples
44452@cindex file-i/o examples
44453
44454Example sequence of a write call, file descriptor 3, buffer is at target
44455address 0x1234, 6 bytes should be written:
44456
44457@smallexample
44458<- @code{Fwrite,3,1234,6}
44459@emph{request memory read from target}
44460-> @code{m1234,6}
44461<- XXXXXX
44462@emph{return "6 bytes written"}
44463-> @code{F6}
44464@end smallexample
44465
44466Example sequence of a read call, file descriptor 3, buffer is at target
44467address 0x1234, 6 bytes should be read:
44468
44469@smallexample
44470<- @code{Fread,3,1234,6}
44471@emph{request memory write to target}
44472-> @code{X1234,6:XXXXXX}
44473@emph{return "6 bytes read"}
44474-> @code{F6}
44475@end smallexample
44476
44477Example sequence of a read call, call fails on the host due to invalid
fc320d37 44478file descriptor (@code{EBADF}):
0ce1b118
CV
44479
44480@smallexample
44481<- @code{Fread,3,1234,6}
44482-> @code{F-1,9}
44483@end smallexample
44484
c8aa23ab 44485Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
44486host is called:
44487
44488@smallexample
44489<- @code{Fread,3,1234,6}
44490-> @code{F-1,4,C}
44491<- @code{T02}
44492@end smallexample
44493
c8aa23ab 44494Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
44495host is called:
44496
44497@smallexample
44498<- @code{Fread,3,1234,6}
44499-> @code{X1234,6:XXXXXX}
44500<- @code{T02}
44501@end smallexample
44502
cfa9d6d9
DJ
44503@node Library List Format
44504@section Library List Format
44505@cindex library list format, remote protocol
44506
44507On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44508same process as your application to manage libraries. In this case,
44509@value{GDBN} can use the loader's symbol table and normal memory
44510operations to maintain a list of shared libraries. On other
44511platforms, the operating system manages loaded libraries.
44512@value{GDBN} can not retrieve the list of currently loaded libraries
44513through memory operations, so it uses the @samp{qXfer:libraries:read}
44514packet (@pxref{qXfer library list read}) instead. The remote stub
44515queries the target's operating system and reports which libraries
44516are loaded.
44517
44518The @samp{qXfer:libraries:read} packet returns an XML document which
44519lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
44520associated name and one or more segment or section base addresses,
44521which report where the library was loaded in memory.
44522
44523For the common case of libraries that are fully linked binaries, the
44524library should have a list of segments. If the target supports
44525dynamic linking of a relocatable object file, its library XML element
44526should instead include a list of allocated sections. The segment or
44527section bases are start addresses, not relocation offsets; they do not
44528depend on the library's link-time base addresses.
cfa9d6d9 44529
9cceb671
DJ
44530@value{GDBN} must be linked with the Expat library to support XML
44531library lists. @xref{Expat}.
44532
cfa9d6d9
DJ
44533A simple memory map, with one loaded library relocated by a single
44534offset, looks like this:
44535
44536@smallexample
44537<library-list>
44538 <library name="/lib/libc.so.6">
44539 <segment address="0x10000000"/>
44540 </library>
44541</library-list>
44542@end smallexample
44543
1fddbabb
PA
44544Another simple memory map, with one loaded library with three
44545allocated sections (.text, .data, .bss), looks like this:
44546
44547@smallexample
44548<library-list>
44549 <library name="sharedlib.o">
44550 <section address="0x10000000"/>
44551 <section address="0x20000000"/>
44552 <section address="0x30000000"/>
44553 </library>
44554</library-list>
44555@end smallexample
44556
cfa9d6d9
DJ
44557The format of a library list is described by this DTD:
44558
44559@smallexample
44560<!-- library-list: Root element with versioning -->
44561<!ELEMENT library-list (library)*>
44562<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44563<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44564<!ATTLIST library name CDATA #REQUIRED>
44565<!ELEMENT segment EMPTY>
44566<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44567<!ELEMENT section EMPTY>
44568<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44569@end smallexample
44570
1fddbabb
PA
44571In addition, segments and section descriptors cannot be mixed within a
44572single library element, and you must supply at least one segment or
44573section for each library.
44574
2268b414
JK
44575@node Library List Format for SVR4 Targets
44576@section Library List Format for SVR4 Targets
44577@cindex library list format, remote protocol
44578
44579On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44580(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44581shared libraries. Still a special library list provided by this packet is
44582more efficient for the @value{GDBN} remote protocol.
44583
44584The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44585loaded libraries and their SVR4 linker parameters. For each library on SVR4
44586target, the following parameters are reported:
44587
44588@itemize @minus
44589@item
44590@code{name}, the absolute file name from the @code{l_name} field of
44591@code{struct link_map}.
44592@item
44593@code{lm} with address of @code{struct link_map} used for TLS
44594(Thread Local Storage) access.
44595@item
44596@code{l_addr}, the displacement as read from the field @code{l_addr} of
44597@code{struct link_map}. For prelinked libraries this is not an absolute
44598memory address. It is a displacement of absolute memory address against
44599address the file was prelinked to during the library load.
44600@item
44601@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44602@end itemize
44603
44604Additionally the single @code{main-lm} attribute specifies address of
44605@code{struct link_map} used for the main executable. This parameter is used
44606for TLS access and its presence is optional.
44607
44608@value{GDBN} must be linked with the Expat library to support XML
44609SVR4 library lists. @xref{Expat}.
44610
44611A simple memory map, with two loaded libraries (which do not use prelink),
44612looks like this:
44613
44614@smallexample
44615<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44616 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44617 l_ld="0xe4eefc"/>
44618 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44619 l_ld="0x152350"/>
2268b414
JK
44620</library-list-svr>
44621@end smallexample
44622
44623The format of an SVR4 library list is described by this DTD:
44624
44625@smallexample
44626<!-- library-list-svr4: Root element with versioning -->
44627<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44628<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44629<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44630<!ELEMENT library EMPTY>
db1ff28b
JK
44631<!ATTLIST library name CDATA #REQUIRED>
44632<!ATTLIST library lm CDATA #REQUIRED>
44633<!ATTLIST library l_addr CDATA #REQUIRED>
44634<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44635@end smallexample
44636
79a6e687
BW
44637@node Memory Map Format
44638@section Memory Map Format
68437a39
DJ
44639@cindex memory map format
44640
44641To be able to write into flash memory, @value{GDBN} needs to obtain a
44642memory map from the target. This section describes the format of the
44643memory map.
44644
44645The memory map is obtained using the @samp{qXfer:memory-map:read}
44646(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44647lists memory regions.
44648
44649@value{GDBN} must be linked with the Expat library to support XML
44650memory maps. @xref{Expat}.
44651
44652The top-level structure of the document is shown below:
68437a39
DJ
44653
44654@smallexample
44655<?xml version="1.0"?>
44656<!DOCTYPE memory-map
44657 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44658 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44659<memory-map>
44660 region...
44661</memory-map>
44662@end smallexample
44663
44664Each region can be either:
44665
44666@itemize
44667
44668@item
44669A region of RAM starting at @var{addr} and extending for @var{length}
44670bytes from there:
44671
44672@smallexample
44673<memory type="ram" start="@var{addr}" length="@var{length}"/>
44674@end smallexample
44675
44676
44677@item
44678A region of read-only memory:
44679
44680@smallexample
44681<memory type="rom" start="@var{addr}" length="@var{length}"/>
44682@end smallexample
44683
44684
44685@item
44686A region of flash memory, with erasure blocks @var{blocksize}
44687bytes in length:
44688
44689@smallexample
44690<memory type="flash" start="@var{addr}" length="@var{length}">
44691 <property name="blocksize">@var{blocksize}</property>
44692</memory>
44693@end smallexample
44694
44695@end itemize
44696
44697Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44698by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44699packets to write to addresses in such ranges.
44700
44701The formal DTD for memory map format is given below:
44702
44703@smallexample
44704<!-- ................................................... -->
44705<!-- Memory Map XML DTD ................................ -->
44706<!-- File: memory-map.dtd .............................. -->
44707<!-- .................................... .............. -->
44708<!-- memory-map.dtd -->
44709<!-- memory-map: Root element with versioning -->
5f1ca24a 44710<!ELEMENT memory-map (memory)*>
68437a39 44711<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44712<!ELEMENT memory (property)*>
68437a39
DJ
44713<!-- memory: Specifies a memory region,
44714 and its type, or device. -->
5f1ca24a 44715<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44716 start CDATA #REQUIRED
5f1ca24a 44717 length CDATA #REQUIRED>
68437a39
DJ
44718<!-- property: Generic attribute tag -->
44719<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44720<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44721@end smallexample
44722
dc146f7c
VP
44723@node Thread List Format
44724@section Thread List Format
44725@cindex thread list format
44726
44727To efficiently update the list of threads and their attributes,
44728@value{GDBN} issues the @samp{qXfer:threads:read} packet
44729(@pxref{qXfer threads read}) and obtains the XML document with
44730the following structure:
44731
44732@smallexample
44733<?xml version="1.0"?>
44734<threads>
79efa585 44735 <thread id="id" core="0" name="name">
dc146f7c
VP
44736 ... description ...
44737 </thread>
44738</threads>
44739@end smallexample
44740
44741Each @samp{thread} element must have the @samp{id} attribute that
44742identifies the thread (@pxref{thread-id syntax}). The
44743@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44744the thread was last executing on. The @samp{name} attribute, if
44745present, specifies the human-readable name of the thread. The content
44746of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44747auxiliary information. The @samp{handle} attribute, if present,
44748is a hex encoded representation of the thread handle.
44749
dc146f7c 44750
b3b9301e
PA
44751@node Traceframe Info Format
44752@section Traceframe Info Format
44753@cindex traceframe info format
44754
44755To be able to know which objects in the inferior can be examined when
44756inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44757memory ranges, registers and trace state variables that have been
44758collected in a traceframe.
44759
44760This list is obtained using the @samp{qXfer:traceframe-info:read}
44761(@pxref{qXfer traceframe info read}) packet and is an XML document.
44762
44763@value{GDBN} must be linked with the Expat library to support XML
44764traceframe info discovery. @xref{Expat}.
44765
44766The top-level structure of the document is shown below:
44767
44768@smallexample
44769<?xml version="1.0"?>
44770<!DOCTYPE traceframe-info
44771 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44772 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44773<traceframe-info>
44774 block...
44775</traceframe-info>
44776@end smallexample
44777
44778Each traceframe block can be either:
44779
44780@itemize
44781
44782@item
44783A region of collected memory starting at @var{addr} and extending for
44784@var{length} bytes from there:
44785
44786@smallexample
44787<memory start="@var{addr}" length="@var{length}"/>
44788@end smallexample
44789
28a93511
YQ
44790@item
44791A block indicating trace state variable numbered @var{number} has been
44792collected:
44793
44794@smallexample
44795<tvar id="@var{number}"/>
44796@end smallexample
44797
b3b9301e
PA
44798@end itemize
44799
44800The formal DTD for the traceframe info format is given below:
44801
44802@smallexample
28a93511 44803<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44804<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44805
44806<!ELEMENT memory EMPTY>
44807<!ATTLIST memory start CDATA #REQUIRED
44808 length CDATA #REQUIRED>
28a93511
YQ
44809<!ELEMENT tvar>
44810<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44811@end smallexample
44812
2ae8c8e7
MM
44813@node Branch Trace Format
44814@section Branch Trace Format
44815@cindex branch trace format
44816
44817In order to display the branch trace of an inferior thread,
44818@value{GDBN} needs to obtain the list of branches. This list is
44819represented as list of sequential code blocks that are connected via
44820branches. The code in each block has been executed sequentially.
44821
44822This list is obtained using the @samp{qXfer:btrace:read}
44823(@pxref{qXfer btrace read}) packet and is an XML document.
44824
44825@value{GDBN} must be linked with the Expat library to support XML
44826traceframe info discovery. @xref{Expat}.
44827
44828The top-level structure of the document is shown below:
44829
44830@smallexample
44831<?xml version="1.0"?>
44832<!DOCTYPE btrace
44833 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44834 "http://sourceware.org/gdb/gdb-btrace.dtd">
44835<btrace>
44836 block...
44837</btrace>
44838@end smallexample
44839
44840@itemize
44841
44842@item
44843A block of sequentially executed instructions starting at @var{begin}
44844and ending at @var{end}:
44845
44846@smallexample
44847<block begin="@var{begin}" end="@var{end}"/>
44848@end smallexample
44849
44850@end itemize
44851
44852The formal DTD for the branch trace format is given below:
44853
44854@smallexample
b20a6524 44855<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44856<!ATTLIST btrace version CDATA #FIXED "1.0">
44857
44858<!ELEMENT block EMPTY>
44859<!ATTLIST block begin CDATA #REQUIRED
44860 end CDATA #REQUIRED>
b20a6524
MM
44861
44862<!ELEMENT pt (pt-config?, raw?)>
44863
44864<!ELEMENT pt-config (cpu?)>
44865
44866<!ELEMENT cpu EMPTY>
44867<!ATTLIST cpu vendor CDATA #REQUIRED
44868 family CDATA #REQUIRED
44869 model CDATA #REQUIRED
44870 stepping CDATA #REQUIRED>
44871
44872<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44873@end smallexample
44874
f4abbc16
MM
44875@node Branch Trace Configuration Format
44876@section Branch Trace Configuration Format
44877@cindex branch trace configuration format
44878
44879For each inferior thread, @value{GDBN} can obtain the branch trace
44880configuration using the @samp{qXfer:btrace-conf:read}
44881(@pxref{qXfer btrace-conf read}) packet.
44882
44883The configuration describes the branch trace format and configuration
d33501a5
MM
44884settings for that format. The following information is described:
44885
44886@table @code
44887@item bts
44888This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44889@table @code
44890@item size
44891The size of the @acronym{BTS} ring buffer in bytes.
44892@end table
b20a6524 44893@item pt
bc504a31 44894This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44895PT}) format.
44896@table @code
44897@item size
bc504a31 44898The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44899@end table
d33501a5 44900@end table
f4abbc16
MM
44901
44902@value{GDBN} must be linked with the Expat library to support XML
44903branch trace configuration discovery. @xref{Expat}.
44904
44905The formal DTD for the branch trace configuration format is given below:
44906
44907@smallexample
b20a6524 44908<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44909<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44910
44911<!ELEMENT bts EMPTY>
d33501a5 44912<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44913
44914<!ELEMENT pt EMPTY>
44915<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44916@end smallexample
44917
f418dd93
DJ
44918@include agentexpr.texi
44919
23181151
DJ
44920@node Target Descriptions
44921@appendix Target Descriptions
44922@cindex target descriptions
44923
23181151
DJ
44924One of the challenges of using @value{GDBN} to debug embedded systems
44925is that there are so many minor variants of each processor
44926architecture in use. It is common practice for vendors to start with
eb17f351 44927a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44928and then make changes to adapt it to a particular market niche. Some
44929architectures have hundreds of variants, available from dozens of
44930vendors. This leads to a number of problems:
44931
44932@itemize @bullet
44933@item
44934With so many different customized processors, it is difficult for
44935the @value{GDBN} maintainers to keep up with the changes.
44936@item
44937Since individual variants may have short lifetimes or limited
44938audiences, it may not be worthwhile to carry information about every
44939variant in the @value{GDBN} source tree.
44940@item
44941When @value{GDBN} does support the architecture of the embedded system
44942at hand, the task of finding the correct architecture name to give the
44943@command{set architecture} command can be error-prone.
44944@end itemize
44945
44946To address these problems, the @value{GDBN} remote protocol allows a
44947target system to not only identify itself to @value{GDBN}, but to
44948actually describe its own features. This lets @value{GDBN} support
44949processor variants it has never seen before --- to the extent that the
44950descriptions are accurate, and that @value{GDBN} understands them.
44951
9cceb671
DJ
44952@value{GDBN} must be linked with the Expat library to support XML
44953target descriptions. @xref{Expat}.
123dc839 44954
23181151
DJ
44955@menu
44956* Retrieving Descriptions:: How descriptions are fetched from a target.
44957* Target Description Format:: The contents of a target description.
123dc839
DJ
44958* Predefined Target Types:: Standard types available for target
44959 descriptions.
81516450 44960* Enum Target Types:: How to define enum target types.
123dc839 44961* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
44962@end menu
44963
44964@node Retrieving Descriptions
44965@section Retrieving Descriptions
44966
44967Target descriptions can be read from the target automatically, or
44968specified by the user manually. The default behavior is to read the
44969description from the target. @value{GDBN} retrieves it via the remote
44970protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44971qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44972@samp{target.xml}. The contents of the @samp{target.xml} annex are an
44973XML document, of the form described in @ref{Target Description
44974Format}.
44975
44976Alternatively, you can specify a file to read for the target description.
44977If a file is set, the target will not be queried. The commands to
44978specify a file are:
44979
44980@table @code
44981@cindex set tdesc filename
44982@item set tdesc filename @var{path}
44983Read the target description from @var{path}.
44984
44985@cindex unset tdesc filename
44986@item unset tdesc filename
44987Do not read the XML target description from a file. @value{GDBN}
44988will use the description supplied by the current target.
44989
44990@cindex show tdesc filename
44991@item show tdesc filename
44992Show the filename to read for a target description, if any.
44993@end table
44994
44995
44996@node Target Description Format
44997@section Target Description Format
44998@cindex target descriptions, XML format
44999
45000A target description annex is an @uref{http://www.w3.org/XML/, XML}
45001document which complies with the Document Type Definition provided in
45002the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45003means you can use generally available tools like @command{xmllint} to
45004check that your feature descriptions are well-formed and valid.
45005However, to help people unfamiliar with XML write descriptions for
45006their targets, we also describe the grammar here.
45007
123dc839
DJ
45008Target descriptions can identify the architecture of the remote target
45009and (for some architectures) provide information about custom register
08d16641
PA
45010sets. They can also identify the OS ABI of the remote target.
45011@value{GDBN} can use this information to autoconfigure for your
123dc839 45012target, or to warn you if you connect to an unsupported target.
23181151
DJ
45013
45014Here is a simple target description:
45015
123dc839 45016@smallexample
1780a0ed 45017<target version="1.0">
23181151
DJ
45018 <architecture>i386:x86-64</architecture>
45019</target>
123dc839 45020@end smallexample
23181151
DJ
45021
45022@noindent
45023This minimal description only says that the target uses
45024the x86-64 architecture.
45025
123dc839
DJ
45026A target description has the following overall form, with [ ] marking
45027optional elements and @dots{} marking repeatable elements. The elements
45028are explained further below.
23181151 45029
123dc839 45030@smallexample
23181151
DJ
45031<?xml version="1.0"?>
45032<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 45033<target version="1.0">
123dc839 45034 @r{[}@var{architecture}@r{]}
08d16641 45035 @r{[}@var{osabi}@r{]}
e35359c5 45036 @r{[}@var{compatible}@r{]}
123dc839 45037 @r{[}@var{feature}@dots{}@r{]}
23181151 45038</target>
123dc839 45039@end smallexample
23181151
DJ
45040
45041@noindent
45042The description is generally insensitive to whitespace and line
45043breaks, under the usual common-sense rules. The XML version
45044declaration and document type declaration can generally be omitted
45045(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
45046useful for XML validation tools. The @samp{version} attribute for
45047@samp{<target>} may also be omitted, but we recommend
45048including it; if future versions of @value{GDBN} use an incompatible
45049revision of @file{gdb-target.dtd}, they will detect and report
45050the version mismatch.
23181151 45051
108546a0
DJ
45052@subsection Inclusion
45053@cindex target descriptions, inclusion
45054@cindex XInclude
45055@ifnotinfo
45056@cindex <xi:include>
45057@end ifnotinfo
45058
45059It can sometimes be valuable to split a target description up into
45060several different annexes, either for organizational purposes, or to
45061share files between different possible target descriptions. You can
45062divide a description into multiple files by replacing any element of
45063the target description with an inclusion directive of the form:
45064
123dc839 45065@smallexample
108546a0 45066<xi:include href="@var{document}"/>
123dc839 45067@end smallexample
108546a0
DJ
45068
45069@noindent
45070When @value{GDBN} encounters an element of this form, it will retrieve
45071the named XML @var{document}, and replace the inclusion directive with
45072the contents of that document. If the current description was read
45073using @samp{qXfer}, then so will be the included document;
45074@var{document} will be interpreted as the name of an annex. If the
45075current description was read from a file, @value{GDBN} will look for
45076@var{document} as a file in the same directory where it found the
45077original description.
45078
123dc839
DJ
45079@subsection Architecture
45080@cindex <architecture>
45081
45082An @samp{<architecture>} element has this form:
45083
45084@smallexample
45085 <architecture>@var{arch}</architecture>
45086@end smallexample
45087
e35359c5
UW
45088@var{arch} is one of the architectures from the set accepted by
45089@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 45090
08d16641
PA
45091@subsection OS ABI
45092@cindex @code{<osabi>}
45093
45094This optional field was introduced in @value{GDBN} version 7.0.
45095Previous versions of @value{GDBN} ignore it.
45096
45097An @samp{<osabi>} element has this form:
45098
45099@smallexample
45100 <osabi>@var{abi-name}</osabi>
45101@end smallexample
45102
45103@var{abi-name} is an OS ABI name from the same selection accepted by
45104@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45105
e35359c5
UW
45106@subsection Compatible Architecture
45107@cindex @code{<compatible>}
45108
45109This optional field was introduced in @value{GDBN} version 7.0.
45110Previous versions of @value{GDBN} ignore it.
45111
45112A @samp{<compatible>} element has this form:
45113
45114@smallexample
45115 <compatible>@var{arch}</compatible>
45116@end smallexample
45117
45118@var{arch} is one of the architectures from the set accepted by
45119@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45120
45121A @samp{<compatible>} element is used to specify that the target
45122is able to run binaries in some other than the main target architecture
45123given by the @samp{<architecture>} element. For example, on the
45124Cell Broadband Engine, the main architecture is @code{powerpc:common}
45125or @code{powerpc:common64}, but the system is able to run binaries
45126in the @code{spu} architecture as well. The way to describe this
45127capability with @samp{<compatible>} is as follows:
45128
45129@smallexample
45130 <architecture>powerpc:common</architecture>
45131 <compatible>spu</compatible>
45132@end smallexample
45133
123dc839
DJ
45134@subsection Features
45135@cindex <feature>
45136
45137Each @samp{<feature>} describes some logical portion of the target
45138system. Features are currently used to describe available CPU
45139registers and the types of their contents. A @samp{<feature>} element
45140has this form:
45141
45142@smallexample
45143<feature name="@var{name}">
45144 @r{[}@var{type}@dots{}@r{]}
45145 @var{reg}@dots{}
45146</feature>
45147@end smallexample
45148
45149@noindent
45150Each feature's name should be unique within the description. The name
45151of a feature does not matter unless @value{GDBN} has some special
45152knowledge of the contents of that feature; if it does, the feature
45153should have its standard name. @xref{Standard Target Features}.
45154
45155@subsection Types
45156
45157Any register's value is a collection of bits which @value{GDBN} must
45158interpret. The default interpretation is a two's complement integer,
45159but other types can be requested by name in the register description.
45160Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
45161Target Types}), and the description can define additional composite
45162and enum types.
123dc839
DJ
45163
45164Each type element must have an @samp{id} attribute, which gives
45165a unique (within the containing @samp{<feature>}) name to the type.
45166Types must be defined before they are used.
45167
45168@cindex <vector>
45169Some targets offer vector registers, which can be treated as arrays
45170of scalar elements. These types are written as @samp{<vector>} elements,
45171specifying the array element type, @var{type}, and the number of elements,
45172@var{count}:
45173
45174@smallexample
45175<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
45176@end smallexample
45177
45178@cindex <union>
45179If a register's value is usefully viewed in multiple ways, define it
45180with a union type containing the useful representations. The
45181@samp{<union>} element contains one or more @samp{<field>} elements,
45182each of which has a @var{name} and a @var{type}:
45183
45184@smallexample
45185<union id="@var{id}">
45186 <field name="@var{name}" type="@var{type}"/>
45187 @dots{}
45188</union>
45189@end smallexample
45190
f5dff777 45191@cindex <struct>
81516450 45192@cindex <flags>
f5dff777 45193If a register's value is composed from several separate values, define
81516450
DE
45194it with either a structure type or a flags type.
45195A flags type may only contain bitfields.
45196A structure type may either contain only bitfields or contain no bitfields.
45197If the value contains only bitfields, its total size in bytes must be
45198specified.
45199
45200Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
45201
45202@smallexample
81516450
DE
45203<struct id="@var{id}">
45204 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
45205 @dots{}
45206</struct>
45207@end smallexample
45208
81516450
DE
45209Both @var{name} and @var{type} values are required.
45210No implicit padding is added.
45211
45212Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
45213
45214@smallexample
81516450
DE
45215<struct id="@var{id}" size="@var{size}">
45216 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
45217 @dots{}
45218</struct>
45219@end smallexample
45220
f5dff777
DJ
45221@smallexample
45222<flags id="@var{id}" size="@var{size}">
81516450 45223 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
45224 @dots{}
45225</flags>
45226@end smallexample
45227
81516450
DE
45228The @var{name} value is required.
45229Bitfield values may be named with the empty string, @samp{""},
45230in which case the field is ``filler'' and its value is not printed.
45231Not all bits need to be specified, so ``filler'' fields are optional.
45232
ee8da4b8
DE
45233The @var{start} and @var{end} values are required, and @var{type}
45234is optional.
81516450
DE
45235The field's @var{start} must be less than or equal to its @var{end},
45236and zero represents the least significant bit.
81516450 45237
ee8da4b8
DE
45238The default value of @var{type} is @code{bool} for single bit fields,
45239and an unsigned integer otherwise.
81516450
DE
45240
45241Which to choose? Structures or flags?
45242
45243Registers defined with @samp{flags} have these advantages over
45244defining them with @samp{struct}:
45245
45246@itemize @bullet
45247@item
45248Arithmetic may be performed on them as if they were integers.
45249@item
45250They are printed in a more readable fashion.
45251@end itemize
45252
45253Registers defined with @samp{struct} have one advantage over
45254defining them with @samp{flags}:
45255
45256@itemize @bullet
45257@item
45258One can fetch individual fields like in @samp{C}.
45259
45260@smallexample
45261(gdb) print $my_struct_reg.field3
45262$1 = 42
45263@end smallexample
45264
45265@end itemize
45266
123dc839
DJ
45267@subsection Registers
45268@cindex <reg>
45269
45270Each register is represented as an element with this form:
45271
45272@smallexample
45273<reg name="@var{name}"
45274 bitsize="@var{size}"
45275 @r{[}regnum="@var{num}"@r{]}
45276 @r{[}save-restore="@var{save-restore}"@r{]}
45277 @r{[}type="@var{type}"@r{]}
45278 @r{[}group="@var{group}"@r{]}/>
45279@end smallexample
45280
45281@noindent
45282The components are as follows:
45283
45284@table @var
45285
45286@item name
45287The register's name; it must be unique within the target description.
45288
45289@item bitsize
45290The register's size, in bits.
45291
45292@item regnum
45293The register's number. If omitted, a register's number is one greater
45294than that of the previous register (either in the current feature or in
177b42fe 45295a preceding feature); the first register in the target description
123dc839
DJ
45296defaults to zero. This register number is used to read or write
45297the register; e.g.@: it is used in the remote @code{p} and @code{P}
45298packets, and registers appear in the @code{g} and @code{G} packets
45299in order of increasing register number.
45300
45301@item save-restore
45302Whether the register should be preserved across inferior function
45303calls; this must be either @code{yes} or @code{no}. The default is
45304@code{yes}, which is appropriate for most registers except for
45305some system control registers; this is not related to the target's
45306ABI.
45307
45308@item type
697aa1b7 45309The type of the register. It may be a predefined type, a type
123dc839
DJ
45310defined in the current feature, or one of the special types @code{int}
45311and @code{float}. @code{int} is an integer type of the correct size
45312for @var{bitsize}, and @code{float} is a floating point type (in the
45313architecture's normal floating point format) of the correct size for
45314@var{bitsize}. The default is @code{int}.
45315
45316@item group
cef0f868
SH
45317The register group to which this register belongs. It can be one of the
45318standard register groups @code{general}, @code{float}, @code{vector} or an
45319arbitrary string. Group names should be limited to alphanumeric characters.
45320If a group name is made up of multiple words the words may be separated by
45321hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45322@var{group} is specified, @value{GDBN} will not display the register in
45323@code{info registers}.
123dc839
DJ
45324
45325@end table
45326
45327@node Predefined Target Types
45328@section Predefined Target Types
45329@cindex target descriptions, predefined types
45330
45331Type definitions in the self-description can build up composite types
45332from basic building blocks, but can not define fundamental types. Instead,
45333standard identifiers are provided by @value{GDBN} for the fundamental
45334types. The currently supported types are:
45335
45336@table @code
45337
81516450
DE
45338@item bool
45339Boolean type, occupying a single bit.
45340
123dc839
DJ
45341@item int8
45342@itemx int16
d1908f2d 45343@itemx int24
123dc839
DJ
45344@itemx int32
45345@itemx int64
7cc46491 45346@itemx int128
123dc839
DJ
45347Signed integer types holding the specified number of bits.
45348
45349@item uint8
45350@itemx uint16
d1908f2d 45351@itemx uint24
123dc839
DJ
45352@itemx uint32
45353@itemx uint64
7cc46491 45354@itemx uint128
123dc839
DJ
45355Unsigned integer types holding the specified number of bits.
45356
45357@item code_ptr
45358@itemx data_ptr
45359Pointers to unspecified code and data. The program counter and
45360any dedicated return address register may be marked as code
45361pointers; printing a code pointer converts it into a symbolic
45362address. The stack pointer and any dedicated address registers
45363may be marked as data pointers.
45364
6e3bbd1a
PB
45365@item ieee_single
45366Single precision IEEE floating point.
45367
45368@item ieee_double
45369Double precision IEEE floating point.
45370
123dc839
DJ
45371@item arm_fpa_ext
45372The 12-byte extended precision format used by ARM FPA registers.
45373
075b51b7
L
45374@item i387_ext
45375The 10-byte extended precision format used by x87 registers.
45376
45377@item i386_eflags
4537832bit @sc{eflags} register used by x86.
45379
45380@item i386_mxcsr
4538132bit @sc{mxcsr} register used by x86.
45382
123dc839
DJ
45383@end table
45384
81516450
DE
45385@node Enum Target Types
45386@section Enum Target Types
45387@cindex target descriptions, enum types
45388
45389Enum target types are useful in @samp{struct} and @samp{flags}
45390register descriptions. @xref{Target Description Format}.
45391
45392Enum types have a name, size and a list of name/value pairs.
45393
45394@smallexample
45395<enum id="@var{id}" size="@var{size}">
45396 <evalue name="@var{name}" value="@var{value}"/>
45397 @dots{}
45398</enum>
45399@end smallexample
45400
45401Enums must be defined before they are used.
45402
45403@smallexample
45404<enum id="levels_type" size="4">
45405 <evalue name="low" value="0"/>
45406 <evalue name="high" value="1"/>
45407</enum>
45408<flags id="flags_type" size="4">
45409 <field name="X" start="0"/>
45410 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45411</flags>
45412<reg name="flags" bitsize="32" type="flags_type"/>
45413@end smallexample
45414
45415Given that description, a value of 3 for the @samp{flags} register
45416would be printed as:
45417
45418@smallexample
45419(gdb) info register flags
45420flags 0x3 [ X LEVEL=high ]
45421@end smallexample
45422
123dc839
DJ
45423@node Standard Target Features
45424@section Standard Target Features
45425@cindex target descriptions, standard features
45426
45427A target description must contain either no registers or all the
45428target's registers. If the description contains no registers, then
45429@value{GDBN} will assume a default register layout, selected based on
45430the architecture. If the description contains any registers, the
45431default layout will not be used; the standard registers must be
45432described in the target description, in such a way that @value{GDBN}
45433can recognize them.
45434
45435This is accomplished by giving specific names to feature elements
45436which contain standard registers. @value{GDBN} will look for features
45437with those names and verify that they contain the expected registers;
45438if any known feature is missing required registers, or if any required
45439feature is missing, @value{GDBN} will reject the target
45440description. You can add additional registers to any of the
45441standard features --- @value{GDBN} will display them just as if
45442they were added to an unrecognized feature.
45443
45444This section lists the known features and their expected contents.
45445Sample XML documents for these features are included in the
45446@value{GDBN} source tree, in the directory @file{gdb/features}.
45447
45448Names recognized by @value{GDBN} should include the name of the
45449company or organization which selected the name, and the overall
45450architecture to which the feature applies; so e.g.@: the feature
45451containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45452
ff6f572f
DJ
45453The names of registers are not case sensitive for the purpose
45454of recognizing standard features, but @value{GDBN} will only display
45455registers using the capitalization used in the description.
45456
e9c17194 45457@menu
430ed3f0 45458* AArch64 Features::
ad0a504f 45459* ARC Features::
e9c17194 45460* ARM Features::
3bb8d5c3 45461* i386 Features::
164224e9 45462* MicroBlaze Features::
1e26b4f8 45463* MIPS Features::
e9c17194 45464* M68K Features::
a28d8e50 45465* NDS32 Features::
a1217d97 45466* Nios II Features::
a994fec4 45467* OpenRISC 1000 Features::
1e26b4f8 45468* PowerPC Features::
b5ffee31 45469* RISC-V Features::
e3ec872f 45470* RX Features::
4ac33720 45471* S/390 and System z Features::
3f7b46f2 45472* Sparc Features::
224bbe49 45473* TIC6x Features::
e9c17194
VP
45474@end menu
45475
45476
430ed3f0
MS
45477@node AArch64 Features
45478@subsection AArch64 Features
45479@cindex target descriptions, AArch64 features
45480
45481The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45482targets. It should contain registers @samp{x0} through @samp{x30},
45483@samp{sp}, @samp{pc}, and @samp{cpsr}.
45484
45485The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45486it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45487and @samp{fpcr}.
45488
95228a0d
AH
45489The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45490it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45491through @samp{p15}, @samp{ffr} and @samp{vg}.
45492
6dc0ebde
AH
45493The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45494it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45495
ad0a504f
AK
45496@node ARC Features
45497@subsection ARC Features
45498@cindex target descriptions, ARC Features
45499
995d3a19
SV
45500ARC processors are so configurable that even core registers and their numbers
45501are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45502registers, which are important to @value{GDBN}, are not ``core'' registers in
45503ARC. Therefore, there are two features that their presence is mandatory:
45504@samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45505
45506The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45507contain registers:
45508
45509@itemize @minus
45510@item
45511@samp{r0} through @samp{r25} for normal register file targets.
45512@item
45513@samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45514register file targets.
45515@item
45516@samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45517@samp{blink}, @samp{lp_count}, @samp{pcl}.
45518@end itemize
45519
45520In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45521feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45522of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45523The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45524and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45525are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45526@samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45527because of their inaccessibility during user space debugging sessions.
45528
45529Extension core registers @samp{r32} through @samp{r59} are optional and their
45530existence depends on the configuration. When debugging GNU/Linux applications,
45531i.e.@: user space debugging, these core registers are not available.
45532
fdd8731b
SV
45533The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
45534is the list of registers pertinent to this feature:
45535
45536@itemize @minus
45537@item
45538mandatory: @samp{pc} and @samp{status32}.
45539@item
45540optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45541@end itemize
ad0a504f 45542
e9c17194 45543@node ARM Features
123dc839
DJ
45544@subsection ARM Features
45545@cindex target descriptions, ARM features
45546
9779414d
DJ
45547The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45548ARM targets.
123dc839
DJ
45549It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45550@samp{lr}, @samp{pc}, and @samp{cpsr}.
45551
9779414d
DJ
45552For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45553feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45554registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45555and @samp{xpsr}.
45556
123dc839
DJ
45557The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45558should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45559
ff6f572f
DJ
45560The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45561it should contain at least registers @samp{wR0} through @samp{wR15} and
45562@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45563@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45564
58d6951d
DJ
45565The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45566should contain at least registers @samp{d0} through @samp{d15}. If
45567they are present, @samp{d16} through @samp{d31} should also be included.
45568@value{GDBN} will synthesize the single-precision registers from
45569halves of the double-precision registers.
45570
45571The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45572need to contain registers; it instructs @value{GDBN} to display the
45573VFP double-precision registers as vectors and to synthesize the
45574quad-precision registers from pairs of double-precision registers.
45575If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45576be present and include 32 double-precision registers.
45577
3bb8d5c3
L
45578@node i386 Features
45579@subsection i386 Features
45580@cindex target descriptions, i386 features
45581
45582The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45583targets. It should describe the following registers:
45584
45585@itemize @minus
45586@item
45587@samp{eax} through @samp{edi} plus @samp{eip} for i386
45588@item
45589@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45590@item
45591@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45592@samp{fs}, @samp{gs}
45593@item
45594@samp{st0} through @samp{st7}
45595@item
45596@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45597@samp{foseg}, @samp{fooff} and @samp{fop}
45598@end itemize
45599
45600The register sets may be different, depending on the target.
45601
3a13a53b 45602The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45603describe registers:
45604
45605@itemize @minus
45606@item
45607@samp{xmm0} through @samp{xmm7} for i386
45608@item
45609@samp{xmm0} through @samp{xmm15} for amd64
45610@item
45611@samp{mxcsr}
45612@end itemize
45613
3a13a53b
L
45614The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45615@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45616describe the upper 128 bits of @sc{ymm} registers:
45617
45618@itemize @minus
45619@item
45620@samp{ymm0h} through @samp{ymm7h} for i386
45621@item
45622@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45623@end itemize
45624
bc504a31 45625The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45626Memory Protection Extension (MPX). It should describe the following registers:
45627
45628@itemize @minus
45629@item
45630@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45631@item
45632@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45633@end itemize
45634
3bb8d5c3
L
45635The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45636describe a single register, @samp{orig_eax}.
45637
2735833d
WT
45638The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45639describe two system registers: @samp{fs_base} and @samp{gs_base}.
45640
01f9f808
MS
45641The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45642@samp{org.gnu.gdb.i386.avx} feature. It should
45643describe additional @sc{xmm} registers:
45644
45645@itemize @minus
45646@item
45647@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45648@end itemize
45649
45650It should describe the upper 128 bits of additional @sc{ymm} registers:
45651
45652@itemize @minus
45653@item
45654@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45655@end itemize
45656
45657It should
45658describe the upper 256 bits of @sc{zmm} registers:
45659
45660@itemize @minus
45661@item
45662@samp{zmm0h} through @samp{zmm7h} for i386.
45663@item
45664@samp{zmm0h} through @samp{zmm15h} for amd64.
45665@end itemize
45666
45667It should
45668describe the additional @sc{zmm} registers:
45669
45670@itemize @minus
45671@item
45672@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45673@end itemize
45674
51547df6
MS
45675The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45676describe a single register, @samp{pkru}. It is a 32-bit register
45677valid for i386 and amd64.
45678
164224e9
ME
45679@node MicroBlaze Features
45680@subsection MicroBlaze Features
45681@cindex target descriptions, MicroBlaze features
45682
45683The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45684targets. It should contain registers @samp{r0} through @samp{r31},
45685@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45686@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45687@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45688
45689The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45690If present, it should contain registers @samp{rshr} and @samp{rslr}
45691
1e26b4f8 45692@node MIPS Features
eb17f351
EZ
45693@subsection @acronym{MIPS} Features
45694@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45695
eb17f351 45696The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45697It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45698@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45699on the target.
45700
45701The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45702contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45703registers. They may be 32-bit or 64-bit depending on the target.
45704
45705The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45706it may be optional in a future version of @value{GDBN}. It should
45707contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45708@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45709
1faeff08
MR
45710The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45711contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45712@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45713be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45714
822b6570
DJ
45715The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45716contain a single register, @samp{restart}, which is used by the
45717Linux kernel to control restartable syscalls.
45718
e9c17194
VP
45719@node M68K Features
45720@subsection M68K Features
45721@cindex target descriptions, M68K features
45722
45723@table @code
45724@item @samp{org.gnu.gdb.m68k.core}
45725@itemx @samp{org.gnu.gdb.coldfire.core}
45726@itemx @samp{org.gnu.gdb.fido.core}
45727One of those features must be always present.
249e1128 45728The feature that is present determines which flavor of m68k is
e9c17194
VP
45729used. The feature that is present should contain registers
45730@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45731@samp{sp}, @samp{ps} and @samp{pc}.
45732
45733@item @samp{org.gnu.gdb.coldfire.fp}
45734This feature is optional. If present, it should contain registers
45735@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45736@samp{fpiaddr}.
b7d2fe14
TT
45737
45738Note that, despite the fact that this feature's name says
45739@samp{coldfire}, it is used to describe any floating point registers.
45740The size of the registers must match the main m68k flavor; so, for
45741example, if the primary feature is reported as @samp{coldfire}, then
4574264-bit floating point registers are required.
e9c17194
VP
45743@end table
45744
a28d8e50
YTL
45745@node NDS32 Features
45746@subsection NDS32 Features
45747@cindex target descriptions, NDS32 features
45748
45749The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45750targets. It should contain at least registers @samp{r0} through
45751@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45752and @samp{pc}.
45753
45754The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45755it should contain 64-bit double-precision floating-point registers
45756@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45757@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45758
45759@emph{Note:} The first sixteen 64-bit double-precision floating-point
45760registers are overlapped with the thirty-two 32-bit single-precision
45761floating-point registers. The 32-bit single-precision registers, if
45762not being listed explicitly, will be synthesized from halves of the
45763overlapping 64-bit double-precision registers. Listing 32-bit
45764single-precision registers explicitly is deprecated, and the
45765support to it could be totally removed some day.
45766
a1217d97
SL
45767@node Nios II Features
45768@subsection Nios II Features
45769@cindex target descriptions, Nios II features
45770
45771The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45772targets. It should contain the 32 core registers (@samp{zero},
45773@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45774@samp{pc}, and the 16 control registers (@samp{status} through
45775@samp{mpuacc}).
45776
a994fec4
FJ
45777@node OpenRISC 1000 Features
45778@subsection Openrisc 1000 Features
45779@cindex target descriptions, OpenRISC 1000 features
45780
45781The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45782targets. It should contain the 32 general purpose registers (@samp{r0}
45783through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45784
1e26b4f8 45785@node PowerPC Features
7cc46491
DJ
45786@subsection PowerPC Features
45787@cindex target descriptions, PowerPC features
45788
45789The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45790targets. It should contain registers @samp{r0} through @samp{r31},
45791@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45792@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45793
45794The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45795contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45796
45797The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45798contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45799@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45800through @samp{v31} as aliases for the corresponding @samp{vrX}
45801registers.
7cc46491 45802
677c5bb1 45803The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45804contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45805combine these registers with the floating point registers (@samp{f0}
45806through @samp{f31}) and the altivec registers (@samp{vr0} through
45807@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45808@samp{vs63}, the set of vector-scalar registers for POWER7.
45809Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45810@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45811
7cc46491
DJ
45812The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45813contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45814@samp{spefscr}. SPE targets should provide 32-bit registers in
45815@samp{org.gnu.gdb.power.core} and provide the upper halves in
45816@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45817these to present registers @samp{ev0} through @samp{ev31} to the
45818user.
45819
7ca18ed6
EBM
45820The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45821contain the 64-bit register @samp{ppr}.
45822
45823The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45824contain the 64-bit register @samp{dscr}.
45825
f2cf6173
EBM
45826The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45827contain the 64-bit register @samp{tar}.
45828
232bfb86
EBM
45829The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45830contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4583164-bit wide.
45832
45833The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45834contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45835and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45836server PMU registers provided by @sc{gnu}/Linux.
45837
8d619c01
EBM
45838The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45839contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4584064-bit wide.
45841
45842The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45843contain the checkpointed general-purpose registers @samp{cr0} through
45844@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45845@samp{cctr}. These registers may all be either 32-bit or 64-bit
45846depending on the target. It should also contain the checkpointed
45847registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45848wide.
45849
45850The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45851contain the checkpointed 64-bit floating-point registers @samp{cf0}
45852through @samp{cf31}, as well as the checkpointed 64-bit register
45853@samp{cfpscr}.
45854
45855The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45856should contain the checkpointed altivec registers @samp{cvr0} through
45857@samp{cvr31}, all 128-bit wide. It should also contain the
45858checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45859wide.
45860
45861The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45862contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45863will combine these registers with the checkpointed floating point
45864registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45865altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45866128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45867@samp{cvs63}. Therefore, this feature requires both
45868@samp{org.gnu.gdb.power.htm.altivec} and
45869@samp{org.gnu.gdb.power.htm.fpu}.
45870
45871The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45872contain the 64-bit checkpointed register @samp{cppr}.
45873
45874The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45875contain the 64-bit checkpointed register @samp{cdscr}.
45876
45877The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45878contain the 64-bit checkpointed register @samp{ctar}.
45879
b5ffee31
AB
45880
45881@node RISC-V Features
45882@subsection RISC-V Features
45883@cindex target descriptions, RISC-V Features
45884
45885The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45886targets. It should contain the registers @samp{x0} through
45887@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45888@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45889etc).
45890
45891The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45892should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45893@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45894architectural register names, or the ABI names can be used.
45895
45896The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45897it should contain registers that are not backed by real registers on
45898the target, but are instead virtual, where the register value is
45899derived from other target state. In many ways these are like
45900@value{GDBN}s pseudo-registers, except implemented by the target.
45901Currently the only register expected in this set is the one byte
45902@samp{priv} register that contains the target's privilege level in the
45903least significant two bits.
45904
45905The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45906should contain all of the target's standard CSRs. Standard CSRs are
45907those defined in the RISC-V specification documents. There is some
45908overlap between this feature and the fpu feature; the @samp{fflags},
45909@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45910expectation is that these registers will be in the fpu feature if the
45911target has floating point hardware, but can be moved into the csr
45912feature if the target has the floating point control registers, but no
45913other floating point hardware.
45914
e3ec872f
YS
45915@node RX Features
45916@subsection RX Features
45917@cindex target descriptions, RX Features
45918
45919The @samp{org.gnu.gdb.rx.core} feature is required for RX
45920targets. It should contain the registers @samp{r0} through
45921@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45922@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45923
4ac33720
UW
45924@node S/390 and System z Features
45925@subsection S/390 and System z Features
45926@cindex target descriptions, S/390 features
45927@cindex target descriptions, System z features
45928
45929The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45930System z targets. It should contain the PSW and the 16 general
45931registers. In particular, System z targets should provide the 64-bit
45932registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45933S/390 targets should provide the 32-bit versions of these registers.
45934A System z target that runs in 31-bit addressing mode should provide
4593532-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45936register's upper halves @samp{r0h} through @samp{r15h}, and their
45937lower halves @samp{r0l} through @samp{r15l}.
45938
45939The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45940contain the 64-bit registers @samp{f0} through @samp{f15}, and
45941@samp{fpc}.
45942
45943The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45944contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45945
45946The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45947contain the register @samp{orig_r2}, which is 64-bit wide on System z
45948targets and 32-bit otherwise. In addition, the feature may contain
45949the @samp{last_break} register, whose width depends on the addressing
45950mode, as well as the @samp{system_call} register, which is always
4595132-bit wide.
45952
45953The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45954contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45955@samp{atia}, and @samp{tr0} through @samp{tr15}.
45956
446899e4
AA
45957The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4595864-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45959combined by @value{GDBN} with the floating point registers @samp{f0}
45960through @samp{f15} to present the 128-bit wide vector registers
45961@samp{v0} through @samp{v15}. In addition, this feature should
45962contain the 128-bit wide vector registers @samp{v16} through
45963@samp{v31}.
45964
289e23aa
AA
45965The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45966the 64-bit wide guarded-storage-control registers @samp{gsd},
45967@samp{gssm}, and @samp{gsepla}.
45968
45969The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45970the 64-bit wide guarded-storage broadcast control registers
45971@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45972
3f7b46f2
IR
45973@node Sparc Features
45974@subsection Sparc Features
45975@cindex target descriptions, sparc32 features
45976@cindex target descriptions, sparc64 features
45977The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45978targets. It should describe the following registers:
45979
45980@itemize @minus
45981@item
45982@samp{g0} through @samp{g7}
45983@item
45984@samp{o0} through @samp{o7}
45985@item
45986@samp{l0} through @samp{l7}
45987@item
45988@samp{i0} through @samp{i7}
45989@end itemize
45990
45991They may be 32-bit or 64-bit depending on the target.
45992
45993Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45994targets. It should describe the following registers:
45995
45996@itemize @minus
45997@item
45998@samp{f0} through @samp{f31}
45999@item
46000@samp{f32} through @samp{f62} for sparc64
46001@end itemize
46002
46003The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46004targets. It should describe the following registers:
46005
46006@itemize @minus
46007@item
46008@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46009@samp{fsr}, and @samp{csr} for sparc32
46010@item
46011@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46012for sparc64
46013@end itemize
46014
224bbe49
YQ
46015@node TIC6x Features
46016@subsection TMS320C6x Features
46017@cindex target descriptions, TIC6x features
46018@cindex target descriptions, TMS320C6x features
46019The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46020targets. It should contain registers @samp{A0} through @samp{A15},
46021registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46022
46023The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46024contain registers @samp{A16} through @samp{A31} and @samp{B16}
46025through @samp{B31}.
46026
46027The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46028contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46029
07e059b5
VP
46030@node Operating System Information
46031@appendix Operating System Information
46032@cindex operating system information
46033
46034@menu
46035* Process list::
46036@end menu
46037
46038Users of @value{GDBN} often wish to obtain information about the state of
46039the operating system running on the target---for example the list of
46040processes, or the list of open files. This section describes the
46041mechanism that makes it possible. This mechanism is similar to the
46042target features mechanism (@pxref{Target Descriptions}), but focuses
46043on a different aspect of target.
46044
6b92c0d3 46045Operating system information is retrieved from the target via the
07e059b5
VP
46046remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46047read}). The object name in the request should be @samp{osdata}, and
46048the @var{annex} identifies the data to be fetched.
46049
46050@node Process list
46051@appendixsection Process list
46052@cindex operating system information, process list
46053
46054When requesting the process list, the @var{annex} field in the
46055@samp{qXfer} request should be @samp{processes}. The returned data is
46056an XML document. The formal syntax of this document is defined in
46057@file{gdb/features/osdata.dtd}.
46058
46059An example document is:
46060
46061@smallexample
46062<?xml version="1.0"?>
46063<!DOCTYPE target SYSTEM "osdata.dtd">
46064<osdata type="processes">
46065 <item>
46066 <column name="pid">1</column>
46067 <column name="user">root</column>
46068 <column name="command">/sbin/init</column>
dc146f7c 46069 <column name="cores">1,2,3</column>
07e059b5
VP
46070 </item>
46071</osdata>
46072@end smallexample
46073
46074Each item should include a column whose name is @samp{pid}. The value
46075of that column should identify the process on the target. The
46076@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
46077displayed by @value{GDBN}. The @samp{cores} column, if present,
46078should contain a comma-separated list of cores that this process
46079is running on. Target may provide additional columns,
07e059b5
VP
46080which @value{GDBN} currently ignores.
46081
05c8c3f5
TT
46082@node Trace File Format
46083@appendix Trace File Format
46084@cindex trace file format
46085
46086The trace file comes in three parts: a header, a textual description
46087section, and a trace frame section with binary data.
46088
46089The header has the form @code{\x7fTRACE0\n}. The first byte is
46090@code{0x7f} so as to indicate that the file contains binary data,
46091while the @code{0} is a version number that may have different values
46092in the future.
46093
46094The description section consists of multiple lines of @sc{ascii} text
46095separated by newline characters (@code{0xa}). The lines may include a
46096variety of optional descriptive or context-setting information, such
46097as tracepoint definitions or register set size. @value{GDBN} will
46098ignore any line that it does not recognize. An empty line marks the end
46099of this section.
46100
0748bf3e
MK
46101@table @code
46102@item R @var{size}
46103Specifies the size of a register block in bytes. This is equal to the
46104size of a @code{g} packet payload in the remote protocol. @var{size}
46105is an ascii decimal number. There should be only one such line in
46106a single trace file.
46107
46108@item status @var{status}
46109Trace status. @var{status} has the same format as a @code{qTStatus}
46110remote packet reply. There should be only one such line in a single trace
46111file.
46112
46113@item tp @var{payload}
46114Tracepoint definition. The @var{payload} has the same format as
46115@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
46116may take multiple lines of definition, corresponding to the multiple
46117reply packets.
46118
46119@item tsv @var{payload}
46120Trace state variable definition. The @var{payload} has the same format as
46121@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
46122may take multiple lines of definition, corresponding to the multiple
46123reply packets.
46124
46125@item tdesc @var{payload}
46126Target description in XML format. The @var{payload} is a single line of
46127the XML file. All such lines should be concatenated together to get
46128the original XML file. This file is in the same format as @code{qXfer}
46129@code{features} payload, and corresponds to the main @code{target.xml}
46130file. Includes are not allowed.
46131
46132@end table
05c8c3f5
TT
46133
46134The trace frame section consists of a number of consecutive frames.
46135Each frame begins with a two-byte tracepoint number, followed by a
46136four-byte size giving the amount of data in the frame. The data in
46137the frame consists of a number of blocks, each introduced by a
46138character indicating its type (at least register, memory, and trace
46139state variable). The data in this section is raw binary, not a
46140hexadecimal or other encoding; its endianness matches the target's
46141endianness.
46142
46143@c FIXME bi-arch may require endianness/arch info in description section
46144
46145@table @code
46146@item R @var{bytes}
46147Register block. The number and ordering of bytes matches that of a
46148@code{g} packet in the remote protocol. Note that these are the
e909d859 46149actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
46150
46151@item M @var{address} @var{length} @var{bytes}...
46152Memory block. This is a contiguous block of memory, at the 8-byte
46153address @var{address}, with a 2-byte length @var{length}, followed by
46154@var{length} bytes.
46155
46156@item V @var{number} @var{value}
46157Trace state variable block. This records the 8-byte signed value
46158@var{value} of trace state variable numbered @var{number}.
46159
46160@end table
46161
46162Future enhancements of the trace file format may include additional types
46163of blocks.
46164
90476074
TT
46165@node Index Section Format
46166@appendix @code{.gdb_index} section format
46167@cindex .gdb_index section format
46168@cindex index section format
46169
46170This section documents the index section that is created by @code{save
46171gdb-index} (@pxref{Index Files}). The index section is
46172DWARF-specific; some knowledge of DWARF is assumed in this
46173description.
46174
46175The mapped index file format is designed to be directly
46176@code{mmap}able on any architecture. In most cases, a datum is
46177represented using a little-endian 32-bit integer value, called an
46178@code{offset_type}. Big endian machines must byte-swap the values
46179before using them. Exceptions to this rule are noted. The data is
46180laid out such that alignment is always respected.
46181
46182A mapped index consists of several areas, laid out in order.
46183
46184@enumerate
46185@item
46186The file header. This is a sequence of values, of @code{offset_type}
46187unless otherwise noted:
46188
46189@enumerate
46190@item
796a7ff8 46191The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 46192Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
46193Version 6 includes symbols for inlined functions, whereas versions 4
46194and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
46195symbol table. Version 8 specifies that symbols from DWARF type units
46196(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
46197compilation unit (@samp{DW_TAG_comp_unit}) using the type.
46198
46199@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 46200by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
46201GDB has a workaround for potentially broken version 7 indices so it is
46202currently not flagged as deprecated.
90476074
TT
46203
46204@item
46205The offset, from the start of the file, of the CU list.
46206
46207@item
46208The offset, from the start of the file, of the types CU list. Note
46209that this area can be empty, in which case this offset will be equal
46210to the next offset.
46211
46212@item
46213The offset, from the start of the file, of the address area.
46214
46215@item
46216The offset, from the start of the file, of the symbol table.
46217
46218@item
46219The offset, from the start of the file, of the constant pool.
46220@end enumerate
46221
46222@item
46223The CU list. This is a sequence of pairs of 64-bit little-endian
46224values, sorted by the CU offset. The first element in each pair is
46225the offset of a CU in the @code{.debug_info} section. The second
46226element in each pair is the length of that CU. References to a CU
46227elsewhere in the map are done using a CU index, which is just the
462280-based index into this table. Note that if there are type CUs, then
46229conceptually CUs and type CUs form a single list for the purposes of
46230CU indices.
46231
46232@item
46233The types CU list. This is a sequence of triplets of 64-bit
46234little-endian values. In a triplet, the first value is the CU offset,
46235the second value is the type offset in the CU, and the third value is
46236the type signature. The types CU list is not sorted.
46237
46238@item
46239The address area. The address area consists of a sequence of address
46240entries. Each address entry has three elements:
46241
46242@enumerate
46243@item
46244The low address. This is a 64-bit little-endian value.
46245
46246@item
46247The high address. This is a 64-bit little-endian value. Like
46248@code{DW_AT_high_pc}, the value is one byte beyond the end.
46249
46250@item
46251The CU index. This is an @code{offset_type} value.
46252@end enumerate
46253
46254@item
46255The symbol table. This is an open-addressed hash table. The size of
46256the hash table is always a power of 2.
46257
46258Each slot in the hash table consists of a pair of @code{offset_type}
46259values. The first value is the offset of the symbol's name in the
46260constant pool. The second value is the offset of the CU vector in the
46261constant pool.
46262
46263If both values are 0, then this slot in the hash table is empty. This
46264is ok because while 0 is a valid constant pool index, it cannot be a
46265valid index for both a string and a CU vector.
46266
46267The hash value for a table entry is computed by applying an
46268iterative hash function to the symbol's name. Starting with an
46269initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
46270the string is incorporated into the hash using the formula depending on the
46271index version:
46272
46273@table @asis
46274@item Version 4
46275The formula is @code{r = r * 67 + c - 113}.
46276
156942c7 46277@item Versions 5 to 7
559a7a62
JK
46278The formula is @code{r = r * 67 + tolower (c) - 113}.
46279@end table
46280
46281The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
46282
46283The step size used in the hash table is computed via
46284@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46285value, and @samp{size} is the size of the hash table. The step size
46286is used to find the next candidate slot when handling a hash
46287collision.
46288
46289The names of C@t{++} symbols in the hash table are canonicalized. We
46290don't currently have a simple description of the canonicalization
46291algorithm; if you intend to create new index sections, you must read
46292the code.
46293
46294@item
46295The constant pool. This is simply a bunch of bytes. It is organized
46296so that alignment is correct: CU vectors are stored first, followed by
46297strings.
46298
46299A CU vector in the constant pool is a sequence of @code{offset_type}
46300values. The first value is the number of CU indices in the vector.
156942c7
DE
46301Each subsequent value is the index and symbol attributes of a CU in
46302the CU list. This element in the hash table is used to indicate which
46303CUs define the symbol and how the symbol is used.
46304See below for the format of each CU index+attributes entry.
90476074
TT
46305
46306A string in the constant pool is zero-terminated.
46307@end enumerate
46308
156942c7
DE
46309Attributes were added to CU index values in @code{.gdb_index} version 7.
46310If a symbol has multiple uses within a CU then there is one
46311CU index+attributes value for each use.
46312
46313The format of each CU index+attributes entry is as follows
46314(bit 0 = LSB):
46315
46316@table @asis
46317
46318@item Bits 0-23
46319This is the index of the CU in the CU list.
46320@item Bits 24-27
46321These bits are reserved for future purposes and must be zero.
46322@item Bits 28-30
46323The kind of the symbol in the CU.
46324
46325@table @asis
46326@item 0
46327This value is reserved and should not be used.
46328By reserving zero the full @code{offset_type} value is backwards compatible
46329with previous versions of the index.
46330@item 1
46331The symbol is a type.
46332@item 2
46333The symbol is a variable or an enum value.
46334@item 3
46335The symbol is a function.
46336@item 4
46337Any other kind of symbol.
46338@item 5,6,7
46339These values are reserved.
46340@end table
46341
46342@item Bit 31
46343This bit is zero if the value is global and one if it is static.
46344
46345The determination of whether a symbol is global or static is complicated.
46346The authorative reference is the file @file{dwarf2read.c} in
46347@value{GDBN} sources.
46348
46349@end table
46350
46351This pseudo-code describes the computation of a symbol's kind and
46352global/static attributes in the index.
46353
46354@smallexample
46355is_external = get_attribute (die, DW_AT_external);
46356language = get_attribute (cu_die, DW_AT_language);
46357switch (die->tag)
46358 @{
46359 case DW_TAG_typedef:
46360 case DW_TAG_base_type:
46361 case DW_TAG_subrange_type:
46362 kind = TYPE;
46363 is_static = 1;
46364 break;
46365 case DW_TAG_enumerator:
46366 kind = VARIABLE;
9c37b5ae 46367 is_static = language != CPLUS;
156942c7
DE
46368 break;
46369 case DW_TAG_subprogram:
46370 kind = FUNCTION;
46371 is_static = ! (is_external || language == ADA);
46372 break;
46373 case DW_TAG_constant:
46374 kind = VARIABLE;
46375 is_static = ! is_external;
46376 break;
46377 case DW_TAG_variable:
46378 kind = VARIABLE;
46379 is_static = ! is_external;
46380 break;
46381 case DW_TAG_namespace:
46382 kind = TYPE;
46383 is_static = 0;
46384 break;
46385 case DW_TAG_class_type:
46386 case DW_TAG_interface_type:
46387 case DW_TAG_structure_type:
46388 case DW_TAG_union_type:
46389 case DW_TAG_enumeration_type:
46390 kind = TYPE;
9c37b5ae 46391 is_static = language != CPLUS;
156942c7
DE
46392 break;
46393 default:
46394 assert (0);
46395 @}
46396@end smallexample
46397
43662968
JK
46398@node Man Pages
46399@appendix Manual pages
46400@cindex Man pages
46401
46402@menu
46403* gdb man:: The GNU Debugger man page
46404* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 46405* gcore man:: Generate a core file of a running program
43662968 46406* gdbinit man:: gdbinit scripts
ba643918 46407* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
46408@end menu
46409
46410@node gdb man
46411@heading gdb man
46412
46413@c man title gdb The GNU Debugger
46414
46415@c man begin SYNOPSIS gdb
46416gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46417[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46418[@option{-b}@w{ }@var{bps}]
46419 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46420[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
46421[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46422 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46423[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
46424@c man end
46425
46426@c man begin DESCRIPTION gdb
46427The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46428going on ``inside'' another program while it executes -- or what another
46429program was doing at the moment it crashed.
46430
46431@value{GDBN} can do four main kinds of things (plus other things in support of
46432these) to help you catch bugs in the act:
46433
46434@itemize @bullet
46435@item
46436Start your program, specifying anything that might affect its behavior.
46437
46438@item
46439Make your program stop on specified conditions.
46440
46441@item
46442Examine what has happened, when your program has stopped.
46443
46444@item
46445Change things in your program, so you can experiment with correcting the
46446effects of one bug and go on to learn about another.
46447@end itemize
46448
906ccdf0
JK
46449You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46450Modula-2.
43662968
JK
46451
46452@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46453commands from the terminal until you tell it to exit with the @value{GDBN}
46454command @code{quit}. You can get online help from @value{GDBN} itself
46455by using the command @code{help}.
46456
46457You can run @code{gdb} with no arguments or options; but the most
46458usual way to start @value{GDBN} is with one argument or two, specifying an
46459executable program as the argument:
46460
46461@smallexample
46462gdb program
46463@end smallexample
46464
46465You can also start with both an executable program and a core file specified:
46466
46467@smallexample
46468gdb program core
46469@end smallexample
46470
4ed4690f
SM
46471You can, instead, specify a process ID as a second argument or use option
46472@code{-p}, if you want to debug a running process:
43662968
JK
46473
46474@smallexample
46475gdb program 1234
906ccdf0 46476gdb -p 1234
43662968
JK
46477@end smallexample
46478
46479@noindent
4ed4690f
SM
46480would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46481can omit the @var{program} filename.
43662968
JK
46482
46483Here are some of the most frequently needed @value{GDBN} commands:
46484
46485@c pod2man highlights the right hand side of the @item lines.
46486@table @env
224f10c1 46487@item break [@var{file}:]@var{function}
43662968
JK
46488Set a breakpoint at @var{function} (in @var{file}).
46489
46490@item run [@var{arglist}]
46491Start your program (with @var{arglist}, if specified).
46492
46493@item bt
46494Backtrace: display the program stack.
46495
46496@item print @var{expr}
46497Display the value of an expression.
46498
46499@item c
46500Continue running your program (after stopping, e.g. at a breakpoint).
46501
46502@item next
46503Execute next program line (after stopping); step @emph{over} any
46504function calls in the line.
46505
46506@item edit [@var{file}:]@var{function}
46507look at the program line where it is presently stopped.
46508
46509@item list [@var{file}:]@var{function}
46510type the text of the program in the vicinity of where it is presently stopped.
46511
46512@item step
46513Execute next program line (after stopping); step @emph{into} any
46514function calls in the line.
46515
46516@item help [@var{name}]
46517Show information about @value{GDBN} command @var{name}, or general information
46518about using @value{GDBN}.
46519
46520@item quit
46521Exit from @value{GDBN}.
46522@end table
46523
46524@ifset man
46525For full details on @value{GDBN},
46526see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46527by Richard M. Stallman and Roland H. Pesch. The same text is available online
46528as the @code{gdb} entry in the @code{info} program.
46529@end ifset
46530@c man end
46531
46532@c man begin OPTIONS gdb
46533Any arguments other than options specify an executable
46534file and core file (or process ID); that is, the first argument
46535encountered with no
46536associated option flag is equivalent to a @option{-se} option, and the second,
46537if any, is equivalent to a @option{-c} option if it's the name of a file.
46538Many options have
46539both long and short forms; both are shown here. The long forms are also
46540recognized if you truncate them, so long as enough of the option is
46541present to be unambiguous. (If you prefer, you can flag option
46542arguments with @option{+} rather than @option{-}, though we illustrate the
46543more usual convention.)
46544
46545All the options and command line arguments you give are processed
46546in sequential order. The order makes a difference when the @option{-x}
46547option is used.
46548
46549@table @env
46550@item -help
46551@itemx -h
46552List all options, with brief explanations.
46553
46554@item -symbols=@var{file}
46555@itemx -s @var{file}
46556Read symbol table from file @var{file}.
46557
46558@item -write
46559Enable writing into executable and core files.
46560
46561@item -exec=@var{file}
46562@itemx -e @var{file}
46563Use file @var{file} as the executable file to execute when
46564appropriate, and for examining pure data in conjunction with a core
46565dump.
46566
46567@item -se=@var{file}
46568Read symbol table from file @var{file} and use it as the executable
46569file.
46570
46571@item -core=@var{file}
46572@itemx -c @var{file}
46573Use file @var{file} as a core dump to examine.
46574
46575@item -command=@var{file}
46576@itemx -x @var{file}
46577Execute @value{GDBN} commands from file @var{file}.
46578
46579@item -ex @var{command}
46580Execute given @value{GDBN} @var{command}.
46581
46582@item -directory=@var{directory}
46583@itemx -d @var{directory}
46584Add @var{directory} to the path to search for source files.
46585
46586@item -nh
64aaad63
AB
46587Do not execute commands from @file{~/.config/gdb/gdbinit} or
46588@file{~/.gdbinit}.
43662968
JK
46589
46590@item -nx
46591@itemx -n
46592Do not execute commands from any @file{.gdbinit} initialization files.
46593
46594@item -quiet
46595@itemx -q
46596``Quiet''. Do not print the introductory and copyright messages. These
46597messages are also suppressed in batch mode.
46598
46599@item -batch
46600Run in batch mode. Exit with status @code{0} after processing all the command
46601files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46602Exit with nonzero status if an error occurs in executing the @value{GDBN}
46603commands in the command files.
46604
46605Batch mode may be useful for running @value{GDBN} as a filter, for example to
46606download and run a program on another computer; in order to make this
46607more useful, the message
46608
46609@smallexample
46610Program exited normally.
46611@end smallexample
46612
46613@noindent
46614(which is ordinarily issued whenever a program running under @value{GDBN} control
46615terminates) is not issued when running in batch mode.
46616
46617@item -cd=@var{directory}
46618Run @value{GDBN} using @var{directory} as its working directory,
46619instead of the current directory.
46620
46621@item -fullname
46622@itemx -f
46623Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46624@value{GDBN} to output the full file name and line number in a standard,
46625recognizable fashion each time a stack frame is displayed (which
46626includes each time the program stops). This recognizable format looks
46627like two @samp{\032} characters, followed by the file name, line number
46628and character position separated by colons, and a newline. The
46629Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46630characters as a signal to display the source code for the frame.
46631
46632@item -b @var{bps}
46633Set the line speed (baud rate or bits per second) of any serial
46634interface used by @value{GDBN} for remote debugging.
46635
46636@item -tty=@var{device}
46637Run using @var{device} for your program's standard input and output.
46638@end table
46639@c man end
46640
46641@c man begin SEEALSO gdb
46642@ifset man
46643The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46644If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46645documentation are properly installed at your site, the command
46646
46647@smallexample
46648info gdb
46649@end smallexample
46650
46651@noindent
46652should give you access to the complete manual.
46653
46654@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46655Richard M. Stallman and Roland H. Pesch, July 1991.
46656@end ifset
46657@c man end
46658
46659@node gdbserver man
46660@heading gdbserver man
46661
46662@c man title gdbserver Remote Server for the GNU Debugger
46663@format
46664@c man begin SYNOPSIS gdbserver
5b8b6385 46665gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46666
5b8b6385
JK
46667gdbserver --attach @var{comm} @var{pid}
46668
46669gdbserver --multi @var{comm}
43662968
JK
46670@c man end
46671@end format
46672
46673@c man begin DESCRIPTION gdbserver
46674@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46675than the one which is running the program being debugged.
46676
46677@ifclear man
46678@subheading Usage (server (target) side)
46679@end ifclear
46680@ifset man
46681Usage (server (target) side):
46682@end ifset
46683
46684First, you need to have a copy of the program you want to debug put onto
46685the target system. The program can be stripped to save space if needed, as
46686@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46687the @value{GDBN} running on the host system.
46688
46689To use the server, you log on to the target system, and run the @command{gdbserver}
46690program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46691your program, and (c) its arguments. The general syntax is:
46692
46693@smallexample
46694target> gdbserver @var{comm} @var{program} [@var{args} ...]
46695@end smallexample
46696
46697For example, using a serial port, you might say:
46698
46699@smallexample
46700@ifset man
46701@c @file would wrap it as F</dev/com1>.
46702target> gdbserver /dev/com1 emacs foo.txt
46703@end ifset
46704@ifclear man
46705target> gdbserver @file{/dev/com1} emacs foo.txt
46706@end ifclear
46707@end smallexample
46708
46709This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46710to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46711waits patiently for the host @value{GDBN} to communicate with it.
46712
46713To use a TCP connection, you could say:
46714
46715@smallexample
46716target> gdbserver host:2345 emacs foo.txt
46717@end smallexample
46718
46719This says pretty much the same thing as the last example, except that we are
46720going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46721that we are expecting to see a TCP connection from @code{host} to local TCP port
467222345. (Currently, the @code{host} part is ignored.) You can choose any number you
46723want for the port number as long as it does not conflict with any existing TCP
46724ports on the target system. This same port number must be used in the host
46725@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46726you chose a port number that conflicts with another service, @command{gdbserver} will
46727print an error message and exit.
46728
5b8b6385 46729@command{gdbserver} can also attach to running programs.
43662968
JK
46730This is accomplished via the @option{--attach} argument. The syntax is:
46731
46732@smallexample
5b8b6385 46733target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46734@end smallexample
46735
46736@var{pid} is the process ID of a currently running process. It isn't
46737necessary to point @command{gdbserver} at a binary for the running process.
46738
5b8b6385
JK
46739To start @code{gdbserver} without supplying an initial command to run
46740or process ID to attach, use the @option{--multi} command line option.
46741In such case you should connect using @kbd{target extended-remote} to start
46742the program you want to debug.
46743
46744@smallexample
46745target> gdbserver --multi @var{comm}
46746@end smallexample
46747
43662968
JK
46748@ifclear man
46749@subheading Usage (host side)
46750@end ifclear
46751@ifset man
46752Usage (host side):
46753@end ifset
46754
46755You need an unstripped copy of the target program on your host system, since
1a088a2e 46756@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46757would, with the target program as the first argument. (You may need to use the
46758@option{--baud} option if the serial line is running at anything except 9600 baud.)
46759That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46760new command you need to know about is @code{target remote}
46761(or @code{target extended-remote}). Its argument is either
43662968
JK
46762a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46763descriptor. For example:
46764
46765@smallexample
46766@ifset man
46767@c @file would wrap it as F</dev/ttyb>.
46768(gdb) target remote /dev/ttyb
46769@end ifset
46770@ifclear man
46771(gdb) target remote @file{/dev/ttyb}
46772@end ifclear
46773@end smallexample
46774
46775@noindent
46776communicates with the server via serial line @file{/dev/ttyb}, and:
46777
46778@smallexample
46779(gdb) target remote the-target:2345
46780@end smallexample
46781
46782@noindent
46783communicates via a TCP connection to port 2345 on host `the-target', where
46784you previously started up @command{gdbserver} with the same port number. Note that for
46785TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46786command, otherwise you may get an error that looks something like
46787`Connection refused'.
5b8b6385
JK
46788
46789@command{gdbserver} can also debug multiple inferiors at once,
46790described in
46791@ifset man
65c574f6
PA
46792the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46793-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46794@end ifset
46795@ifclear man
65c574f6 46796@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46797@end ifclear
46798In such case use the @code{extended-remote} @value{GDBN} command variant:
46799
46800@smallexample
46801(gdb) target extended-remote the-target:2345
46802@end smallexample
46803
46804The @command{gdbserver} option @option{--multi} may or may not be used in such
46805case.
43662968
JK
46806@c man end
46807
46808@c man begin OPTIONS gdbserver
5b8b6385
JK
46809There are three different modes for invoking @command{gdbserver}:
46810
46811@itemize @bullet
46812
46813@item
46814Debug a specific program specified by its program name:
46815
46816@smallexample
46817gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46818@end smallexample
46819
46820The @var{comm} parameter specifies how should the server communicate
46821with @value{GDBN}; it is either a device name (to use a serial line),
46822a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46823stdin/stdout of @code{gdbserver}. Specify the name of the program to
46824debug in @var{prog}. Any remaining arguments will be passed to the
46825program verbatim. When the program exits, @value{GDBN} will close the
46826connection, and @code{gdbserver} will exit.
46827
46828@item
46829Debug a specific program by specifying the process ID of a running
46830program:
46831
46832@smallexample
46833gdbserver --attach @var{comm} @var{pid}
46834@end smallexample
46835
46836The @var{comm} parameter is as described above. Supply the process ID
46837of a running program in @var{pid}; @value{GDBN} will do everything
46838else. Like with the previous mode, when the process @var{pid} exits,
46839@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46840
46841@item
46842Multi-process mode -- debug more than one program/process:
46843
46844@smallexample
46845gdbserver --multi @var{comm}
46846@end smallexample
46847
46848In this mode, @value{GDBN} can instruct @command{gdbserver} which
46849command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46850close the connection when a process being debugged exits, so you can
46851debug several processes in the same session.
46852@end itemize
46853
46854In each of the modes you may specify these options:
46855
46856@table @env
46857
46858@item --help
46859List all options, with brief explanations.
46860
46861@item --version
46862This option causes @command{gdbserver} to print its version number and exit.
46863
46864@item --attach
46865@command{gdbserver} will attach to a running program. The syntax is:
46866
46867@smallexample
46868target> gdbserver --attach @var{comm} @var{pid}
46869@end smallexample
46870
46871@var{pid} is the process ID of a currently running process. It isn't
46872necessary to point @command{gdbserver} at a binary for the running process.
46873
46874@item --multi
46875To start @code{gdbserver} without supplying an initial command to run
46876or process ID to attach, use this command line option.
46877Then you can connect using @kbd{target extended-remote} and start
46878the program you want to debug. The syntax is:
46879
46880@smallexample
46881target> gdbserver --multi @var{comm}
46882@end smallexample
46883
46884@item --debug
46885Instruct @code{gdbserver} to display extra status information about the debugging
46886process.
46887This option is intended for @code{gdbserver} development and for bug reports to
46888the developers.
46889
46890@item --remote-debug
46891Instruct @code{gdbserver} to display remote protocol debug output.
46892This option is intended for @code{gdbserver} development and for bug reports to
46893the developers.
46894
aeb2e706
AH
46895@item --debug-file=@var{filename}
46896Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46897This option is intended for @code{gdbserver} development and for bug reports to
46898the developers.
46899
87ce2a04
DE
46900@item --debug-format=option1@r{[},option2,...@r{]}
46901Instruct @code{gdbserver} to include extra information in each line
46902of debugging output.
46903@xref{Other Command-Line Arguments for gdbserver}.
46904
5b8b6385
JK
46905@item --wrapper
46906Specify a wrapper to launch programs
46907for debugging. The option should be followed by the name of the
46908wrapper, then any command-line arguments to pass to the wrapper, then
46909@kbd{--} indicating the end of the wrapper arguments.
46910
46911@item --once
46912By default, @command{gdbserver} keeps the listening TCP port open, so that
46913additional connections are possible. However, if you start @code{gdbserver}
46914with the @option{--once} option, it will stop listening for any further
46915connection attempts after connecting to the first @value{GDBN} session.
46916
46917@c --disable-packet is not documented for users.
46918
46919@c --disable-randomization and --no-disable-randomization are superseded by
46920@c QDisableRandomization.
46921
46922@end table
43662968
JK
46923@c man end
46924
46925@c man begin SEEALSO gdbserver
46926@ifset man
46927The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46928If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46929documentation are properly installed at your site, the command
46930
46931@smallexample
46932info gdb
46933@end smallexample
46934
46935should give you access to the complete manual.
46936
46937@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46938Richard M. Stallman and Roland H. Pesch, July 1991.
46939@end ifset
46940@c man end
46941
b292c783
JK
46942@node gcore man
46943@heading gcore
46944
46945@c man title gcore Generate a core file of a running program
46946
46947@format
46948@c man begin SYNOPSIS gcore
129eb0f1 46949gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46950@c man end
46951@end format
46952
46953@c man begin DESCRIPTION gcore
129eb0f1
SDJ
46954Generate core dumps of one or more running programs with process IDs
46955@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46956is equivalent to one produced by the kernel when the process crashes
46957(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46958limit). However, unlike after a crash, after @command{gcore} finishes
46959its job the program remains running without any change.
b292c783
JK
46960@c man end
46961
46962@c man begin OPTIONS gcore
46963@table @env
c179febe
SL
46964@item -a
46965Dump all memory mappings. The actual effect of this option depends on
46966the Operating System. On @sc{gnu}/Linux, it will disable
46967@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46968enable @code{dump-excluded-mappings} (@pxref{set
46969dump-excluded-mappings}).
46970
129eb0f1
SDJ
46971@item -o @var{prefix}
46972The optional argument @var{prefix} specifies the prefix to be used
46973when composing the file names of the core dumps. The file name is
46974composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46975process ID of the running program being analyzed by @command{gcore}.
46976If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
46977@end table
46978@c man end
46979
46980@c man begin SEEALSO gcore
46981@ifset man
46982The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46983If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46984documentation are properly installed at your site, the command
46985
46986@smallexample
46987info gdb
46988@end smallexample
46989
46990@noindent
46991should give you access to the complete manual.
46992
46993@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46994Richard M. Stallman and Roland H. Pesch, July 1991.
46995@end ifset
46996@c man end
46997
43662968
JK
46998@node gdbinit man
46999@heading gdbinit
47000
47001@c man title gdbinit GDB initialization scripts
47002
47003@format
47004@c man begin SYNOPSIS gdbinit
47005@ifset SYSTEM_GDBINIT
47006@value{SYSTEM_GDBINIT}
47007@end ifset
47008
ed2a2229
CB
47009@ifset SYSTEM_GDBINIT_DIR
47010@value{SYSTEM_GDBINIT_DIR}/*
47011@end ifset
47012
64aaad63
AB
47013~/.config/gdb/gdbinit
47014
43662968
JK
47015~/.gdbinit
47016
47017./.gdbinit
47018@c man end
47019@end format
47020
47021@c man begin DESCRIPTION gdbinit
47022These files contain @value{GDBN} commands to automatically execute during
47023@value{GDBN} startup. The lines of contents are canned sequences of commands,
47024described in
47025@ifset man
47026the @value{GDBN} manual in node @code{Sequences}
47027-- shell command @code{info -f gdb -n Sequences}.
47028@end ifset
47029@ifclear man
47030@ref{Sequences}.
47031@end ifclear
47032
47033Please read more in
47034@ifset man
47035the @value{GDBN} manual in node @code{Startup}
47036-- shell command @code{info -f gdb -n Startup}.
47037@end ifset
47038@ifclear man
47039@ref{Startup}.
47040@end ifclear
47041
47042@table @env
47043@ifset SYSTEM_GDBINIT
47044@item @value{SYSTEM_GDBINIT}
47045@end ifset
47046@ifclear SYSTEM_GDBINIT
47047@item (not enabled with @code{--with-system-gdbinit} during compilation)
47048@end ifclear
47049System-wide initialization file. It is executed unless user specified
47050@value{GDBN} option @code{-nx} or @code{-n}.
47051See more in
47052@ifset man
47053the @value{GDBN} manual in node @code{System-wide configuration}
47054-- shell command @code{info -f gdb -n 'System-wide configuration'}.
47055@end ifset
ed2a2229
CB
47056@ifset SYSTEM_GDBINIT_DIR
47057@item @value{SYSTEM_GDBINIT_DIR}
47058@end ifset
47059@ifclear SYSTEM_GDBINIT_DIR
47060@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
47061@end ifclear
47062System-wide initialization directory. All files in this directory are
47063executed on startup unless user specified @value{GDBN} option @code{-nx} or
47064@code{-n}, as long as they have a recognized file extension.
47065See more in
47066@ifset man
47067the @value{GDBN} manual in node @code{System-wide configuration}
47068-- shell command @code{info -f gdb -n 'System-wide configuration'}.
47069@end ifset
43662968
JK
47070@ifclear man
47071@ref{System-wide configuration}.
47072@end ifclear
47073
64aaad63 47074@item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
43662968
JK
47075User initialization file. It is executed unless user specified
47076@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
47077
64aaad63 47078@item @file{.gdbinit}
43662968
JK
47079Initialization file for current directory. It may need to be enabled with
47080@value{GDBN} security command @code{set auto-load local-gdbinit}.
47081See more in
47082@ifset man
47083the @value{GDBN} manual in node @code{Init File in the Current Directory}
47084-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
47085@end ifset
47086@ifclear man
47087@ref{Init File in the Current Directory}.
47088@end ifclear
47089@end table
47090@c man end
47091
47092@c man begin SEEALSO gdbinit
47093@ifset man
47094gdb(1), @code{info -f gdb -n Startup}
47095
47096The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47097If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47098documentation are properly installed at your site, the command
ba643918
SDJ
47099
47100@smallexample
47101info gdb
47102@end smallexample
47103
47104should give you access to the complete manual.
47105
47106@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47107Richard M. Stallman and Roland H. Pesch, July 1991.
47108@end ifset
47109@c man end
47110
47111@node gdb-add-index man
ba643918 47112@heading gdb-add-index
d726cb5d 47113@pindex gdb-add-index
dbfa4523 47114@anchor{gdb-add-index}
ba643918
SDJ
47115
47116@c man title gdb-add-index Add index files to speed up GDB
47117
47118@c man begin SYNOPSIS gdb-add-index
47119gdb-add-index @var{filename}
47120@c man end
47121
47122@c man begin DESCRIPTION gdb-add-index
47123When @value{GDBN} finds a symbol file, it scans the symbols in the
47124file in order to construct an internal symbol table. This lets most
47125@value{GDBN} operations work quickly--at the cost of a delay early on.
47126For large programs, this delay can be quite lengthy, so @value{GDBN}
47127provides a way to build an index, which speeds up startup.
47128
47129To determine whether a file contains such an index, use the command
47130@kbd{readelf -S filename}: the index is stored in a section named
47131@code{.gdb_index}. The index file can only be produced on systems
47132which use ELF binaries and DWARF debug information (i.e., sections
47133named @code{.debug_*}).
47134
47135@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
47136in the @env{PATH} environment variable. If you want to use different
47137versions of these programs, you can specify them through the
47138@env{GDB} and @env{OBJDUMP} environment variables.
47139
47140See more in
47141@ifset man
47142the @value{GDBN} manual in node @code{Index Files}
47143-- shell command @kbd{info -f gdb -n "Index Files"}.
47144@end ifset
47145@ifclear man
47146@ref{Index Files}.
47147@end ifclear
47148@c man end
47149
47150@c man begin SEEALSO gdb-add-index
47151@ifset man
47152The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47153If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47154documentation are properly installed at your site, the command
43662968
JK
47155
47156@smallexample
47157info gdb
47158@end smallexample
47159
47160should give you access to the complete manual.
47161
47162@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47163Richard M. Stallman and Roland H. Pesch, July 1991.
47164@end ifset
47165@c man end
47166
aab4e0ec 47167@include gpl.texi
eb12ee30 47168
e4c0cfae
SS
47169@node GNU Free Documentation License
47170@appendix GNU Free Documentation License
6826cf00
EZ
47171@include fdl.texi
47172
00595b5e
EZ
47173@node Concept Index
47174@unnumbered Concept Index
c906108c
SS
47175
47176@printindex cp
47177
00595b5e
EZ
47178@node Command and Variable Index
47179@unnumbered Command, Variable, and Function Index
47180
47181@printindex fn
47182
c906108c 47183@tex
984359d2 47184% I think something like @@colophon should be in texinfo. In the
c906108c
SS
47185% meantime:
47186\long\def\colophon{\hbox to0pt{}\vfill
47187\centerline{The body of this manual is set in}
47188\centerline{\fontname\tenrm,}
47189\centerline{with headings in {\bf\fontname\tenbf}}
47190\centerline{and examples in {\tt\fontname\tentt}.}
47191\centerline{{\it\fontname\tenit\/},}
47192\centerline{{\bf\fontname\tenbf}, and}
47193\centerline{{\sl\fontname\tensl\/}}
47194\centerline{are used for emphasis.}\vfill}
47195\page\colophon
984359d2 47196% Blame: doc@@cygnus.com, 1991.
c906108c
SS
47197@end tex
47198
c906108c 47199@bye
This page took 8.423753 seconds and 4 git commands to generate.